Runs black

This commit is contained in:
Mouse Reeve
2021-03-08 08:49:10 -08:00
parent a07f955781
commit 70296e760b
198 changed files with 10239 additions and 8572 deletions

View File

@ -1,4 +1,4 @@
''' tests updating reading progress '''
""" tests updating reading progress """
from datetime import datetime
from unittest.mock import patch
from django.test import TestCase, Client
@ -6,63 +6,68 @@ from django.utils import timezone
from bookwyrm import models
@patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay')
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class ReadThrough(TestCase):
''' readthrough tests '''
""" readthrough tests """
def setUp(self):
''' basic user and book data '''
""" basic user and book data """
self.client = Client()
self.work = models.Work.objects.create(
title='Example Work'
)
self.work = models.Work.objects.create(title="Example Work")
self.edition = models.Edition.objects.create(
title='Example Edition',
parent_work=self.work
title="Example Edition", parent_work=self.work
)
self.work.default_edition = self.edition
self.work.save()
self.user = models.User.objects.create_user(
'cinco', 'cinco@example.com', 'seissiete',
local=True, localname='cinco')
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
)
with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
self.client.force_login(self.user)
def test_create_basic_readthrough(self, delay_mock):
"""A basic readthrough doesn't create a progress update"""
self.assertEqual(self.edition.readthrough_set.count(), 0)
self.client.post('/start-reading/{}'.format(self.edition.id), {
'start_date': '2020-11-27',
})
self.client.post(
"/start-reading/{}".format(self.edition.id),
{
"start_date": "2020-11-27",
},
)
readthroughs = self.edition.readthrough_set.all()
self.assertEqual(len(readthroughs), 1)
self.assertEqual(readthroughs[0].progressupdate_set.count(), 0)
self.assertEqual(
readthroughs[0].start_date,
datetime(2020, 11, 27, tzinfo=timezone.utc))
readthroughs[0].start_date, datetime(2020, 11, 27, tzinfo=timezone.utc)
)
self.assertEqual(readthroughs[0].progress, None)
self.assertEqual(readthroughs[0].finish_date, None)
self.assertEqual(delay_mock.call_count, 1)
def test_create_progress_readthrough(self, delay_mock):
''' a readthrough with progress '''
""" a readthrough with progress """
self.assertEqual(self.edition.readthrough_set.count(), 0)
self.client.post('/start-reading/{}'.format(self.edition.id), {
'start_date': '2020-11-27',
'progress': 50,
})
self.client.post(
"/start-reading/{}".format(self.edition.id),
{
"start_date": "2020-11-27",
"progress": 50,
},
)
readthroughs = self.edition.readthrough_set.all()
self.assertEqual(len(readthroughs), 1)
self.assertEqual(
readthroughs[0].start_date,
datetime(2020, 11, 27, tzinfo=timezone.utc))
readthroughs[0].start_date, datetime(2020, 11, 27, tzinfo=timezone.utc)
)
self.assertEqual(readthroughs[0].progress, 50)
self.assertEqual(readthroughs[0].finish_date, None)
@ -73,13 +78,17 @@ class ReadThrough(TestCase):
self.assertEqual(delay_mock.call_count, 1)
# Update progress
self.client.post('/edit-readthrough', {
'id': readthroughs[0].id,
'progress': 100,
})
self.client.post(
"/edit-readthrough",
{
"id": readthroughs[0].id,
"progress": 100,
},
)
progress_updates = readthroughs[0].progressupdate_set\
.order_by('updated_date').all()
progress_updates = (
readthroughs[0].progressupdate_set.order_by("updated_date").all()
)
self.assertEqual(len(progress_updates), 2)
self.assertEqual(progress_updates[1].mode, models.ProgressMode.PAGE)
self.assertEqual(progress_updates[1].progress, 100)
@ -87,9 +96,12 @@ class ReadThrough(TestCase):
# Edit doesn't publish anything
self.assertEqual(delay_mock.call_count, 1)
self.client.post('/delete-readthrough', {
'id': readthroughs[0].id,
})
self.client.post(
"/delete-readthrough",
{
"id": readthroughs[0].id,
},
)
readthroughs = self.edition.readthrough_set.all()
updates = self.user.progressupdate_set.all()