add function to determine if all players are ready for the next round; fix tests
This commit is contained in:
parent
d0b2d9c484
commit
6133fb1891
|
@ -20,6 +20,12 @@ class StoryRound(models.Model):
|
|||
# TODO: implement, for each story get unfinished part and check user
|
||||
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):
|
||||
# user = models.ForeignKey(User, on_delete=CASCADE)
|
||||
|
|
|
@ -48,7 +48,7 @@ class TestModelFunctions(TestCase):
|
|||
user=user,
|
||||
previous_part=previous_part,
|
||||
part_of=story,
|
||||
round_number=i
|
||||
turn_number=i
|
||||
)
|
||||
parts.append(new_part)
|
||||
previous_part = new_part
|
||||
|
@ -87,3 +87,33 @@ class TestModelFunctions(TestCase):
|
|||
result = self.story1.get_first_unfinished_part()
|
||||
|
||||
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())
|
||||
|
|
Loading…
Reference in New Issue