From 4e161bebe625e7f52a1cd1dbaadc2e2a0f0ac97c Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Wed, 28 Aug 2013 17:13:35 -0700 Subject: [PATCH] explicit import of regluit.core.parameters move to using the openly available github hosted version of Eric's Open Access Ebooks for core.EbookFileTests.test_ebookfile test Should we delete the static/test epub? --- core/models.py | 11 ++++++++++- core/tests.py | 36 ++++++++++++++++++++++++++++++------ settings/common.py | 2 +- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/core/models.py b/core/models.py index a04d5894..360c3e81 100755 --- a/core/models.py +++ b/core/models.py @@ -47,7 +47,16 @@ from regluit.payment.parameters import ( TRANSACTION_STATUS_FAILED, TRANSACTION_STATUS_INCOMPLETE ) -from regluit.core.parameters import * + +from regluit.core.parameters import ( + REWARDS, + BUY2UNGLUE, + INDIVIDUAL, + LIBRARY, + BORROWED, + TESTING +) + from regluit.booxtream import BooXtream watermarker = BooXtream() diff --git a/core/tests.py b/core/tests.py index 9aaa2413..0adcf742 100755 --- a/core/tests.py +++ b/core/tests.py @@ -6,8 +6,11 @@ from decimal import Decimal as D from math import factorial from time import sleep, mktime from urlparse import parse_qs, urlparse +from tempfile import NamedTemporaryFile from celery.task import chord from celery.task.sets import TaskSet +import requests +import os """ django imports @@ -17,6 +20,7 @@ from django.contrib.auth.models import User from django.contrib.comments.models import Comment from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site +from django.core.files import File as DjangoFile from django.db import IntegrityError from django.http import Http404 from django.test import TestCase @@ -52,7 +56,8 @@ from regluit.core.models import ( EbookFile, Acq, ) -from regluit.core.parameters import * + +from regluit.core.parameters import TESTING from regluit.frontend.views import safe_get_work from regluit.payment.models import Transaction from regluit.payment.parameters import PAYMENT_TYPE_AUTHORIZATION @@ -818,14 +823,33 @@ class MailingListTests(TestCase): class EbookFileTests(TestCase): def test_ebookfile(self): + """ + Read the test epub file + """ w = Work.objects.create(title="Work 1") e = Edition.objects.create(title=w.title,work=w) u = User.objects.create_user('test', 'test@example.org', 'testpass') - test_file = open(settings.BOOXTREAM_TEST_EPUB) - from django.core.files import File as DjangoFile - dj_file = DjangoFile(test_file) - ebf = EbookFile( format='epub', edition=e, file=dj_file) - ebf.save() + + # download the test epub into a temp file + temp = NamedTemporaryFile(delete=False) + test_file_content = requests.get(settings.BOOXTREAM_TEST_EPUB_URL).content + + temp.write(test_file_content) + temp.close() + + try: + # now we can try putting the test epub file into Django storage + temp_file = open(temp.name) + + dj_file = DjangoFile(temp_file) + ebf = EbookFile( format='epub', edition=e, file=dj_file) + ebf.save() + + temp_file.close() + finally: + # make sure we get rid of temp file + os.remove(temp.name) + acq=Acq.objects.create(user=u,work=w,license=TESTING) url= acq.get_epub_url() diff --git a/settings/common.py b/settings/common.py index e1d6677d..3bbf4984 100644 --- a/settings/common.py +++ b/settings/common.py @@ -410,5 +410,5 @@ MARC_CHOICES = ( BOOXTREAM_API_KEY = '7ynRCsx4q21zEY67it7yk8u5rc6EXY' BOOXTREAM_API_USER = 'ungluetest' -BOOXTREAM_TEST_EPUB = STATIC_ROOT+'/test/134221.0.epub' +BOOXTREAM_TEST_EPUB_URL = 'https://github.com/Gluejar/open_access_ebooks_ebook/raw/master/download/open_access_ebooks.epub' FILE_UPLOAD_MAX_MEMORY_SIZE = 20971520 #20MB