get_next_story_part: implement & test

This commit is contained in:
Gesche 2021-04-20 00:31:50 +02:00
parent 6133fb1891
commit b1e3031254
2 changed files with 31 additions and 2 deletions

View File

@ -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():

View File

@ -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])