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?pull/1/head
parent
0ba5c9a00e
commit
4e161bebe6
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue