Merge pull request #781 from Gluejar/add-travis

files for running tests with travis
pull/91/head
eshellman 2018-06-08 15:34:31 -04:00 committed by GitHub
commit 8d3cacb821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 150 additions and 52 deletions

3
.gitignore vendored
View File

@ -2,7 +2,8 @@
*.pyc
*.log
settings/me.*
settings/keys/*
settings/keys/c*
settings/keys/h*
*.dot
reports
ENV

23
.travis.yml Normal file
View File

@ -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/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/Gluejar/regluit/test/travis-host.py.enc -out ~/build/Gluejar/regluit/settings/keys/host.py -d
install:
- pip install -r requirements_versioned.pip
script: django-admin test

View File

@ -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,25 +49,25 @@ 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'),
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
@ -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

View File

@ -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
errormsg += 'Error %s: %s\n'% (error.find('Code').text, error.find('Msg').text)
return errormsg

View File

@ -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

View File

@ -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
@ -23,14 +23,16 @@ 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))
params={
self.assertIn('expirydays not set', str(cm.exception))
params = {
'customername': 'Jane Test',
'languagecode':'1043',
'expirydays': 1,
@ -47,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',
@ -57,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/')

View File

@ -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):

View File

@ -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)

View File

@ -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

View File

@ -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 *
@ -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'

View File

67
settings/travis.py Normal file
View File

@ -0,0 +1,67 @@
# 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'
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 = ''
GOOGLE_BOOKS_API_KEY = ''
TEST_INTEGRATION = False
LOCAL_TEST = True
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

BIN
test/travis-host.py.enc Normal file

Binary file not shown.