forked from mirrors/bookwyrm
Adds tests
This commit is contained in:
parent
327020f7b3
commit
ef9e130669
1 changed files with 66 additions and 0 deletions
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue