From 9a985176bcfb3bf4e44d1c36e490e40a47a91d50 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Fri, 20 Jul 2012 08:40:11 -0700 Subject: [PATCH 1/2] Fixed problems in tests stemming from an edition of Neuromancer no longer in Google Books -- switched to another one We still have issues about language of editions for Cat's Cradle --- api/tests.py | 12 ++++++------ core/tests.py | 33 ++++++++++++++++----------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/api/tests.py b/api/tests.py index 755340d8..a97024b5 100755 --- a/api/tests.py +++ b/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 diff --git a/core/tests.py b/core/tests.py index 6a7ac2cb..7f790ae1 100755 --- a/core/tests.py +++ b/core/tests.py @@ -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) @@ -289,14 +289,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 +448,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 +455,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') From 6c7e9594c05bc61b263fcc9c78ea64ddef12df80 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Fri, 20 Jul 2012 09:28:14 -0700 Subject: [PATCH 2/2] [#33125113] Marking the language test for Cat's Eye as expected failure because I think Google has bad data for this work. Worth looking at other books --- core/tests.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/tests.py b/core/tests.py index 7f790ae1..e9b860d6 100755 --- a/core/tests.py +++ b/core/tests.py @@ -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')