diff --git a/stories/writingtogether/models.py b/stories/writingtogether/models.py index 01f65ce..0031bb1 100644 --- a/stories/writingtogether/models.py +++ b/stories/writingtogether/models.py @@ -17,8 +17,11 @@ class StoryRound(models.Model): return reverse('writing:detail', kwargs={'pk': self.pk}) def get_next_story_part(self, user: User) -> 'StoryPart': - # TODO: implement, for each story get unfinished part and check user - pass + return StoryPart.objects.get( + part_of__part_of_round=self, + turn_number=self.current_turn, + user=user + ) def next_round_ready(self) -> bool: for story in self.story_set.all(): diff --git a/stories/writingtogether/tests/test_model_functions.py b/stories/writingtogether/tests/test_model_functions.py index 1f5d1dc..1e7e3ba 100644 --- a/stories/writingtogether/tests/test_model_functions.py +++ b/stories/writingtogether/tests/test_model_functions.py @@ -117,3 +117,29 @@ class TestModelFunctions(TestCase): self.parts2[1].text = 'some text' self.parts2[1].save() self.assertTrue(self.story_round.next_round_ready()) + + def test_get_next_story_part__each_user_starts_with_own_story(self): + self.create_users_and_story_round_with_stories_and_parts() + + result = self.story_round.get_next_story_part(self.user1) + self.assertEqual(result, self.parts1[0]) + + result = self.story_round.get_next_story_part(self.user2) + self.assertEqual(result, self.parts2[0]) + + def test_get_next_story_part__second_round_story_switched(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.story_round.current_turn = 1 + self.story_round.save() + + result = self.story_round.get_next_story_part(self.user1) + self.assertEqual(result, self.parts2[1]) + + result = self.story_round.get_next_story_part(self.user2) + self.assertEqual(result, self.parts1[1]) \ No newline at end of file