From 3e782e636dd69a48c9f7cba10c1b7cd18d0e8b9a Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 6 Jun 2018 23:27:08 -0400 Subject: [PATCH 01/12] files for running tests with travis --- .gitignore | 3 ++- .travis.yml | 23 +++++++++++++++++++ settings/travis.py | 55 +++++++++++++++++++++++++++++++++++++++++++++ test/common.py.enc | Bin 0 -> 544 bytes 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 settings/travis.py create mode 100644 test/common.py.enc diff --git a/.gitignore b/.gitignore index 4a693c5d..df1ad729 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ *.pyc *.log settings/me.* -settings/keys/* +settings/keys/c* +settings/keys/h* *.dot reports ENV diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..25378555 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +language: python + +python: + - '2.7' + +services: + - redis-server + - mysql + +env: + global: + - DJANGO_SETTINGS_MODULE=regluit.settings.travis + - PYTHONPATH=/home/travis/build/EbookFoundation/ + +before_install: + - sudo mkdir /var/log/django + - sudo chmod 777 /var/log/django + - openssl aes-256-cbc -K $encrypted_56eb2b7cc527_key -iv $encrypted_56eb2b7cc527_iv -in ~/build/EbookFoundation/regluit/test/common.py.enc -out ~/build/EbookFoundation/regluit/settings/keys/common.py -d + +install: + - pip install -r requirements_versioned.pip + +script: django-admin test diff --git a/settings/travis.py b/settings/travis.py new file mode 100644 index 00000000..dec133c2 --- /dev/null +++ b/settings/travis.py @@ -0,0 +1,55 @@ +# coding=utf-8 +from .common import * + +DEBUG = True +TEMPLATES[0]['OPTIONS']['debug'] = DEBUG +IS_PREVIEW = False + +ADMINS = ( + ('Raymond Yee', 'rdhyee+ungluebugs@gluejar.com'), + ('Eric Hellman', 'eric@gluejar.com'), +) + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'regluit', + 'USER': 'root', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + 'TEST_CHARSET': 'utf8', + } +} + +TIME_ZONE = 'America/New_York' + +# settings for outbout email +# if you have a gmail account you can use your email address and password + +EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend' +MAIL_USE_TLS = True +EMAIL_HOST = 'email-smtp.us-east-1.amazonaws.com' +EMAIL_PORT = 465 +DEFAULT_FROM_EMAIL = 'notices@gluejar.com' + + +# formerly of settings/common.py to surface old vars +# TO DO: invalidate before we open source + +# for use with test google account only +GOOGLE_DISPLAY_NAME = 'Unglue.It' +REDIRECT_IS_HTTPS = False + +#BASE_URL = 'http://0.0.0.0/' +BASE_URL_SECURE = 'http://0.0.0.0/' + +BROKER_TRANSPORT = "redis" +BROKER_HOST = "localhost" +BROKER_PORT = 6379 +BROKER_VHOST = "0" + +# Amazon S3 access +AWS_STORAGE_BUCKET_NAME = 'unglueit-testfiles' diff --git a/test/common.py.enc b/test/common.py.enc new file mode 100644 index 0000000000000000000000000000000000000000..9c6f2c2b6a76f76c332b9b737b5f7f387e3424da GIT binary patch literal 544 zcmV+*0^j}km3t@2?&*v5@bBcbz3nIGX1;&`bhq`x+1#;5hb57Wfl)+c!x|7;B!hF7LbqC^K9@Ls&Y#isMsZ$ zI`rZph#`#)RU}$e7j|`;Ja+XiaCpDatLy*fvxYJvXgPacMoZ$0{tW0K78&mJu@4&x z;}$JbrFfGfKH5Ok!NH2f`@>7%#6k>4{{4AE8QtQDZ!sZ*0&c5fZe5WyQ}|->qpxHP z3O;Ke!8zLc09Q?yf}`TZ%o;I%ia;`jq~5Q!!7iRzptF&H-U$L`vKd_pA#`Z@a>NgAVqU$pcBJ7dMHf;T^J7{phl118+UM~vox zND|-PR0pFx6}yjdC53S*b%499-J_r|ls+w)em{%?b Date: Wed, 6 Jun 2018 23:34:06 -0400 Subject: [PATCH 02/12] user is specific to org --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25378555..6990592c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,12 +10,12 @@ services: env: global: - DJANGO_SETTINGS_MODULE=regluit.settings.travis - - PYTHONPATH=/home/travis/build/EbookFoundation/ + - PYTHONPATH=/home/travis/build/Gluejar/ before_install: - sudo mkdir /var/log/django - sudo chmod 777 /var/log/django - - openssl aes-256-cbc -K $encrypted_56eb2b7cc527_key -iv $encrypted_56eb2b7cc527_iv -in ~/build/EbookFoundation/regluit/test/common.py.enc -out ~/build/EbookFoundation/regluit/settings/keys/common.py -d + - openssl aes-256-cbc -K $encrypted_56eb2b7cc527_key -iv $encrypted_56eb2b7cc527_iv -in ~/build/Gluejar/regluit/test/common.py.enc -out ~/build/Gluejar/regluit/settings/keys/common.py -d install: - pip install -r requirements_versioned.pip From 0deb76b678f1aa578f3a8a38edb80dc9477d27f4 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 7 Jun 2018 09:59:35 -0400 Subject: [PATCH 03/12] make keys a module --- settings/keys/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 settings/keys/__init__.py diff --git a/settings/keys/__init__.py b/settings/keys/__init__.py new file mode 100644 index 00000000..e69de29b From 3028c5f19db5b81b89e017ec2a0c42116da70850 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 7 Jun 2018 12:17:46 -0400 Subject: [PATCH 04/12] re-decrypt --- test/common.py.enc | Bin 544 -> 544 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/common.py.enc b/test/common.py.enc index 9c6f2c2b6a76f76c332b9b737b5f7f387e3424da..9d025ae9bb61ab871fbde619567bc1ce99923aee 100644 GIT binary patch literal 544 zcmV+*0^j|NoHsq>>v6Q!62Df@h=cs2Le&M6z3z|~(u`*aU_RbyKtTxsQB!)(1{lwvz!@!`{oE|n@w%OZ z;hg*1vtNMMom8S3MeW5&!$NyTzof%sKKW{_2^7~_fc#?EIV(%lzA1dMph&{-W?qg= zGQJHGgA!F*bBAq09;<-YO7E@o3HdI zjzH)thhvdyIZ`uYF-0@vtR85sTm>ajDeNF|LZ1dn*f8jMmbDd)Hw!ey+W@C|XAU0i zx=#-j=gj6#l$PkA=$9m(%=JVN8(GtbFdIj(VTJU!>TmKhygNxQ7_2nQt)`P4KjwP6 zx1sHAhq~hO({uI;nzVhkSPag}vV;B|`n4Cg`lCGuA4@T|MC@@tLzCWr$-8jH3832{ zDW8JTQdys$W%+XAWge#sOaVH4K|x$D9s?Y);7jUjy%5$1L{{dEw#0Bs zCBu57h=t|OH)MIjy=KoM(Weq`x+1#;5hb57Wfl)+c!x|7;B!hF7LbqC^K9@Ls&Y#isMsZ$ zI`rZph#`#)RU}$e7j|`;Ja+XiaCpDatLy*fvxYJvXgPacMoZ$0{tW0K78&mJu@4&x z;}$JbrFfGfKH5Ok!NH2f`@>7%#6k>4{{4AE8QtQDZ!sZ*0&c5fZe5WyQ}|->qpxHP z3O;Ke!8zLc09Q?yf}`TZ%o;I%ia;`jq~5Q!!7iRzptF&H-U$L`vKd_pA#`Z@a>NgAVqU$pcBJ7dMHf;T^J7{phl118+UM~vox zND|-PR0pFx6}yjdC53S*b%499-J_r|ls+w)em{%?b Date: Thu, 7 Jun 2018 13:05:25 -0400 Subject: [PATCH 05/12] make sure common.keys overrides common --- settings/common.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/settings/common.py b/settings/common.py index 3a42e422..c300cdfe 100644 --- a/settings/common.py +++ b/settings/common.py @@ -7,11 +7,6 @@ from os.path import dirname, realpath, join import regluit from regluit.payment.parameters import PAYMENT_HOST_PAYPAL, PAYMENT_HOST_AMAZON -try: - from .keys.common import * -except ImportError: - print 'no real key file found, using dummy' - from .dummy.common import * PROJECT_DIR = dirname(dirname(realpath(__file__))) @@ -478,6 +473,11 @@ QUESTIONNAIRE_SHOW_ITEM_RESULTS = False FIREFOX_PATH = '' CHROMEDRIVER_PATH = '' +try: + from .keys.common import * +except ImportError: + print 'no real key file found, using dummy' + from .dummy.common import * try: from .keys.host import * From f75fd07c762315115ba6633bc6bd8a8061639d92 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 7 Jun 2018 14:39:36 -0400 Subject: [PATCH 06/12] use hosts not common --- .travis.yml | 2 +- settings/travis.py | 8 ++++++++ test/{common.py.enc => travis-host.py.enc} | Bin 3 files changed, 9 insertions(+), 1 deletion(-) rename test/{common.py.enc => travis-host.py.enc} (100%) diff --git a/.travis.yml b/.travis.yml index 6990592c..715396c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ env: before_install: - sudo mkdir /var/log/django - sudo chmod 777 /var/log/django - - openssl aes-256-cbc -K $encrypted_56eb2b7cc527_key -iv $encrypted_56eb2b7cc527_iv -in ~/build/Gluejar/regluit/test/common.py.enc -out ~/build/Gluejar/regluit/settings/keys/common.py -d + - openssl aes-256-cbc -K $encrypted_56eb2b7cc527_key -iv $encrypted_56eb2b7cc527_iv -in ~/build/Gluejar/regluit/test/travis-host.py.enc -out ~/build/Gluejar/regluit/settings/keys/host.py -d install: - pip install -r requirements_versioned.pip diff --git a/settings/travis.py b/settings/travis.py index dec133c2..808fcbdf 100644 --- a/settings/travis.py +++ b/settings/travis.py @@ -53,3 +53,11 @@ BROKER_VHOST = "0" # Amazon S3 access AWS_STORAGE_BUCKET_NAME = 'unglueit-testfiles' + +SOCIAL_AUTH_TWITTER_KEY = '' +SOCIAL_AUTH_TWITTER_SECRET = '' +SOCIAL_AUTH_FACEBOOK_KEY = '' +SOCIAL_AUTH_FACEBOOK_SECRET = '' +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' + diff --git a/test/common.py.enc b/test/travis-host.py.enc similarity index 100% rename from test/common.py.enc rename to test/travis-host.py.enc From 4afe792a735a405c5559250bfcb76f145ba3a72b Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 7 Jun 2018 15:08:23 -0400 Subject: [PATCH 07/12] set TEST_INTEGRATION --- settings/travis.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/settings/travis.py b/settings/travis.py index 808fcbdf..1ae01146 100644 --- a/settings/travis.py +++ b/settings/travis.py @@ -60,4 +60,6 @@ SOCIAL_AUTH_FACEBOOK_KEY = '' SOCIAL_AUTH_FACEBOOK_SECRET = '' SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' +GOOGLE_BOOKS_API_KEY = '' +TEST_INTEGRATION = False From 8aae6808d114b9ea88ccc0ef2de6a09fc2743ce1 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 7 Jun 2018 16:28:12 -0400 Subject: [PATCH 08/12] thought I already did this --- settings/travis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/settings/travis.py b/settings/travis.py index 1ae01146..57d889a5 100644 --- a/settings/travis.py +++ b/settings/travis.py @@ -62,4 +62,5 @@ SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' GOOGLE_BOOKS_API_KEY = '' TEST_INTEGRATION = False +DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' From ca5e5bed0c21565abf2368198bb56c6a6e4cfb0d Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 8 Jun 2018 13:55:05 -0400 Subject: [PATCH 09/12] update boto --- requirements_versioned.pip | 7 ++++--- settings/common.py | 2 +- settings/travis.py | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/requirements_versioned.pip b/requirements_versioned.pip index 0d8673ce..bb459b10 100644 --- a/requirements_versioned.pip +++ b/requirements_versioned.pip @@ -9,8 +9,9 @@ PyYAML==3.11 amqp==1.4.9 anyjson==0.3.3 billiard==3.3.0.23 -awscli==1.10.26 -boto==2.42.0 +awscli==1.15.33 +boto==2.48.0 +boto3==1.7.33 celery==3.1.23 certifi==2018.4.16 chardet==3.0.4 @@ -34,7 +35,7 @@ git+git://github.com/eshellman/django-notification.git@a4620e893e2da220994e0189b django-registration==2.1.2 django-selectable==0.9.0 django-smtp-ssl==1.0 -django-storages==1.4.1 +django-storages==1.5.2 django-tastypie==0.13.3 #django-transmeta==0.7.3 git+git://github.com/resulto/django-transmeta.git@ad4d7278ba330dcf8c8446f8ae9b2c769ae8684e diff --git a/settings/common.py b/settings/common.py index c300cdfe..e9d2016b 100644 --- a/settings/common.py +++ b/settings/common.py @@ -488,7 +488,7 @@ except ImportError: LOCAL_TEST = True if AWS_SECRET_ACCESS_KEY: - DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' + DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' else: DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' diff --git a/settings/travis.py b/settings/travis.py index 57d889a5..477b4b41 100644 --- a/settings/travis.py +++ b/settings/travis.py @@ -62,5 +62,6 @@ SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' GOOGLE_BOOKS_API_KEY = '' TEST_INTEGRATION = False -DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' +LOCAL_TEST = True +DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' From ab3c1934d5708aa843495d0eb56ce32e2b141245 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 8 Jun 2018 13:56:07 -0400 Subject: [PATCH 10/12] fix pdf tester boto3 storage returns unicode not str someplace --- core/pdf.py | 8 ++++++-- core/tests.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/pdf.py b/core/pdf.py index 5f0baf19..0931e46b 100644 --- a/core/pdf.py +++ b/core/pdf.py @@ -1,6 +1,7 @@ """ Utilities that manipulate pdf files """ +import logging import requests from xhtml2pdf import pisa # import python module from PyPDF2 import PdfFileMerger,PdfFileReader @@ -9,6 +10,7 @@ from tempfile import NamedTemporaryFile from django.template.loader import render_to_string from regluit import settings +logger = logging.getLogger(__name__) # Utility function def ask_pdf(context={}): @@ -35,7 +37,7 @@ def pdf_append( file1, file2, file_out ): def test_pdf(pdf_file): temp = None try: - if isinstance(pdf_file , str): + if isinstance(pdf_file , (str, unicode)): if pdf_file.startswith('http:') or pdf_file.startswith('https:'): temp = NamedTemporaryFile(delete=False) test_file_content = requests.get(pdf_file).content @@ -53,7 +55,9 @@ def test_pdf(pdf_file): except: success = False return success - except: + except Exception: + pdf_file = unicode(pdf_file) + logger.exception('error testing a pdf: %s' % pdf_file[:100]) return False def test_test_pdf(self): diff --git a/core/tests.py b/core/tests.py index ddd6311c..8532df09 100755 --- a/core/tests.py +++ b/core/tests.py @@ -1119,7 +1119,8 @@ class EbookFileTests(TestCase): #test the ask-appender c.add_ask_to_ebfs() if settings.AWS_SECRET_ACCESS_KEY: - assert test_pdf(c.work.ebookfiles().filter(asking=True)[0].file.url) + askingpdfurl = c.work.ebookfiles().filter(asking=True)[0].file.url + assert test_pdf(askingpdfurl) else: assert test_pdf(c.work.ebookfiles().filter(asking=True)[0].file) From 8b385d05ede4c1377a107faf81574bfe4c715fc6 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 8 Jun 2018 15:01:22 -0400 Subject: [PATCH 11/12] fix Booxtreem LOCAL_TEST --- booxtream/__init__.py | 6 +++--- booxtream/tests.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/booxtream/__init__.py b/booxtream/__init__.py index 33b7f0cd..a87aeba8 100644 --- a/booxtream/__init__.py +++ b/booxtream/__init__.py @@ -64,9 +64,9 @@ class BooXtream(object): boox = Boox.objects.create( download_link_epub='https://github.com/eshellman/42_ebook/blob/master/download/42.epub?raw=true&extra=download.booxtream.com/', download_link_mobi='https://github.com/eshellman/42_ebook/blob/master/download/42.mobi?raw=true', - referenceid= kwargs.get('referenceid'), - downloads_remaining= kwargs.get('downloadlimit'), - expirydays=kwargs.get('expirydays'), + referenceid= kwargs.get('referenceid', '42'), + downloads_remaining= kwargs.get('downloadlimit', 10), + expirydays=kwargs.get('expirydays', 30), ) return boox diff --git a/booxtream/tests.py b/booxtream/tests.py index 359c9044..e3492546 100644 --- a/booxtream/tests.py +++ b/booxtream/tests.py @@ -23,13 +23,15 @@ class TestBooXtream(unittest.TestCase): return manager def test_booxtream_errors(self): + if settings.LOCAL_TEST: + return from .exceptions import BooXtreamError inst = self._makeOne() if not settings.BOOXTREAM_API_KEY: return with self.assertRaises(BooXtreamError) as cm: inst.platform() - self.assertIn( 'expirydays not set',str(cm.exception)) + self.assertIn('expirydays not set', str(cm.exception)) params={ 'customername': 'Jane Test', 'languagecode':'1043', From 455032ebc35b1064f41ab85802468130eed4be61 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 8 Jun 2018 15:17:39 -0400 Subject: [PATCH 12/12] delint --- booxtream/__init__.py | 30 +++++++++++++++--------------- booxtream/exceptions.py | 6 +++--- booxtream/models.py | 15 +++++++-------- booxtream/tests.py | 20 ++++++++++---------- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/booxtream/__init__.py b/booxtream/__init__.py index a87aeba8..4c3d9cca 100644 --- a/booxtream/__init__.py +++ b/booxtream/__init__.py @@ -1,10 +1,11 @@ -import requests import random -from django.conf import settings -from urllib import quote from functools import partial +from urllib import quote from xml.etree import ElementTree +import requests +from django.conf import settings + from django.apps import apps from . exceptions import BooXtreamError @@ -34,10 +35,10 @@ class BooXtream(object): if not apiuser: apiuser = settings.BOOXTREAM_API_USER self.endpoint = 'https://service.booxtream.com/' - self.postrequest = partial(requests.post, timeout=timeout, auth=(apiuser,apikey)) + self.postrequest = partial(requests.post, timeout=timeout, auth=(apiuser, apikey)) - def platform(self, epubfile=None, epub=True, kf8mobi=False, **kwargs): + def platform(self, epubfile=None, epub=True, kf8mobi=False, **kwargs): """ Make an API request to BooXtream ``self.apikey``, ``epubfile`` and the supplied ``kwargs``. Attempts to deserialize the XML response and return the download link. @@ -48,24 +49,24 @@ class BooXtream(object): Boox = apps.get_model('booxtream', 'Boox') url = self.endpoint + 'booxtream.xml' - kwargs['epub'] = '1' if epub else '0' + kwargs['epub'] = '1' if epub else '0' kwargs['kf8mobi'] = '1' if kf8mobi else '0' if epubfile: - if hasattr(epubfile,'name') and str(epubfile.name).endswith('.epub'): - files= {'epubfile': (str(epubfile.name),epubfile)} + if hasattr(epubfile, 'name') and str(epubfile.name).endswith('.epub'): + files = {'epubfile': (str(epubfile.name), epubfile)} else: # give it a random file name so that kindlegen doesn't choke # needed for in-memory (StringIO) epubs - files= {'epubfile': ('%012x.epub' % random.randrange(16**12),epubfile)} + files= {'epubfile': ('%012x.epub' % random.randrange(16**12), epubfile)} else: - files={} + files = {} if settings.LOCAL_TEST: # fake it, so you can test other functions without hitting booxtream boox = Boox.objects.create( download_link_epub='https://github.com/eshellman/42_ebook/blob/master/download/42.epub?raw=true&extra=download.booxtream.com/', download_link_mobi='https://github.com/eshellman/42_ebook/blob/master/download/42.mobi?raw=true', referenceid= kwargs.get('referenceid', '42'), - downloads_remaining= kwargs.get('downloadlimit', 10), + downloads_remaining=kwargs.get('downloadlimit', 10), expirydays=kwargs.get('expirydays', 30), ) return boox @@ -86,9 +87,8 @@ class BooXtream(object): boox = Boox.objects.create( download_link_epub=download_link_epub, download_link_mobi=download_link_mobi, - referenceid= kwargs.get('referenceid'), - downloads_remaining= kwargs.get('downloadlimit'), + referenceid=kwargs.get('referenceid'), + downloads_remaining=kwargs.get('downloadlimit'), expirydays=kwargs.get('expirydays'), ) - return boox - + return boox \ No newline at end of file diff --git a/booxtream/exceptions.py b/booxtream/exceptions.py index 202d1047..12fb6d1f 100644 --- a/booxtream/exceptions.py +++ b/booxtream/exceptions.py @@ -7,7 +7,7 @@ class BooXtreamError(Exception): self.errors = errors def __str__(self): - errormsg='BooXtream errors:' + errormsg = 'BooXtream errors:' for error in self.errors: - errormsg += 'Error %s: %s\n'% (error.find('Code').text,error.find('Msg').text) - return errormsg \ No newline at end of file + errormsg += 'Error %s: %s\n'% (error.find('Code').text, error.find('Msg').text) + return errormsg diff --git a/booxtream/models.py b/booxtream/models.py index 918e2bab..cbf2e606 100644 --- a/booxtream/models.py +++ b/booxtream/models.py @@ -6,22 +6,21 @@ class Boox(models.Model): """ keeps a record of a file that's been watermarked """ - download_link_epub = models.URLField(null=True) - download_link_mobi = models.URLField(null=True) + download_link_epub = models.URLField(null=True) + download_link_mobi = models.URLField(null=True) referenceid = models.CharField(max_length=32) - downloads_remaining = models.PositiveSmallIntegerField(default = 0) + downloads_remaining = models.PositiveSmallIntegerField(default=0) expirydays = models.PositiveSmallIntegerField() created = models.DateTimeField(auto_now_add=True) - + @property def expired(self): return self.created+timedelta(days=self.expirydays) < datetime.now() - + def download_link(self, format): if format == 'epub': return self.download_link_epub elif format == 'mobi': return self.download_link_mobi - else: - return None - + return None + diff --git a/booxtream/tests.py b/booxtream/tests.py index e3492546..c7cf266f 100644 --- a/booxtream/tests.py +++ b/booxtream/tests.py @@ -1,6 +1,6 @@ import unittest import time -import urllib2 +import urllib2 from tempfile import NamedTemporaryFile from StringIO import StringIO from django.conf import settings @@ -32,7 +32,7 @@ class TestBooXtream(unittest.TestCase): with self.assertRaises(BooXtreamError) as cm: inst.platform() self.assertIn('expirydays not set', str(cm.exception)) - params={ + params = { 'customername': 'Jane Test', 'languagecode':'1043', 'expirydays': 1, @@ -49,7 +49,7 @@ class TestBooXtream(unittest.TestCase): def test_booxtream_good(self): inst = self._makeOne() - params={ + params = { 'customeremailaddress':'jane@example.com', 'customername': 'Jane Test', 'languagecode':'1043', @@ -59,16 +59,16 @@ class TestBooXtream(unittest.TestCase): 'chapterfooter':1, 'disclaimer':1, } - params['referenceid']= 'order'+str(time.time()) - boox=inst.platform(epubfile=self.epub2file, **params) - self.assertRegexpMatches(boox.download_link_epub,'download.booxtream.com/') + params['referenceid'] = 'order' + str(time.time()) + boox = inst.platform(epubfile=self.epub2file, **params) + self.assertRegexpMatches(boox.download_link_epub, 'download.booxtream.com/') self.assertFalse(boox.expired) - self.assertEqual(boox.downloads_remaining,3) - + self.assertEqual(boox.downloads_remaining, 3) + # make sure it works with an in-memory file self.epub2file.seek(0) in_mem_epub = StringIO() in_mem_epub.write(self.epub2file.read()) in_mem_epub.seek(0) - boox2=inst.platform(epubfile=in_mem_epub, **params) - self.assertRegexpMatches(boox2.download_link_epub,'download.booxtream.com/') + boox2 = inst.platform(epubfile=in_mem_epub, **params) + self.assertRegexpMatches(boox2.download_link_epub, 'download.booxtream.com/')