Merge branch 'master' into ola_fulfill
commit
08e18bbcd3
12
api/tests.py
12
api/tests.py
|
@ -13,7 +13,7 @@ class ApiTests(TestCase):
|
|||
work_id=None
|
||||
|
||||
def setUp(self):
|
||||
edition = bookloader.add_by_isbn_from_google(isbn='0441012035')
|
||||
edition = bookloader.add_by_isbn_from_google(isbn='0441007465')
|
||||
self.work_id=edition.work.id
|
||||
campaign = models.Campaign.objects.create(
|
||||
name=edition.work.title,
|
||||
|
@ -58,7 +58,7 @@ class ApiTests(TestCase):
|
|||
def test_campaign_lookup_by_isbn(self):
|
||||
r = self.client.get('/api/v1/campaign/', data={
|
||||
'format': 'json',
|
||||
'work__identifiers__value': regluit.core.isbn.convert_10_to_13('0441012035'),
|
||||
'work__identifiers__value': regluit.core.isbn.convert_10_to_13('0441007465'),
|
||||
'work__identifiers__type': 'isbn',
|
||||
'username': self.user.username,
|
||||
'api_key': self.user.api_key.key
|
||||
|
@ -73,7 +73,7 @@ class ApiTests(TestCase):
|
|||
def test_identifier_lookup(self):
|
||||
r = self.client.get('/api/v1/identifier/', data={
|
||||
'format': 'json',
|
||||
'value': regluit.core.isbn.convert_10_to_13('0441012035'),
|
||||
'value': regluit.core.isbn.convert_10_to_13('0441007465'),
|
||||
'type': 'isbn',
|
||||
'username': self.user.username,
|
||||
'api_key': self.user.api_key.key
|
||||
|
@ -87,7 +87,7 @@ class ApiTests(TestCase):
|
|||
|
||||
r = self.client.get('/api/v1/campaign/', data={
|
||||
'format': 'json',
|
||||
'work__identifiers__value': regluit.core.isbn.convert_10_to_13('0441012035'),
|
||||
'work__identifiers__value': regluit.core.isbn.convert_10_to_13('0441007465'),
|
||||
'work__identifiers__type': 'isbn',
|
||||
'username': self.user.username,
|
||||
'api_key': self.user.api_key.key
|
||||
|
@ -96,11 +96,11 @@ class ApiTests(TestCase):
|
|||
self.assertEqual(j['meta']['logged_in_username'], 'test')
|
||||
self.assertEqual(j['objects'][0]['in_wishlist'], False)
|
||||
|
||||
w = models.Work.objects.get(identifiers__value=regluit.core.isbn.convert_10_to_13('0441012035'), identifiers__type='isbn')
|
||||
w = models.Work.objects.get(identifiers__value=regluit.core.isbn.convert_10_to_13('0441007465'), identifiers__type='isbn')
|
||||
self.user.wishlist.add_work(w,'test')
|
||||
r = self.client.get('/api/v1/campaign/', data={
|
||||
'format': 'json',
|
||||
'work__identifiers__value': regluit.core.isbn.convert_10_to_13('0441012035'),
|
||||
'work__identifiers__value': regluit.core.isbn.convert_10_to_13('0441007465'),
|
||||
'work__identifiers__type': 'isbn',
|
||||
'username': self.user.username,
|
||||
'api_key': self.user.api_key.key
|
||||
|
|
|
@ -35,13 +35,13 @@ class BookLoaderTests(TestCase):
|
|||
|
||||
def test_add_by_isbn(self):
|
||||
# edition
|
||||
edition = bookloader.add_by_isbn('0441012035')
|
||||
edition = bookloader.add_by_isbn('0441007465')
|
||||
self.assertEqual(edition.title, 'Neuromancer')
|
||||
self.assertEqual(edition.publication_date, '2004')
|
||||
self.assertEqual(edition.publisher, u'Ace Hardcover')
|
||||
self.assertEqual(edition.isbn_10, '0441012035')
|
||||
self.assertEqual(edition.isbn_13, '9780441012039')
|
||||
self.assertEqual(edition.googlebooks_id, "2NyiPwAACAAJ")
|
||||
self.assertEqual(edition.publication_date, u'2000-07-01')
|
||||
self.assertEqual(edition.publisher, u'Ace Trade')
|
||||
self.assertEqual(edition.isbn_10, '0441007465')
|
||||
self.assertEqual(edition.isbn_13, '9780441007462')
|
||||
self.assertEqual(edition.googlebooks_id, 'IDFfMPW32hQC')
|
||||
|
||||
# authors
|
||||
self.assertEqual(edition.authors.all().count(), 1)
|
||||
|
@ -66,8 +66,8 @@ class BookLoaderTests(TestCase):
|
|||
self.assertEqual(e.title, 'Forbidden Journeys')
|
||||
|
||||
def test_double_add(self):
|
||||
bookloader.add_by_isbn('0441012035')
|
||||
bookloader.add_by_isbn('0441012035')
|
||||
bookloader.add_by_isbn('0441007465')
|
||||
bookloader.add_by_isbn('0441007465')
|
||||
self.assertEqual(models.Edition.objects.all().count(), 1)
|
||||
self.assertEqual(models.Author.objects.all().count(), 1)
|
||||
self.assertEqual(models.Work.objects.all().count(), 1)
|
||||
|
@ -77,19 +77,19 @@ class BookLoaderTests(TestCase):
|
|||
self.assertEqual(e, None)
|
||||
|
||||
def test_thingisbn(self):
|
||||
isbns = bookloader.thingisbn('0441012035')
|
||||
isbns = bookloader.thingisbn('0441007465')
|
||||
self.assertTrue(len(isbns) > 20)
|
||||
self.assertTrue('0441012035' in isbns)
|
||||
self.assertTrue('0441007465' in isbns)
|
||||
self.assertTrue('3453313895' in isbns)
|
||||
|
||||
def test_add_related(self):
|
||||
# add one edition
|
||||
edition = bookloader.add_by_isbn('0441012035')
|
||||
edition = bookloader.add_by_isbn('0441007465')
|
||||
self.assertEqual(models.Edition.objects.count(), 1)
|
||||
self.assertEqual(models.Work.objects.count(), 1)
|
||||
lang=edition.work.language
|
||||
# ask for related editions to be added using the work we just created
|
||||
bookloader.add_related('0441012035')
|
||||
bookloader.add_related('0441007465')
|
||||
self.assertTrue(models.Edition.objects.count() > 15)
|
||||
self.assertEqual(models.Work.objects.filter(language=lang).count(), 1)
|
||||
self.assertTrue(edition.work.editions.count() > 9)
|
||||
|
@ -279,9 +279,13 @@ class BookLoaderTests(TestCase):
|
|||
e = bookloader.add_by_isbn('0465019358')
|
||||
self.assertTrue(e)
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_one_language(self):
|
||||
# english edition for cat's cradle should only pull in other
|
||||
# english editions
|
||||
# expected failure right now because Google seems to have bad data about language of Cat's Cradle
|
||||
# e.g., https://www.googleapis.com/books/v1/volumes?q=isbn:9789513033774
|
||||
# title = "Kissan kehto" -- language according to API = English
|
||||
work = bookloader.add_by_isbn('079530272X').work
|
||||
self.assertEqual(work.language, 'en')
|
||||
bookloader.add_related('079530272X')
|
||||
|
@ -289,14 +293,14 @@ class BookLoaderTests(TestCase):
|
|||
self.assertEqual(edition.title.lower(), "cat's cradle")
|
||||
|
||||
def test_add_openlibrary(self):
|
||||
work = bookloader.add_by_isbn('0441012035').work
|
||||
bookloader.add_related('0441012035')
|
||||
work = bookloader.add_by_isbn('0441007465').work
|
||||
bookloader.add_related('0441007465')
|
||||
bookloader.add_openlibrary(work)
|
||||
subjects = [s.name for s in work.subjects.all()]
|
||||
self.assertTrue(len(subjects) > 10)
|
||||
self.assertTrue('Science fiction' in subjects)
|
||||
self.assertTrue('/works/OL27258W' in work.identifiers.filter(type='olwk').values_list('value',flat=True) )
|
||||
self.assertTrue('14770' in work.identifiers.filter(type='gdrd').values_list('value',flat=True))
|
||||
self.assertTrue('888628' in work.identifiers.filter(type='gdrd').values_list('value',flat=True))
|
||||
self.assertTrue('609' in work.identifiers.filter(type='ltwk').values_list('value',flat=True))
|
||||
|
||||
def test_load_gutenberg_edition(self):
|
||||
|
@ -448,7 +452,6 @@ class CampaignTests(TestCase):
|
|||
t.campaign = c6
|
||||
t.user = user
|
||||
t.save()
|
||||
print w2.percent_of_goal()
|
||||
self.assertEqual(w2.percent_of_goal(), 23)
|
||||
|
||||
class WishlistTest(TestCase):
|
||||
|
@ -456,7 +459,7 @@ class WishlistTest(TestCase):
|
|||
def test_add_remove(self):
|
||||
# add a work to a user's wishlist
|
||||
user = User.objects.create_user('test', 'test@example.com', 'testpass')
|
||||
edition = bookloader.add_by_isbn('0441012035')
|
||||
edition = bookloader.add_by_isbn('0441007465')
|
||||
work = edition.work
|
||||
num_wishes=work.num_wishes
|
||||
user.wishlist.add_work(work, 'test')
|
||||
|
|
Loading…
Reference in New Issue