mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 21:41:25 +00:00
Tests handle import shelving
This commit is contained in:
parent
8c8aae2c92
commit
b2c22c5b7f
1 changed files with 55 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
''' sending out activities '''
|
''' sending out activities '''
|
||||||
|
import csv
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
@ -258,6 +259,60 @@ class Outgoing(TestCase):
|
||||||
self.assertEqual(self.shelf.books.count(), 0)
|
self.assertEqual(self.shelf.books.count(), 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_imported_book(self):
|
||||||
|
''' goodreads import added a book, this adds related connections '''
|
||||||
|
shelf = self.local_user.shelf_set.filter(identifier='read').first()
|
||||||
|
self.assertIsNone(shelf.books.first())
|
||||||
|
|
||||||
|
import_job = models.ImportJob.objects.create(user=self.local_user)
|
||||||
|
datafile = pathlib.Path(__file__).parent.joinpath('data/goodreads.csv')
|
||||||
|
csv_file = open(datafile, 'r')
|
||||||
|
for index, entry in enumerate(list(csv.DictReader(csv_file))):
|
||||||
|
import_item = models.ImportItem.objects.create(
|
||||||
|
job_id=import_job.id, index=index, data=entry, book=self.book)
|
||||||
|
break
|
||||||
|
|
||||||
|
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||||
|
outgoing.handle_imported_book(
|
||||||
|
self.local_user, import_item, False, 'public')
|
||||||
|
|
||||||
|
shelf.refresh_from_db()
|
||||||
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
|
|
||||||
|
readthrough = models.ReadThrough.objects.get(user=self.local_user)
|
||||||
|
self.assertEqual(readthrough.book, self.book)
|
||||||
|
self.assertEqual(readthrough.start_date.year, 2020)
|
||||||
|
self.assertEqual(readthrough.start_date.month, 10)
|
||||||
|
self.assertEqual(readthrough.start_date.day, 21)
|
||||||
|
self.assertEqual(readthrough.finish_date.year, 2020)
|
||||||
|
self.assertEqual(readthrough.finish_date.month, 10)
|
||||||
|
self.assertEqual(readthrough.finish_date.day, 25)
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_imported_book_already_shelved(self):
|
||||||
|
''' goodreads import added a book, this adds related connections '''
|
||||||
|
shelf = self.local_user.shelf_set.filter(identifier='to-read').first()
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
shelf=shelf, added_by=self.local_user, book=self.book)
|
||||||
|
|
||||||
|
import_job = models.ImportJob.objects.create(user=self.local_user)
|
||||||
|
datafile = pathlib.Path(__file__).parent.joinpath('data/goodreads.csv')
|
||||||
|
csv_file = open(datafile, 'r')
|
||||||
|
for index, entry in enumerate(list(csv.DictReader(csv_file))):
|
||||||
|
import_item = models.ImportItem.objects.create(
|
||||||
|
job_id=import_job.id, index=index, data=entry, book=self.book)
|
||||||
|
break
|
||||||
|
|
||||||
|
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||||
|
outgoing.handle_imported_book(
|
||||||
|
self.local_user, import_item, False, 'public')
|
||||||
|
|
||||||
|
shelf.refresh_from_db()
|
||||||
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
|
self.assertIsNone(
|
||||||
|
self.local_user.shelf_set.get(identifier='read').books.first())
|
||||||
|
|
||||||
|
|
||||||
def test_handle_status(self):
|
def test_handle_status(self):
|
||||||
''' create a status '''
|
''' create a status '''
|
||||||
form = forms.CommentForm({
|
form = forms.CommentForm({
|
||||||
|
|
Loading…
Reference in a new issue