From d82cda07ba29ee0a12ae529ed0695d71ae5111f4 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Wed, 12 Oct 2011 15:48:41 -0700 Subject: [PATCH 1/2] Load campaign with Decimal target amount. --- core/management/commands/random_campaigns.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/management/commands/random_campaigns.py b/core/management/commands/random_campaigns.py index d032240d..f7050331 100644 --- a/core/management/commands/random_campaigns.py +++ b/core/management/commands/random_campaigns.py @@ -1,5 +1,6 @@ from random import randint, randrange from datetime import datetime, timedelta +from decimal import Decimal as D from django.core.management.base import BaseCommand @@ -18,7 +19,7 @@ class Command(BaseCommand): campaign.description = "Test Campaign" # random campaign target between $200 and $10,000 - campaign.target = float(randint(200,10000)) + campaign.target = D(randint(200,10000)) # random deadline between 5 days from now and 180 days from now now = datetime.now() From 983c045a8ce390e70594f6ad26f75f8878ffeecb Mon Sep 17 00:00:00 2001 From: Ed Summers Date: Wed, 12 Oct 2011 21:59:46 -0400 Subject: [PATCH 2/2] added bookloader.thingisbn and a test --- core/bookloader.py | 7 +++++++ core/tests.py | 16 +++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/bookloader.py b/core/bookloader.py index 478a2f63..74e05fe4 100755 --- a/core/bookloader.py +++ b/core/bookloader.py @@ -1,5 +1,6 @@ import json import logging +from xml.etree import ElementTree import requests from django.conf import settings @@ -55,6 +56,12 @@ def add_by_googlebooks_id(googlebooks_id): return e +def thingisbn(isbn): + url = "http://www.librarything.com/api/thingISBN/%s" % isbn + xml = requests.get(url, headers={"User-Agent": settings.USER_AGENT}).content + doc = ElementTree.fromstring(xml) + return [e.text for e in doc.findall('isbn')] + def _get_json(url, params={}): # TODO: should X-Forwarded-For change based on the request from client? headers = {'User-Agent': settings.USER_AGENT, diff --git a/core/tests.py b/core/tests.py index c4b339ab..a4d5d1be 100755 --- a/core/tests.py +++ b/core/tests.py @@ -10,7 +10,7 @@ from regluit.core.models import Campaign, Work, UnglueitError from regluit.core import bookloader, models, search from regluit.payment.parameters import PAYMENT_TYPE_AUTHORIZATION -class TestBooks(TestCase): +class TestBookLoader(TestCase): def test_add_book(self): # edition @@ -46,6 +46,12 @@ class TestBooks(TestCase): e = bookloader.add_by_isbn('0139391401') self.assertEqual(e, None) + def test_thingisbn(self): + isbns = bookloader.thingisbn('0441012035') + self.assertTrue(len(isbns) > 20) + self.assertTrue('0441012035' in isbns) + self.assertTrue('3453313895' in isbns) + class SearchTests(TestCase): def test_basic_search(self): @@ -136,11 +142,3 @@ class CampaignTests(TestCase): c5.save() c5.activate().withdraw('testing') self.assertEqual(c5.status, 'WITHDRAWN') - -def suite(): - - testcases = [TestBooks, SearchTests, CampaignTests] - suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases]) - return suites - -