diff --git a/smash/web/tests/view/test_flying_teams.py b/smash/web/tests/view/test_flying_teams.py index 0e8e11eefac1f026098a0624b19103902fbd2e30..32cfe22ff9d0ac7cbd073f66dd3691ff051a06b9 100644 --- a/smash/web/tests/view/test_flying_teams.py +++ b/smash/web/tests/view/test_flying_teams.py @@ -1,16 +1,22 @@ +import logging + from django.urls import reverse +from web.tests.functions import create_flying_team from web.models import FlyingTeam from web.tests import LoggedInTestCase +logger = logging.getLogger(__name__) + class FlyingTeamTests(LoggedInTestCase): - def generate_more_or_less_random_name(self): + @staticmethod + def generate_more_or_less_random_name(): import random - letters = [chr(x) for x in range(97,122)] - return 'Radom' + ''.join(random.choice(letters) for x in range(15)) + letters = [chr(x) for x in range(97, 122)] + return 'Random' + ''.join(random.choice(letters) for x in range(15)) - def test_flyingteam_requests(self): + def test_flying_team_requests(self): pages = [ 'web.views.equipment_and_rooms.flying_teams', 'web.views.equipment_and_rooms.flying_teams_add', @@ -20,23 +26,33 @@ class FlyingTeamTests(LoggedInTestCase): response = self.client.get(reverse(page)) self.assertEqual(response.status_code, 200) - def test_flyingteam_add(self): - # TODO - return - """ # It supposedly doesn't work like this + def test_flying_team_add(self): page = reverse('web.views.equipment_and_rooms.flying_teams_add') data = { - 'id_place': self.generate_more_or_less_random_name() + 'place': self.generate_more_or_less_random_name() } - response = self.client.post(page, data) # <== it doesn't post the - # data at the correct place - self.assertEqual(response.status_code, 200) + response = self.client.post(page, data) + self.assertEqual(response.status_code, 302) - freshly_created = FlyingTeam.objects.filter(place=data['id_place']) + freshly_created = FlyingTeam.objects.filter(place=data['place']) self.assertEqual(len(freshly_created), 1) - freshly_created.delete() - """ - def test_flyingteam_edit(self): - # TODO - return + def test_flying_team_edit(self): + flying_team = create_flying_team() + page = reverse('web.views.equipment_and_rooms.flying_teams_edit', + kwargs={'flying_team_id': str(flying_team.id)}) + data = { + 'place': self.generate_more_or_less_random_name() + } + response = self.client.post(page, data) + self.assertEqual(response.status_code, 302) + + freshly_edited = FlyingTeam.objects.get(id=flying_team.id) + self.assertEqual(freshly_edited.place, data["place"]) + + def test_flying_team_edit_request(self): + flying_team = create_flying_team() + page = reverse('web.views.equipment_and_rooms.flying_teams_edit', + kwargs={'flying_team_id': str(flying_team.id)}) + response = self.client.get(page) + self.assertEqual(response.status_code, 200)