rename main code directory
This commit is contained in:
1
bookwyrm/tests/models/__init__.py
Normal file
1
bookwyrm/tests/models/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import *
|
25
bookwyrm/tests/models/test_base_model.py
Normal file
25
bookwyrm/tests/models/test_base_model.py
Normal file
@ -0,0 +1,25 @@
|
||||
''' testing models '''
|
||||
from django.test import TestCase
|
||||
|
||||
from fedireads import models
|
||||
from fedireads.models.base_model import FedireadsModel
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
class BaseModel(TestCase):
|
||||
def test_remote_id(self):
|
||||
instance = FedireadsModel()
|
||||
instance.id = 1
|
||||
expected = instance.get_remote_id()
|
||||
self.assertEqual(expected, 'https://%s/fedireadsmodel/1' % DOMAIN)
|
||||
|
||||
def test_remote_id_with_user(self):
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword')
|
||||
instance = FedireadsModel()
|
||||
instance.user = user
|
||||
instance.id = 1
|
||||
expected = instance.get_remote_id()
|
||||
self.assertEqual(
|
||||
expected,
|
||||
'https://%s/user/mouse/fedireadsmodel/1' % DOMAIN)
|
63
bookwyrm/tests/models/test_book_model.py
Normal file
63
bookwyrm/tests/models/test_book_model.py
Normal file
@ -0,0 +1,63 @@
|
||||
''' testing models '''
|
||||
from django.test import TestCase
|
||||
|
||||
from fedireads import models, settings
|
||||
|
||||
|
||||
class Book(TestCase):
|
||||
''' not too much going on in the books model but here we are '''
|
||||
def setUp(self):
|
||||
self.work = models.Work.objects.create(
|
||||
title='Example Work',
|
||||
remote_id='https://example.com/book/1'
|
||||
)
|
||||
self.first_edition = models.Edition.objects.create(
|
||||
title='Example Edition',
|
||||
parent_work=self.work,
|
||||
)
|
||||
self.second_edition = models.Edition.objects.create(
|
||||
title='Another Example Edition',
|
||||
parent_work=self.work,
|
||||
)
|
||||
|
||||
def test_remote_id(self):
|
||||
local_id = 'https://%s/book/%d' % (settings.DOMAIN, self.work.id)
|
||||
self.assertEqual(self.work.get_remote_id(), local_id)
|
||||
self.assertEqual(self.work.remote_id, 'https://example.com/book/1')
|
||||
|
||||
def test_local_id(self):
|
||||
''' the local_id property for books '''
|
||||
expected_id = 'https://%s/book/%d' % (settings.DOMAIN, self.work.id)
|
||||
self.assertEqual(self.work.local_id, expected_id)
|
||||
|
||||
def test_create_book(self):
|
||||
''' you shouldn't be able to create Books (only editions and works) '''
|
||||
self.assertRaises(
|
||||
ValueError,
|
||||
models.Book.objects.create,
|
||||
title='Invalid Book'
|
||||
)
|
||||
|
||||
def test_default_edition(self):
|
||||
''' a work should always be able to produce a deafult edition '''
|
||||
self.assertIsInstance(self.work.default_edition, models.Edition)
|
||||
self.assertEqual(self.work.default_edition, self.first_edition)
|
||||
|
||||
self.second_edition.default = True
|
||||
self.second_edition.save()
|
||||
|
||||
self.assertEqual(self.work.default_edition, self.second_edition)
|
||||
|
||||
|
||||
class Shelf(TestCase):
|
||||
def setUp(self):
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword')
|
||||
models.Shelf.objects.create(
|
||||
name='Test Shelf', identifier='test-shelf', user=user)
|
||||
|
||||
def test_remote_id(self):
|
||||
''' editions and works use the same absolute id syntax '''
|
||||
shelf = models.Shelf.objects.get(identifier='test-shelf')
|
||||
expected_id = 'https://%s/user/mouse/shelf/test-shelf' % settings.DOMAIN
|
||||
self.assertEqual(shelf.get_remote_id(), expected_id)
|
112
bookwyrm/tests/models/test_import_model.py
Normal file
112
bookwyrm/tests/models/test_import_model.py
Normal file
@ -0,0 +1,112 @@
|
||||
''' testing models '''
|
||||
import datetime
|
||||
from django.test import TestCase
|
||||
|
||||
from fedireads import models
|
||||
|
||||
|
||||
class ImportJob(TestCase):
|
||||
''' this is a fancy one!!! '''
|
||||
def setUp(self):
|
||||
''' data is from a goodreads export of The Raven Tower '''
|
||||
read_data = {
|
||||
'Book Id': 39395857,
|
||||
'Title': 'The Raven Tower',
|
||||
'Author': 'Ann Leckie',
|
||||
'Author l-f': 'Leckie, Ann',
|
||||
'Additional Authors': '',
|
||||
'ISBN': '="0356506991"',
|
||||
'ISBN13': '="9780356506999"',
|
||||
'My Rating': 0,
|
||||
'Average Rating': 4.06,
|
||||
'Publisher': 'Orbit',
|
||||
'Binding': 'Hardcover',
|
||||
'Number of Pages': 416,
|
||||
'Year Published': 2019,
|
||||
'Original Publication Year': 2019,
|
||||
'Date Read': '2019/04/09',
|
||||
'Date Added': '2019/04/09',
|
||||
'Bookshelves': '',
|
||||
'Bookshelves with positions': '',
|
||||
'Exclusive Shelf': 'read',
|
||||
'My Review': '',
|
||||
'Spoiler': '',
|
||||
'Private Notes': '',
|
||||
'Read Count': 1,
|
||||
'Recommended For': '',
|
||||
'Recommended By': '',
|
||||
'Owned Copies': 0,
|
||||
'Original Purchase Date': '',
|
||||
'Original Purchase Location': '',
|
||||
'Condition': '',
|
||||
'Condition Description': '',
|
||||
'BCID': ''
|
||||
}
|
||||
currently_reading_data = read_data.copy()
|
||||
currently_reading_data['Exclusive Shelf'] = 'currently-reading'
|
||||
currently_reading_data['Date Read'] = ''
|
||||
|
||||
unknown_read_data = currently_reading_data.copy()
|
||||
unknown_read_data['Exclusive Shelf'] = 'read'
|
||||
unknown_read_data['Date Read'] = ''
|
||||
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword')
|
||||
job = models.ImportJob.objects.create(user=user)
|
||||
models.ImportItem.objects.create(
|
||||
job=job, index=1, data=currently_reading_data)
|
||||
models.ImportItem.objects.create(
|
||||
job=job, index=2, data=read_data)
|
||||
models.ImportItem.objects.create(
|
||||
job=job, index=3, data=unknown_read_data)
|
||||
|
||||
|
||||
def test_isbn(self):
|
||||
''' it unquotes the isbn13 field from data '''
|
||||
expected = '9780356506999'
|
||||
item = models.ImportItem.objects.get(index=1)
|
||||
self.assertEqual(item.isbn, expected)
|
||||
|
||||
|
||||
def test_shelf(self):
|
||||
''' converts to the local shelf typology '''
|
||||
expected = 'reading'
|
||||
item = models.ImportItem.objects.get(index=1)
|
||||
self.assertEqual(item.shelf, expected)
|
||||
|
||||
|
||||
def test_date_added(self):
|
||||
''' converts to the local shelf typology '''
|
||||
expected = datetime.datetime(2019, 4, 9, 0, 0)
|
||||
item = models.ImportItem.objects.get(index=1)
|
||||
self.assertEqual(item.date_added, expected)
|
||||
|
||||
|
||||
def test_date_read(self):
|
||||
''' converts to the local shelf typology '''
|
||||
expected = datetime.datetime(2019, 4, 9, 0, 0)
|
||||
item = models.ImportItem.objects.get(index=2)
|
||||
self.assertEqual(item.date_read, expected)
|
||||
|
||||
|
||||
def test_currently_reading_reads(self):
|
||||
expected = [models.ReadThrough(
|
||||
start_date=datetime.datetime(2019, 4, 9, 0, 0))]
|
||||
actual = models.ImportItem.objects.get(index=1)
|
||||
self.assertEqual(actual.reads[0].start_date, expected[0].start_date)
|
||||
self.assertEqual(actual.reads[0].finish_date, expected[0].finish_date)
|
||||
|
||||
def test_read_reads(self):
|
||||
expected = [models.ReadThrough(
|
||||
finish_date=datetime.datetime(2019, 4, 9, 0, 0))]
|
||||
actual = models.ImportItem.objects.get(index=2)
|
||||
self.assertEqual(actual.reads[0].start_date, expected[0].start_date)
|
||||
self.assertEqual(actual.reads[0].finish_date, expected[0].finish_date)
|
||||
|
||||
def test_unread_reads(self):
|
||||
expected = []
|
||||
actual = models.ImportItem.objects.get(index=3)
|
||||
self.assertEqual(actual.reads, expected)
|
||||
|
||||
|
||||
|
52
bookwyrm/tests/models/test_status_model.py
Normal file
52
bookwyrm/tests/models/test_status_model.py
Normal file
@ -0,0 +1,52 @@
|
||||
''' testing models '''
|
||||
from django.test import TestCase
|
||||
|
||||
from fedireads import models, settings
|
||||
|
||||
|
||||
class Status(TestCase):
|
||||
def setUp(self):
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword')
|
||||
book = models.Edition.objects.create(title='Example Edition')
|
||||
|
||||
models.Status.objects.create(user=user, content='Blah blah')
|
||||
models.Comment.objects.create(user=user, content='content', book=book)
|
||||
models.Quotation.objects.create(
|
||||
user=user, content='content', book=book, quote='blah')
|
||||
models.Review.objects.create(
|
||||
user=user, content='content', book=book, rating=3)
|
||||
|
||||
def test_status(self):
|
||||
status = models.Status.objects.first()
|
||||
expected_id = 'https://%s/user/mouse/status/%d' % \
|
||||
(settings.DOMAIN, status.id)
|
||||
self.assertEqual(status.remote_id, expected_id)
|
||||
|
||||
def test_comment(self):
|
||||
comment = models.Comment.objects.first()
|
||||
expected_id = 'https://%s/user/mouse/comment/%d' % \
|
||||
(settings.DOMAIN, comment.id)
|
||||
self.assertEqual(comment.remote_id, expected_id)
|
||||
|
||||
def test_quotation(self):
|
||||
quotation = models.Quotation.objects.first()
|
||||
expected_id = 'https://%s/user/mouse/quotation/%d' % \
|
||||
(settings.DOMAIN, quotation.id)
|
||||
self.assertEqual(quotation.remote_id, expected_id)
|
||||
|
||||
def test_review(self):
|
||||
review = models.Review.objects.first()
|
||||
expected_id = 'https://%s/user/mouse/review/%d' % \
|
||||
(settings.DOMAIN, review.id)
|
||||
self.assertEqual(review.remote_id, expected_id)
|
||||
|
||||
|
||||
class Tag(TestCase):
|
||||
def test_tag(self):
|
||||
book = models.Edition.objects.create(title='Example Edition')
|
||||
user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword')
|
||||
tag = models.Tag.objects.create(user=user, book=book, name='t/est tag')
|
||||
self.assertEqual(tag.identifier, 't%2Fest+tag')
|
||||
|
34
bookwyrm/tests/models/test_user_model.py
Normal file
34
bookwyrm/tests/models/test_user_model.py
Normal file
@ -0,0 +1,34 @@
|
||||
''' testing models '''
|
||||
from django.test import TestCase
|
||||
|
||||
from fedireads import models
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
class User(TestCase):
|
||||
def setUp(self):
|
||||
models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword')
|
||||
|
||||
def test_computed_fields(self):
|
||||
''' username instead of id here '''
|
||||
user = models.User.objects.get(localname='mouse')
|
||||
expected_id = 'https://%s/user/mouse' % DOMAIN
|
||||
self.assertEqual(user.remote_id, expected_id)
|
||||
self.assertEqual(user.username, 'mouse@%s' % DOMAIN)
|
||||
self.assertEqual(user.localname, 'mouse')
|
||||
self.assertEqual(user.shared_inbox, 'https://%s/inbox' % DOMAIN)
|
||||
self.assertEqual(user.inbox, '%s/inbox' % expected_id)
|
||||
self.assertEqual(user.outbox, '%s/outbox' % expected_id)
|
||||
self.assertIsNotNone(user.private_key)
|
||||
self.assertIsNotNone(user.public_key)
|
||||
|
||||
|
||||
def test_user_shelves(self):
|
||||
user = models.User.objects.get(localname='mouse')
|
||||
shelves = models.Shelf.objects.filter(user=user).all()
|
||||
self.assertEqual(len(shelves), 3)
|
||||
names = [s.name for s in shelves]
|
||||
self.assertEqual(names, ['To Read', 'Currently Reading', 'Read'])
|
||||
ids = [s.identifier for s in shelves]
|
||||
self.assertEqual(ids, ['to-read', 'reading', 'read'])
|
Reference in New Issue
Block a user