From 768ce1e5e79a9b86adb0d4aa566bdb192bfdce53 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 9 May 2020 17:10:02 -0700 Subject: [PATCH] split tests into separate files --- fedireads/tests/test_book_model.py | 44 ++++++++++ .../{test_models.py => test_import_model.py} | 86 +------------------ fedireads/tests/test_status_model.py | 60 +++++++++++++ 3 files changed, 105 insertions(+), 85 deletions(-) create mode 100644 fedireads/tests/test_book_model.py rename fedireads/tests/{test_models.py => test_import_model.py} (52%) create mode 100644 fedireads/tests/test_status_model.py diff --git a/fedireads/tests/test_book_model.py b/fedireads/tests/test_book_model.py new file mode 100644 index 00000000..58cc8fc0 --- /dev/null +++ b/fedireads/tests/test_book_model.py @@ -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) diff --git a/fedireads/tests/test_models.py b/fedireads/tests/test_import_model.py similarity index 52% rename from fedireads/tests/test_models.py rename to fedireads/tests/test_import_model.py index 5af338fa..bcdcafb9 100644 --- a/fedireads/tests/test_models.py +++ b/fedireads/tests/test_import_model.py @@ -1,35 +1,8 @@ ''' testing models ''' import datetime - 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) +from fedireads import models class ImportJob(TestCase): @@ -138,61 +111,4 @@ class ImportJob(TestCase): 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) diff --git a/fedireads/tests/test_status_model.py b/fedireads/tests/test_status_model.py new file mode 100644 index 00000000..6d221d62 --- /dev/null +++ b/fedireads/tests/test_status_model.py @@ -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') +