shelf model unit test

also fixes my bad logic in the import job tests
This commit is contained in:
Mouse Reeve 2020-05-09 16:38:05 -07:00
parent 93e53d3cca
commit 49cdd5388f
1 changed files with 31 additions and 24 deletions

View File

@ -75,6 +75,7 @@ class ImportJob(TestCase):
unknown_read_data = currently_reading_data.copy() unknown_read_data = currently_reading_data.copy()
unknown_read_data['Exclusive Shelf'] = 'read' unknown_read_data['Exclusive Shelf'] = 'read'
unknown_read_data['Date Read'] = ''
user = models.User.objects.create_user( user = models.User.objects.create_user(
'mouse', 'mouse@mouse.mouse', 'mouseword') 'mouse', 'mouse@mouse.mouse', 'mouseword')
@ -117,29 +118,35 @@ class ImportJob(TestCase):
def test_reads(self): def test_reads(self):
''' various states of reading ''' ''' various states of reading '''
expected_current = [models.ReadThrough( # currently reading
start_date=datetime.datetime(2019, 4, 9, 0, 0), expected = [models.ReadThrough(
finish_date=None start_date=datetime.datetime(2019, 4, 9, 0, 0))]
)] actual = models.ImportItem.objects.get(index=1)
expected_read = [models.ReadThrough( self.assertEqual(actual.reads[0].start_date, expected[0].start_date)
start_date=datetime.datetime(2019, 4, 9, 0, 0), self.assertEqual(actual.reads[0].finish_date, expected[0].finish_date)
finish_date=datetime.datetime(2019, 4, 9, 0, 0),
)]
expected_unknown = [models.ReadThrough(
start_date=None,
finish_date=None
)]
expecteds = [expected_current, expected_read, expected_unknown]
actuals = [ # read
models.ImportItem.objects.get(index=1), expected = [models.ReadThrough(
models.ImportItem.objects.get(index=2), finish_date=datetime.datetime(2019, 4, 9, 0, 0))]
models.ImportItem.objects.get(index=3), actual = models.ImportItem.objects.get(index=2)
] self.assertEqual(actual.reads[0].start_date, expected[0].start_date)
for (expected, actual) in zip(expecteds, actuals): self.assertEqual(actual.reads[0].finish_date, expected[0].finish_date)
actual = actual.reads
self.assertIsInstance(actual, list) # unknown dates
self.assertIsInstance(actual, models.ReadThrough) expected = []
self.assertEqual(actual[0].start_date, expected[0].start_date) actual = models.ImportItem.objects.get(index=3)
self.assertEqual(actual[0].finish_date, expected[0].finish_date) 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)