mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 13:31:08 +00:00
split tests into separate files
This commit is contained in:
parent
4468933edd
commit
768ce1e5e7
3 changed files with 105 additions and 85 deletions
44
fedireads/tests/test_book_model.py
Normal file
44
fedireads/tests/test_book_model.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
''' 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):
|
||||||
|
work = models.Work.objects.create(title='Example Work')
|
||||||
|
models.Edition.objects.create(title='Example Edition', parent_work=work)
|
||||||
|
|
||||||
|
def test_absolute_id(self):
|
||||||
|
''' editions and works use the same absolute id syntax '''
|
||||||
|
book = models.Edition.objects.first()
|
||||||
|
expected_id = 'https://%s/book/%d' % (settings.DOMAIN, book.id)
|
||||||
|
self.assertEqual(book.absolute_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 '''
|
||||||
|
default_edition = models.Work.objects.first().default_edition
|
||||||
|
self.assertIsInstance(default_edition, models.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_absolute_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.absolute_id, expected_id)
|
|
@ -1,35 +1,8 @@
|
||||||
''' testing models '''
|
''' testing models '''
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from fedireads import models, settings
|
from fedireads import models
|
||||||
|
|
||||||
|
|
||||||
class Book(TestCase):
|
|
||||||
''' not too much going on in the books model but here we are '''
|
|
||||||
def setUp(self):
|
|
||||||
work = models.Work.objects.create(title='Example Work')
|
|
||||||
models.Edition.objects.create(title='Example Edition', parent_work=work)
|
|
||||||
|
|
||||||
def test_absolute_id(self):
|
|
||||||
''' editions and works use the same absolute id syntax '''
|
|
||||||
book = models.Edition.objects.first()
|
|
||||||
expected_id = 'https://%s/book/%d' % (settings.DOMAIN, book.id)
|
|
||||||
self.assertEqual(book.absolute_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 '''
|
|
||||||
default_edition = models.Work.objects.first().default_edition
|
|
||||||
self.assertIsInstance(default_edition, models.Edition)
|
|
||||||
|
|
||||||
|
|
||||||
class ImportJob(TestCase):
|
class ImportJob(TestCase):
|
||||||
|
@ -138,61 +111,4 @@ class ImportJob(TestCase):
|
||||||
self.assertEqual(actual.reads, expected)
|
self.assertEqual(actual.reads, expected)
|
||||||
|
|
||||||
|
|
||||||
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_absolute_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.absolute_id, expected_id)
|
|
||||||
|
|
||||||
|
|
||||||
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()
|
|
||||||
self.assertEqual(status.status_type, 'Note')
|
|
||||||
self.assertEqual(status.activity_type, 'Note')
|
|
||||||
expected_id = 'https://%s/user/mouse/status/%d' % \
|
|
||||||
(settings.DOMAIN, status.id)
|
|
||||||
self.assertEqual(status.absolute_id, expected_id)
|
|
||||||
|
|
||||||
def test_comment(self):
|
|
||||||
comment = models.Comment.objects.first()
|
|
||||||
self.assertEqual(comment.status_type, 'Comment')
|
|
||||||
self.assertEqual(comment.activity_type, 'Note')
|
|
||||||
expected_id = 'https://%s/user/mouse/comment/%d' % \
|
|
||||||
(settings.DOMAIN, comment.id)
|
|
||||||
self.assertEqual(comment.absolute_id, expected_id)
|
|
||||||
|
|
||||||
def test_quotation(self):
|
|
||||||
quotation = models.Quotation.objects.first()
|
|
||||||
self.assertEqual(quotation.status_type, 'Quotation')
|
|
||||||
self.assertEqual(quotation.activity_type, 'Note')
|
|
||||||
expected_id = 'https://%s/user/mouse/quotation/%d' % \
|
|
||||||
(settings.DOMAIN, quotation.id)
|
|
||||||
self.assertEqual(quotation.absolute_id, expected_id)
|
|
||||||
|
|
||||||
def test_review(self):
|
|
||||||
review = models.Review.objects.first()
|
|
||||||
self.assertEqual(review.status_type, 'Review')
|
|
||||||
self.assertEqual(review.activity_type, 'Article')
|
|
||||||
expected_id = 'https://%s/user/mouse/review/%d' % \
|
|
||||||
(settings.DOMAIN, review.id)
|
|
||||||
self.assertEqual(review.absolute_id, expected_id)
|
|
60
fedireads/tests/test_status_model.py
Normal file
60
fedireads/tests/test_status_model.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
''' 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()
|
||||||
|
self.assertEqual(status.status_type, 'Note')
|
||||||
|
self.assertEqual(status.activity_type, 'Note')
|
||||||
|
expected_id = 'https://%s/user/mouse/status/%d' % \
|
||||||
|
(settings.DOMAIN, status.id)
|
||||||
|
self.assertEqual(status.absolute_id, expected_id)
|
||||||
|
|
||||||
|
def test_comment(self):
|
||||||
|
comment = models.Comment.objects.first()
|
||||||
|
self.assertEqual(comment.status_type, 'Comment')
|
||||||
|
self.assertEqual(comment.activity_type, 'Note')
|
||||||
|
expected_id = 'https://%s/user/mouse/comment/%d' % \
|
||||||
|
(settings.DOMAIN, comment.id)
|
||||||
|
self.assertEqual(comment.absolute_id, expected_id)
|
||||||
|
|
||||||
|
def test_quotation(self):
|
||||||
|
quotation = models.Quotation.objects.first()
|
||||||
|
self.assertEqual(quotation.status_type, 'Quotation')
|
||||||
|
self.assertEqual(quotation.activity_type, 'Note')
|
||||||
|
expected_id = 'https://%s/user/mouse/quotation/%d' % \
|
||||||
|
(settings.DOMAIN, quotation.id)
|
||||||
|
self.assertEqual(quotation.absolute_id, expected_id)
|
||||||
|
|
||||||
|
def test_review(self):
|
||||||
|
review = models.Review.objects.first()
|
||||||
|
self.assertEqual(review.status_type, 'Review')
|
||||||
|
self.assertEqual(review.activity_type, 'Article')
|
||||||
|
expected_id = 'https://%s/user/mouse/review/%d' % \
|
||||||
|
(settings.DOMAIN, review.id)
|
||||||
|
self.assertEqual(review.absolute_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')
|
||||||
|
|
Loading…
Reference in a new issue