From ba3916c4b673e486e0e53f8c2fe10162cef41dd5 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 19 Nov 2022 10:08:53 +0100 Subject: [PATCH] Refactor hurt character generation --- src/character/tests/test_interactions.py | 34 +++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/character/tests/test_interactions.py b/src/character/tests/test_interactions.py index e9a5c7e..f499b5e 100644 --- a/src/character/tests/test_interactions.py +++ b/src/character/tests/test_interactions.py @@ -1,3 +1,5 @@ +from random import randint + import pytest from django.core.management import call_command from django.urls import reverse @@ -145,23 +147,14 @@ def test_delete_character(selenium: WebDriver, live_server: LiveServer): @pytest.mark.django_db +@pytest.mark.parametrize("profile_name", ["Magicien", "Druide", "Guerrier"]) def test_reset_stats_view( - selenium: WebDriver, live_server: LiveServer, initial_data: None + profile_name: str, selenium: WebDriver, live_server: LiveServer, initial_data: None ): username, password = "user", "some_password" player = User.objects.create_user(username, password=password) - profile = Profile.objects.get(name__iexact="Magicien") - - character = baker.make(Character, player=player, profile=profile) - character.health_max = 20 - character.health_remaining = 15 - character.value_intelligence = 15 - character.level = 3 - character.mana_remaining = character.mana_max - 1 - character.recovery_points_remaining = 2 - character.value_charisma = 15 - character.luck_points_remaining = character.luck_points_max - 2 - character.save() + profile = Profile.objects.get(name__iexact=profile_name) + character = create_hurt_character(player, profile) login(selenium, live_server, username, password) @@ -178,6 +171,21 @@ def test_reset_stats_view( assert character.luck_points_remaining == character.luck_points_max +def create_hurt_character(player, profile): + character = baker.make(Character, player=player, profile=profile) + character.health_max = randint(5, 20) + character.health_remaining = randint(0, character.health_max - 1) + character.value_intelligence = randint(10, 20) + character.level = randint(1, 12) + if character.mana_max > 0: + character.mana_remaining = randint(0, character.mana_max - 1) + character.recovery_points_remaining = randint(0, character.recovery_points_max - 1) + character.value_charisma = randint(10, 20) + character.luck_points_remaining = randint(0, character.luck_points_max - 1) + character.save() + return character + + def login( selenium: WebDriver, live_server: LiveServer, username: str, password: str ) -> None: