Skip to content

Commit

Permalink
Add travis builds for optional dependencies
Browse files Browse the repository at this point in the history
- Django
- SQLAlchemy
- Google AppEngine
  • Loading branch information
njoyce committed Jan 23, 2015
1 parent b3b5571 commit 547b311
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 66 deletions.
38 changes: 31 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,42 @@ python:
- "2.6"
- "2.7"

env:
global:
- PYTHONPATH=/tmp/gaesdk

matrix:
- USE_EXTENSIONS=true # no dependencies
- USE_EXTENSIONS=false
- USE_EXTENSIONS=true DJANGO_VERSION=1.2.7
- USE_EXTENSIONS=false DJANGO_VERSION=1.2.7
- USE_EXTENSIONS=true DJANGO_VERSION=1.3.7
- USE_EXTENSIONS=false DJANGO_VERSION=1.3.7
- USE_EXTENSIONS=true DJANGO_VERSION=1.5.12
- USE_EXTENSIONS=false DJANGO_VERSION=1.5.12
- USE_EXTENSIONS=true SQLALCHEMY_VERSION=0.7.10
- USE_EXTENSIONS=false SQLALCHEMY_VERSION=0.7.10
- USE_EXTENSIONS=true SQLALCHEMY_VERSION=0.8.7
- USE_EXTENSIONS=false SQLALCHEMY_VERSION=0.8.7
- USE_EXTENSIONS=true SQLALCHEMY_VERSION=0.9.8
- USE_EXTENSIONS=false SQLALCHEMY_VERSION=0.9.8
- USE_EXTENSIONS=true TWISTED_VERSION=14.0.2
- USE_EXTENSIONS=false TWISTED_VERSION=14.0.2
- USE_EXTENSIONS=true GAESDK_VERSION=1.9.17
- USE_EXTENSIONS=false GAESDK_VERSION=1.9.17

before_install:
- pip install flake8
- flake8

install:
- pip install flake8 coverage coveralls
- pip install -e .

before_script:
- flake8
- ./install_optional_dependencies.sh
- ./maybe_install_cython.sh

script:
- coverage run -p --source=pyamf setup.py test
- pip install Cython
- coverage run -p --source=pyamf setup.py test
- coverage combine
- coverage run --source=pyamf setup.py test

after_success:
- coveralls
43 changes: 43 additions & 0 deletions install_optional_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash -e

# used by Travis to install optional dependencies
# see .travis.yml:env for envrionment variables

function install_django {
if [ -z "${DJANGO_VERSION}" ]; then
return 0
fi

pip install Django==${DJANGO_VERSION}
}

function install_sqlalchemy {
if [ -z "${SQLALCHEMY_VERSION}" ]; then
return 0
fi

pip install SQLAlchemy==${SQLALCHEMY_VERSION}
}

function install_twisted {
if [ -z "${TWISTED_VERSION}" ]; then
return 0
fi

pip install Twisted==${TWISTED_VERSION}
}

function install_gae_sdk {
if [ -z "${GAESDK_VERSION}" ]; then
return 0
fi

wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_${GAESDK_VERSION}.zip -nv
mkdir -p /tmp/gaesdk
unzip -q google_appengine_${GAESDK_VERSION}.zip -d /tmp/gaesdk
}

install_django
install_sqlalchemy
install_twisted
install_gae_sdk
9 changes: 9 additions & 0 deletions maybe_install_cython.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e

# used by travis to determine whether to install Cython (and thereby compile
# the PyAMF extensions)


if [ "${USE_EXTENSIONS}" == "true" ]; then
pip install Cython
fi
8 changes: 6 additions & 2 deletions pyamf/adapters/_django_utils_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@


def convert_lazy(l, encoder=None):
if l.__class__._delegate_unicode:
return unicode(l)
try:
if l.__class__._delegate_text:
return unicode(l)
except AttributeError:
if l.__class__._delegate_unicode:
return unicode(l)

if l.__class__._delegate_str:
return str(l)
Expand Down
14 changes: 6 additions & 8 deletions pyamf/remoting/gateway/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,15 @@ def __call__(self, http_request):
stream = None
timezone_offset = self._get_timezone_offset()

try:
body = http_request.body
except AttributeError:
body = http_request.raw_post_data

# Decode the request
try:
request = remoting.decode(
http_request.raw_post_data,
strict=self.strict,
logger=self.logger,
timezone_offset=timezone_offset
)
except AttributeError: # fix to make work with Django 1.6
request = remoting.decode(
http_request.body,
body,
strict=self.strict,
logger=self.logger,
timezone_offset=timezone_offset
Expand Down
2 changes: 1 addition & 1 deletion pyamf/remoting/gateway/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get(self):
)

def post(self):
body = self.request.body_file.read()
body = self.request.body
stream = None
timezone_offset = self._get_timezone_offset()

Expand Down
12 changes: 12 additions & 0 deletions pyamf/tests/adapters/django_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@

# The simplest Django settings possible

# support for Django < 1.5
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = ':memory:'

# support for Django >= 1.5
SECRET_KEY = 'unittest'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.' + DATABASE_ENGINE,
'NAME': DATABASE_NAME,
}
}


INSTALLED_APPS = ('adapters',)
10 changes: 4 additions & 6 deletions pyamf/tests/adapters/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
if django and django.VERSION < (1, 0):
django = None

try:
reload(settings)
except NameError:
from pyamf.tests.adapters.django_app import settings


settings = None
context = None

#: django modules/functions used once bootstrapped
Expand All @@ -50,12 +46,14 @@ def init_django():
"""
Bootstrap Django and initialise this module
"""
global django, management, create_test_db, destroy_test_db
global django, management, create_test_db, destroy_test_db, settings
global setup_test_environment, teardown_test_environment

if not django:
return

from pyamf.tests.adapters.django_app import settings

from django.core import management

project_dir = management.setup_environ(settings)
Expand Down
29 changes: 19 additions & 10 deletions pyamf/tests/adapters/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
@since: 0.3.1
"""

import unittest
import datetime
import struct
import os

import pyamf
from pyamf import amf3
from pyamf.tests import util


try:
from google.appengine.ext import db
import dev_appserver

dev_appserver.fix_sys_path()
except ImportError:
db = None
dev_appserver = None


db = None
blobstore = None
polymodel = None
adapter_db = None
adapter_blobstore = None
testbed = None

test_models = None

Expand All @@ -36,17 +39,17 @@ def setUpModule():
"""
"""
global db, blobstore, polymodel, adapter_blobstore, adapter_db, test_models
global dev_appserver, testbed

if db is None:
if dev_appserver is None:
return

if not os.environ.get('SERVER_SOFTWARE', None):
# this is an extra check because the AppEngine SDK may be in PYTHONPATH
raise unittest.SkipTest('Appengine env not bootstrapped correctly')

# all looks good - we now initialise the imports we require

from google.appengine.ext import db # noqa
from google.appengine.ext import blobstore # noqa
from google.appengine.ext.db import polymodel # noqa
from google.appengine.ext import testbed # noqa

from pyamf.adapters import _google_appengine_ext_db as adapter_db # noqa
from pyamf.adapters import ( # noqa
Expand All @@ -61,10 +64,16 @@ class BaseTestCase(util.ClassCacheClearingTestCase):
"""

def setUp(self):
if db is None:
if dev_appserver is None:
self.skipTest('google appengine sdk not found')

util.ClassCacheClearingTestCase.setUp(self)
self.testbed = testbed.Testbed()

self.testbed.activate()
# Next, declare which service stubs you want to use.
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()

def put(self, entity):
entity.put()
Expand Down
Loading

0 comments on commit 547b311

Please sign in to comment.