add function to determine if all players are ready for the next round; fix tests

This commit is contained in:
Gesche 2021-04-20 00:25:58 +02:00
parent d0b2d9c484
commit 6133fb1891
2 changed files with 37 additions and 1 deletions

View File

@ -20,6 +20,12 @@ class StoryRound(models.Model):
# TODO: implement, for each story get unfinished part and check user # TODO: implement, for each story get unfinished part and check user
pass pass
def next_round_ready(self) -> bool:
for story in self.story_set.all():
if not story.storypart_set.get(turn_number=self.current_turn).finished:
return False
return True
#class Participant(models.Model): #class Participant(models.Model):
# user = models.ForeignKey(User, on_delete=CASCADE) # user = models.ForeignKey(User, on_delete=CASCADE)

View File

@ -48,7 +48,7 @@ class TestModelFunctions(TestCase):
user=user, user=user,
previous_part=previous_part, previous_part=previous_part,
part_of=story, part_of=story,
round_number=i turn_number=i
) )
parts.append(new_part) parts.append(new_part)
previous_part = new_part previous_part = new_part
@ -87,3 +87,33 @@ class TestModelFunctions(TestCase):
result = self.story1.get_first_unfinished_part() result = self.story1.get_first_unfinished_part()
self.assertEqual(result, None) self.assertEqual(result, None)
def test_next_round_ready__game_start(self):
self.create_users_and_story_round_with_stories_and_parts()
self.assertFalse(self.story_round.next_round_ready())
def test_next_round_ready__half_done(self):
self.create_users_and_story_round_with_stories_and_parts()
self.parts1[0].text = 'some text'
self.parts1[0].save()
self.assertFalse(self.story_round.next_round_ready())
def test_next_round_ready__first_round_done(self):
self.create_users_and_story_round_with_stories_and_parts()
self.parts1[0].text = 'some text'
self.parts1[0].save()
self.parts2[0].text = 'some text'
self.parts2[0].save()
self.assertTrue(self.story_round.next_round_ready())
def test_next_round_ready__second_round_done(self):
self.create_users_and_story_round_with_stories_and_parts()
self.story_round.current_turn = 1
self.story_round.save()
self.parts1[1].text = 'some text'
self.parts1[1].save()
self.parts2[1].text = 'some text'
self.parts2[1].save()
self.assertTrue(self.story_round.next_round_ready())