From 622f3ea10b6f8bb44c79a744c5ff8ab36c46e2ef Mon Sep 17 00:00:00 2001 From: Sebastien Corbin Date: Sat, 18 Apr 2020 18:53:42 +0200 Subject: [PATCH] Rework test matrix and structure --- .gitignore | 2 + .travis.yml | 76 +++++++++-------- jsignature/mixins.py | 3 +- jsignature/tests/__init__.py | 5 -- quicktest.py | 82 ------------------- runtests.py | 15 ++++ tests/__init__.py | 0 {jsignature/tests => tests}/models.py | 2 +- tests/settings.py | 34 ++++++++ .../tests/fields.py => tests/test_fields.py | 4 +- .../tests/forms.py => tests/test_forms.py | 4 +- .../tests/mixins.py => tests/test_mixins.py | 18 +--- .../tests/utils.py => tests/test_utils.py | 2 +- .../tests/widgets.py => tests/test_widgets.py | 6 +- tox.ini | 23 ++++++ 15 files changed, 127 insertions(+), 149 deletions(-) delete mode 100644 jsignature/tests/__init__.py delete mode 100644 quicktest.py create mode 100755 runtests.py create mode 100644 tests/__init__.py rename {jsignature/tests => tests}/models.py (70%) create mode 100644 tests/settings.py rename jsignature/tests/fields.py => tests/test_fields.py (94%) rename jsignature/tests/forms.py => tests/test_forms.py (89%) rename jsignature/tests/mixins.py => tests/test_mixins.py (75%) rename jsignature/tests/utils.py => tests/test_utils.py (95%) rename jsignature/tests/widgets.py => tests/test_widgets.py (95%) create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 0680a75..8c0f172 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.pyc .coverage htmlcov +*.egg-info +.tox diff --git a/.travis.yml b/.travis.yml index 6a0e139..4c6b6ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,42 +1,46 @@ language: python -python: - - 2.6 - - 2.7 - - 3.2 - - 3.3 - - 3.4 +matrix: + fast_finish: true + allow_failures: + - env: DJANGO=master + include: + - python: 2.7 + env: DJANGO=1.11 -env: - - DJANGO_VERSION=1.4 MODULE=jsignature - - DJANGO_VERSION=1.5 MODULE=jsignature - - DJANGO_VERSION=1.6 MODULE=jsignature.tests - - DJANGO_VERSION=1.7 MODULE=jsignature.tests + - python: 3.5 + env: DJANGO=1.11 + - python: 3.5 + env: DJANGO=2.2 + + - python: 3.6 + env: DJANGO=1.11 + - python: 3.6 + env: DJANGO=2.2 + - python: 3.6 + env: DJANGO=3.0 + - python: 3.6 + env: DJANGO=master + + - python: 3.7 + env: DJANGO=2.2 + - python: 3.7 + env: DJANGO=3.0 + - python: 3.7 + env: DJANGO=master + + + - python: 3.8 + env: DJANGO=2.2 + - python: 3.8 + env: DJANGO=3.0 + - python: 3.8 + env: DJANGO=master install: - - pip install -r requirements.txt --use-mirrors - - pip install -q Django==$DJANGO_VERSION --use-mirrors - - pip install coverage - -script: coverage run quicktest.py $MODULE - + - pip install tox tox-travis +script: + - tox after_success: - - pip install coveralls - - coveralls - -# We need to exclude old versions of Django for tests with python 3. -# We need to exclude old versions of Python for tests with Django >= 1.7. -matrix: - exclude: - - python: 3.2 - env: DJANGO_VERSION=1.4 MODULE=jsignature - - python: 3.3 - env: DJANGO_VERSION=1.4 MODULE=jsignature - - python: 3.4 - env: DJANGO_VERSION=1.4 MODULE=jsignature - - python: 3.4 - env: DJANGO_VERSION=1.5 MODULE=jsignature - - python: 3.4 - env: DJANGO_VERSION=1.6 MODULE=jsignature.tests - - python: 2.6 - env: DJANGO_VERSION=1.7 MODULE=jsignature.tests + - pip install coveralls + - coveralls diff --git a/jsignature/mixins.py b/jsignature/mixins.py index d8d9b4a..9eadaed 100644 --- a/jsignature/mixins.py +++ b/jsignature/mixins.py @@ -2,6 +2,7 @@ A django mixin providing fields to store a signature captured with jSignature jQuery plugin """ +import json from datetime import datetime from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -28,7 +29,7 @@ class JSignatureFieldsMixin(models.Model): original = not is_new and self.__class__.objects.get(pk=self.pk) if self.signature: - if is_new or self.signature != original.signature: + if is_new or json.dumps(self.signature) != original.signature: self.signature_date = datetime.now() else: self.signature_date = None diff --git a/jsignature/tests/__init__.py b/jsignature/tests/__init__.py deleted file mode 100644 index 29ac698..0000000 --- a/jsignature/tests/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .widgets import JSignatureWidgetTest -from .forms import JSignatureFormFieldTest -from .fields import JSignatureFieldTest -from .mixins import JSignatureFieldsMixinTest -from .utils import UtilsTest diff --git a/quicktest.py b/quicktest.py deleted file mode 100644 index 885e736..0000000 --- a/quicktest.py +++ /dev/null @@ -1,82 +0,0 @@ -import os -import sys -import argparse -from django.conf import settings - - -class QuickDjangoTest(object): - """ - A quick way to run the Django test suite without a fully-configured project. - - Example usage: - - >>> QuickDjangoTest('app1', 'app2') - - Based on a script published by Lukasz Dziedzia at: - http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app - """ - DIRNAME = os.path.dirname(__file__) - INSTALLED_APPS = ( - ) - - def __init__(self, *args, **kwargs): - self.apps = args - self.run_tests() - - def run_tests(self): - """ - Fire up the Django test suite developed for version 1.2 - """ - settings.configure( - TEMPLATE_DIRS = ('jsignature/templates/',), - ROOT_URLCONF = 'jsignature.tests', - DEBUG = True, - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(self.DIRNAME, 'database.db'), - 'USER': '', - 'PASSWORD': '', - 'HOST': '', - 'PORT': '', - } - }, - MIDDLEWARE_CLASSES = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - ), - INSTALLED_APPS = self.INSTALLED_APPS + self.apps - ) - # Setup is needed for Django >= 1.7 - import django - if hasattr(django, 'setup'): - django.setup() - try: - from django.test.runner import DiscoverRunner - failures = DiscoverRunner().run_tests(self.apps, verbosity=1) - except ImportError: - # DjangoTestSuiteRunner has been deprecated in Django 1.7 - from django.test.simple import DjangoTestSuiteRunner - failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1) - if failures: # pragma: no cover - sys.exit(failures) - -if __name__ == '__main__': - """ - What do when the user hits this file from the shell. - - Example usage: - - $ python quicktest.py app1 app2 - - """ - parser = argparse.ArgumentParser( - usage="[args]", - description="Run Django tests on the provided applications." - ) - parser.add_argument('apps', nargs='+', type=str) - args = parser.parse_args() - QuickDjangoTest(*args.apps) diff --git a/runtests.py b/runtests.py new file mode 100755 index 0000000..0c2ef30 --- /dev/null +++ b/runtests.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +import django +from django.conf import settings +from django.test.utils import get_runner + +if __name__ == "__main__": + os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' + django.setup() + TestRunner = get_runner(settings) + test_runner = TestRunner() + failures = test_runner.run_tests(["tests"]) + sys.exit(bool(failures)) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jsignature/tests/models.py b/tests/models.py similarity index 70% rename from jsignature/tests/models.py rename to tests/models.py index c7b631a..c0bc3a9 100644 --- a/jsignature/tests/models.py +++ b/tests/models.py @@ -1,5 +1,5 @@ """ Provides a dummy model implementing JSignatureFieldsMixin """ -from ..mixins import JSignatureFieldsMixin +from jsignature.mixins import JSignatureFieldsMixin class JSignatureTestModel(JSignatureFieldsMixin): diff --git a/tests/settings.py b/tests/settings.py new file mode 100644 index 0000000..2ed8828 --- /dev/null +++ b/tests/settings.py @@ -0,0 +1,34 @@ +import os + +DEBUG = True + +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + +SECRET_KEY = 'thisisntactuallysecretatall' + +ALLOWED_HOSTS = ['*'] + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } +} + +# ROOT_URLCONF = 'tests.urls' + +INSTALLED_APPS = [ + 'jsignature', + 'tests', +] + +PASSWORD_HASHERS = { + 'django.contrib.auth.hashers.MD5PasswordHasher', +} + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + }, +] diff --git a/jsignature/tests/fields.py b/tests/test_fields.py similarity index 94% rename from jsignature/tests/fields.py rename to tests/test_fields.py index 5e520aa..5a432cc 100644 --- a/jsignature/tests/fields.py +++ b/tests/test_fields.py @@ -4,8 +4,8 @@ import six from django.test import SimpleTestCase from django.core.exceptions import ValidationError -from ..fields import JSignatureField -from ..forms import JSignatureField as JSignatureFormField +from jsignature.fields import JSignatureField +from jsignature.forms import JSignatureField as JSignatureFormField class JSignatureFieldTest(SimpleTestCase): diff --git a/jsignature/tests/forms.py b/tests/test_forms.py similarity index 89% rename from jsignature/tests/forms.py rename to tests/test_forms.py index 2325590..56c9b26 100644 --- a/jsignature/tests/forms.py +++ b/tests/test_forms.py @@ -1,8 +1,8 @@ from django.test import SimpleTestCase from django.core.exceptions import ValidationError -from ..widgets import JSignatureWidget -from ..forms import JSignatureField +from jsignature.widgets import JSignatureWidget +from jsignature.forms import JSignatureField class JSignatureFormFieldTest(SimpleTestCase): diff --git a/jsignature/tests/mixins.py b/tests/test_mixins.py similarity index 75% rename from jsignature/tests/mixins.py rename to tests/test_mixins.py index 838355b..9da013e 100644 --- a/jsignature/tests/mixins.py +++ b/tests/test_mixins.py @@ -1,24 +1,10 @@ from datetime import date -from django.conf import settings -from django.db.models import loading -from django.test import SimpleTestCase -from django.core.management import call_command +from django.test import TestCase from .models import JSignatureTestModel -class JSignatureFieldsMixinTest(SimpleTestCase): - - def setUp(self): - self.old_installed_apps = settings.INSTALLED_APPS - settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) - settings.INSTALLED_APPS.append('jsignature.tests') - loading.cache.loaded = False - call_command('syncdb', verbosity=0) - - def tearDown(self): - settings.INSTALLED_APPS = self.old_installed_apps - +class JSignatureFieldsMixinTest(TestCase): def test_save_create(self): # If an object is created signed, signature date must be set signature_value = [{"x": [1, 2], "y": [3, 4]}] diff --git a/jsignature/tests/utils.py b/tests/test_utils.py similarity index 95% rename from jsignature/tests/utils.py rename to tests/test_utils.py index cc38d96..83741f4 100644 --- a/jsignature/tests/utils.py +++ b/tests/test_utils.py @@ -4,7 +4,7 @@ import imghdr from PIL import Image from django.test import SimpleTestCase -from ..utils import draw_signature +from jsignature.utils import draw_signature DUMMY_VALUE = [{"x": [205, 210], "y": [59, 63]}, {"x": [205, 207], "y": [67, 64]}] diff --git a/jsignature/tests/widgets.py b/tests/test_widgets.py similarity index 95% rename from jsignature/tests/widgets.py rename to tests/test_widgets.py index 5d4be07..42cabe1 100644 --- a/jsignature/tests/widgets.py +++ b/tests/test_widgets.py @@ -5,8 +5,8 @@ import six from django.test import SimpleTestCase from django.core.exceptions import ValidationError -from ..widgets import JSignatureWidget -from ..settings import JSIGNATURE_HEIGHT +from jsignature.widgets import JSignatureWidget +from jsignature.settings import JSIGNATURE_HEIGHT class JSignatureWidgetTest(SimpleTestCase): @@ -15,7 +15,7 @@ class JSignatureWidgetTest(SimpleTestCase): widget = JSignatureWidget() media = widget.media media_js = list(media.render_js()) - self.assertEqual(2, len(media_js)) + self.assertEqual(3, len(media_js)) media_js_str = "".join(media_js) self.assertIn('jSignature.min.js', media_js_str) self.assertIn('django_jsignature.js', media_js_str) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..6b450bb --- /dev/null +++ b/tox.ini @@ -0,0 +1,23 @@ +[tox] +envlist = + {py27,py35,py36}-django111, + {py35,py36,py37,py38}-django22, + {py36,py37,py38}-django{30,master} + +[testenv] +deps= + django111: Django>=1.11,<2.0 + django22: Django>=2.2,<3.0 + django30: Django>=3.0,<4.0 + djangomaster: https://github.com/django/django/archive/master.tar.gz + -r requirements.txt + coverage + +commands= coverage run ./runtests.py + +[travis:env] +DJANGO = + 1.11: django111 + 2.2: django22 + 3.0: django30 + master: djangomaster