From 7d62a3b72f03b8242b67749725260af0254a4511 Mon Sep 17 00:00:00 2001 From: Diederik van der Boor Date: Tue, 9 May 2017 15:03:03 +0200 Subject: [PATCH] Add testing framework, no tests written yet --- .coveragerc | 2 + .travis.yml | 31 ++++++++++++ private_storage/tests/__init__.py | 0 private_storage/tests/test_imports.py | 12 +++++ runtests.py | 71 +++++++++++++++++++++++++++ tox.ini | 28 +++++++++++ 6 files changed, 144 insertions(+) create mode 100644 .coveragerc create mode 100644 .travis.yml create mode 100644 private_storage/tests/__init__.py create mode 100644 private_storage/tests/test_imports.py create mode 100755 runtests.py create mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..793b167 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,2 @@ +[run] +source = private_storage diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1a2cc3d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +sudo: false +language: python +python: +- '2.7' +- '3.6' +env: +- DJANGO="django>=1.8.0,<1.9.0" +- DJANGO="django>=1.9.0,<1.10.0" +- DJANGO="django>=1.10.0,<1.11.0" +- DJANGO="django>=1.11.0,<1.12.0" +before_install: +- pip install codecov +install: +- travis_retry pip install $DJANGO django-storages boto3 -e . +script: +- coverage run --rcfile=.coveragerc runtests.py +after_success: +- codecov +branches: + only: + - master +notifications: + email: + recipients: + - travis@edoburu.nl + on_success: never + on_failure: always + slack: + secure: WWNa4MHf50AOybB+XW9UKXCk/9Q8r++Jc4xTdEib43rj4odH9wxIaTRrzAbbpo3EO2gYuLgq6mMbaIZPD5l2UmgSnyuIbeYAAKIQblT+8XMamtXwnSS5j9vfBXYdj54rTlh+jKwEMW/JiQKl+SQpfQ2v1NMvYO63m89Ev9vXvcU= + on_success: never + on_failure: always diff --git a/private_storage/tests/__init__.py b/private_storage/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/private_storage/tests/test_imports.py b/private_storage/tests/test_imports.py new file mode 100644 index 0000000..0d9eeb6 --- /dev/null +++ b/private_storage/tests/test_imports.py @@ -0,0 +1,12 @@ +# Most pathetic test case ever, only see if all files are importable. +# TODO: write real tests. +import private_storage +import private_storage.storage.files +import private_storage.storage.s3boto3 +import private_storage.appconfig +import private_storage.fields +import private_storage.models +import private_storage.permissions +import private_storage.servers +import private_storage.urls +import private_storage.views diff --git a/runtests.py b/runtests.py new file mode 100755 index 0000000..e8d50eb --- /dev/null +++ b/runtests.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +import sys +import django +from django.conf import settings, global_settings as default_settings +from django.core.management import execute_from_command_line +from os import path + +if not settings.configured: + module_root = path.dirname(path.realpath(__file__)) + + sys.path.insert(0, path.join(module_root, 'example')) + + if django.VERSION >= (1, 8): + template_settings = dict( + TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': (), + 'DEBUG': True, + 'OPTIONS': { + 'loaders': ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + ), + 'context_processors': ( + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'django.template.context_processors.request', + 'django.template.context_processors.static', + 'django.contrib.auth.context_processors.auth', + ), + }, + }, + ] + ) + else: + template_settings = dict( + TEMPLATE_LOADERS = ( + 'django.template.loaders.app_directories.Loader', + 'django.template.loaders.filesystem.Loader', + ), + TEMPLATE_CONTEXT_PROCESSORS = list(default_settings.TEMPLATE_CONTEXT_PROCESSORS) + [ + 'django.core.context_processors.request', + ], + TEMPLATE_DEBUG = True, + ) + + settings.configure( + DEBUG = False, # will be False anyway by DjangoTestRunner. + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } + }, + INSTALLED_APPS = ( + 'private_storage', + ), + TEST_RUNNER = 'django.test.runner.DiscoverRunner', + AWS_PRIVATE_STORAGE_BUCKET_NAME='foobar', + **template_settings + ) + + +def runtests(): + argv = sys.argv[:1] + ['test', 'private_storage'] + sys.argv[1:] + execute_from_command_line(argv) + +if __name__ == '__main__': + runtests() diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..1dac4a7 --- /dev/null +++ b/tox.ini @@ -0,0 +1,28 @@ +[tox] +envlist= + py27-django{18,19,110,111}, + py36-django{18,19,110,111}, + # py36-django-dev, + coverage, + +[testenv] +deps = + django-storages + boto3 + django18: Django >= 1.8,<1.9 + django19: Django >= 1.9,<1.10 + django110: Django >= 1.10,<1.11 + django111: Django >= 1.11,<1.12 + django-dev: https://github.com/django/django/tarball/master +commands= + python runtests.py + +[testenv:coverage] +basepython=python3.6 +deps= + django==1.11 + coverage +commands= + coverage erase + coverage run --rcfile=.coveragerc runtests.py + coverage report