From ef9e1306697852d918e5d9f684229b93a31a2ae0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 10 Jan 2021 15:56:57 -0800 Subject: [PATCH] Adds tests --- bookwyrm/tests/test_view_actions.py | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/bookwyrm/tests/test_view_actions.py b/bookwyrm/tests/test_view_actions.py index 2e5258f6..418568c6 100644 --- a/bookwyrm/tests/test_view_actions.py +++ b/bookwyrm/tests/test_view_actions.py @@ -1,6 +1,7 @@ ''' test for app action functionality ''' from unittest.mock import patch +import dateutil from django.core.exceptions import PermissionDenied from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType @@ -358,6 +359,71 @@ class ViewActions(TestCase): self.assertEqual(resp.template_name, 'edit_author.html') + def test_edit_readthrough(self): + ''' adding dates to an ongoing readthrough ''' + start = dateutil.parser.parse('2021-01-03') + readthrough = models.ReadThrough.objects.create( + book=self.book, user=self.local_user, start_date=start) + request = self.factory.post( + '', { + 'start_date': '2017-01-01', + 'finish_date': '2018-03-07', + 'book': '', + 'id': readthrough.id, + }) + request.user = self.local_user + + actions.edit_readthrough(request) + readthrough.refresh_from_db() + self.assertEqual(readthrough.start_date.year, 2017) + self.assertEqual(readthrough.start_date.month, 1) + self.assertEqual(readthrough.start_date.day, 1) + self.assertEqual(readthrough.finish_date.year, 2018) + self.assertEqual(readthrough.finish_date.month, 3) + self.assertEqual(readthrough.finish_date.day, 7) + self.assertEqual(readthrough.book, self.book) + + + def test_delete_readthrough(self): + ''' remove a readthrough ''' + readthrough = models.ReadThrough.objects.create( + book=self.book, user=self.local_user) + models.ReadThrough.objects.create( + book=self.book, user=self.local_user) + request = self.factory.post( + '', { + 'id': readthrough.id, + }) + request.user = self.local_user + + actions.delete_readthrough(request) + self.assertFalse( + models.ReadThrough.objects.filter(id=readthrough.id).exists()) + + + def test_create_readthrough(self): + ''' adding new read dates ''' + request = self.factory.post( + '', { + 'start_date': '2017-01-01', + 'finish_date': '2018-03-07', + 'book': self.book.id, + 'id': '', + }) + request.user = self.local_user + + actions.create_readthrough(request) + readthrough = models.ReadThrough.objects.get() + self.assertEqual(readthrough.start_date.year, 2017) + self.assertEqual(readthrough.start_date.month, 1) + self.assertEqual(readthrough.start_date.day, 1) + self.assertEqual(readthrough.finish_date.year, 2018) + self.assertEqual(readthrough.finish_date.month, 3) + self.assertEqual(readthrough.finish_date.day, 7) + self.assertEqual(readthrough.book, self.book) + self.assertEqual(readthrough.user, self.local_user) + + def test_tag(self): ''' add a tag to a book ''' request = self.factory.post(