diff --git a/src/character/templates/character/snippets/characters_list/character_card.html b/src/character/templates/character/snippets/characters_list/character_card.html index 4d43b87..cde9127 100644 --- a/src/character/templates/character/snippets/characters_list/character_card.html +++ b/src/character/templates/character/snippets/characters_list/character_card.html @@ -1,6 +1,6 @@ {% load character_extras %}
-
+
{% if character.private %} diff --git a/src/character/tests/test_interactions.py b/src/character/tests/test_interactions.py index 72820cd..db6c7f6 100644 --- a/src/character/tests/test_interactions.py +++ b/src/character/tests/test_interactions.py @@ -1,6 +1,7 @@ import pytest from django.core.management import call_command from django.urls import reverse +from model_bakery import baker from pytest_django.live_server_helper import LiveServer from selenium.webdriver.common.by import By from selenium.webdriver.firefox.webdriver import WebDriver @@ -33,13 +34,12 @@ def test_create_character(selenium: WebDriver, live_server: LiveServer): # Check no existing character assert Character.objects.count() == 0 - # Fill form + # Fill form with missing age raw_values = { "name": "My Character", "equipment": "Lighter, blanket", "damage_reduction": "Something here", "level": 8, - "age": 32, "height": 134, "weight": 78, "value_strength": 9, @@ -57,19 +57,32 @@ def test_create_character(selenium: WebDriver, live_server: LiveServer): "money_pa": 3, "money_pc": 4, } + for name, value in raw_values.items(): + element = selenium.find_element(By.ID, f"id_{name}") + element.clear() + element.send_keys(str(value)) + related_values = { "race": "Gnome", "profile": "Druide", "racial_capability": "Don étrange", } - for name, value in raw_values.items(): - element = selenium.find_element(By.ID, f"id_{name}") - element.clear() - element.send_keys(str(value)) for name, value in related_values.items(): element = selenium.find_element(By.ID, f"id_{name}") element.send_keys(str(value)) + # Save + url = selenium.current_url + selenium.find_element(By.CSS_SELECTOR, "button[type=submit]").click() + + # Assert URL hasn't changed + assert selenium.current_url == url + + # Fill level + level_element = selenium.find_element(By.ID, "id_age") + level_element.clear() + level_element.send_keys("32") + # Save selenium.find_element(By.CSS_SELECTOR, "button[type=submit]").click() @@ -82,3 +95,41 @@ def test_create_character(selenium: WebDriver, live_server: LiveServer): assert character.player == player for name, value in raw_values.items(): assert getattr(character, name) == value + + +@pytest.mark.django_db +def test_list_characters(selenium: WebDriver, live_server: LiveServer): + # Load fixtures + call_command("loaddata", "initial_data") + # Create user 1 + username, password = "user1", "some_password" + player = User.objects.create_user(username, password=password) + + # Create user 2 + other = User.objects.create_user("user2", password=password) + + # Create two characters (1, 2) for user 1 + characters = baker.make(Character, _quantity=2, player=player) + + # Create a character (3) for user 2 + baker.make(Character, player=other) + + # Go to home page + selenium.get(live_server.url) + + # Login as user 1 + selenium.find_element(By.ID, "login").click() + selenium.find_element(By.ID, "id_username").send_keys(username) + selenium.find_element(By.ID, "id_password").send_keys(password) + selenium.find_element(By.CSS_SELECTOR, "button[type=submit]").click() + + # Assert only characters 1 and 2 are shown although there are 3 characters in DB + assert Character.objects.count() == 3 + names = { + name.text + for name in selenium.find_elements( + By.CSS_SELECTOR, ".character.card .card-title" + ) + } + expected_names = {character.name for character in characters} + assert names == expected_names