From f8f546679cfc0d3bea867ffcc77fa36c90949f1b Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 16 Nov 2022 15:21:29 +0100 Subject: [PATCH] Fix observe character in group 500 Closes #25 --- src/character/models/character.py | 2 +- src/party/tests/test_interactions.py | 29 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/character/models/character.py b/src/character/models/character.py index cc87a94..e01134a 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -93,7 +93,7 @@ class CharacterQuerySet(models.QuerySet): Q(player=user) | Q(parties__in=Party.objects.related_to(user)) | Q(invites__in=Party.objects.related_to(user)) - ) + ).distinct() DEFAULT_NOTES = """ diff --git a/src/party/tests/test_interactions.py b/src/party/tests/test_interactions.py index 406195e..ef2f824 100644 --- a/src/party/tests/test_interactions.py +++ b/src/party/tests/test_interactions.py @@ -64,3 +64,32 @@ def test_gm_observe_invited_character_in_group( ).click() title = selenium.find_element(By.TAG_NAME, "h1").text.strip() assert title == character.name + + +@pytest.mark.django_db +def test_gm_observe_invited_character_in_two_groups( + selenium: WebDriver, live_server: LiveServer +): + call_command("loaddata", "initial_data") + + username, password = "gm", "password" + gm = User.objects.create_user(username, password=password) + player = User.objects.create_user("player") + party = baker.make(Party, game_master=gm) + other_party = baker.make(Party, game_master=gm) + character = baker.make(Character, player=player) + party.invited_characters.add(character) + other_party.invited_characters.add(character) + + selenium.get(live_server.url) + login(selenium, username, password) + + selenium.get(live_server.url + reverse("party:list")) + selenium.find_element( + By.CSS_SELECTOR, f".party[data-id='{party.pk}'] .access" + ).click() + selenium.find_element( + By.CSS_SELECTOR, f".character[data-id='{character.pk}'] .observe" + ).click() + title = selenium.find_element(By.TAG_NAME, "h1").text.strip() + assert title == character.name