From ce105247dd3743ed321a023b6fa08d89c59f67ef Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Sun, 15 Feb 2015 15:20:52 +0100 Subject: [PATCH 01/17] Move tests folder to root directory Collecting 59 tests in every environment. --- conftest.py | 92 +++++++++++++++++++ django_extensions/tests/__init__.py | 26 ------ tests/__init__.py | 26 ++++++ .../tests => tests}/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../commands/error_raising_command.py | 0 .../tests => tests}/test_clean_pyc.py | 0 .../tests => tests}/test_compile_pyc.py | 0 .../tests => tests}/test_dumpscript.py | 4 +- .../test_encrypted_fields.py | 4 +- .../tests/fields.py => tests/test_fields.py | 14 +-- .../json_field.py => tests/test_json_field.py | 4 +- .../test_management_command.py | 0 .../tests => tests}/test_models.py | 2 +- .../test_shortuuid_field.py | 2 +- .../tests => tests}/test_templatetags.py | 0 .../tests/utils.py => tests/test_utils.py | 0 .../uuid_field.py => tests/test_uuid_field.py | 4 +- .../tests => tests}/testapp/__init__.py | 0 .../tests => tests}/testapp/models.py | 0 .../tests => tests}/testapp/urls.py | 0 tox.ini | 5 +- 22 files changed, 138 insertions(+), 45 deletions(-) create mode 100644 conftest.py delete mode 100644 django_extensions/tests/__init__.py create mode 100644 tests/__init__.py rename {django_extensions/tests => tests}/management/__init__.py (100%) rename {django_extensions/tests => tests}/management/commands/__init__.py (100%) rename {django_extensions/tests => tests}/management/commands/error_raising_command.py (100%) rename {django_extensions/tests => tests}/test_clean_pyc.py (100%) rename {django_extensions/tests => tests}/test_compile_pyc.py (100%) rename {django_extensions/tests => tests}/test_dumpscript.py (95%) rename django_extensions/tests/encrypted_fields.py => tests/test_encrypted_fields.py (98%) rename django_extensions/tests/fields.py => tests/test_fields.py (93%) rename django_extensions/tests/json_field.py => tests/test_json_field.py (79%) rename django_extensions/tests/management_command.py => tests/test_management_command.py (100%) rename {django_extensions/tests => tests}/test_models.py (96%) rename django_extensions/tests/shortuuid_field.py => tests/test_shortuuid_field.py (90%) rename {django_extensions/tests => tests}/test_templatetags.py (100%) rename django_extensions/tests/utils.py => tests/test_utils.py (100%) rename django_extensions/tests/uuid_field.py => tests/test_uuid_field.py (91%) rename {django_extensions/tests => tests}/testapp/__init__.py (100%) rename {django_extensions/tests => tests}/testapp/models.py (100%) rename {django_extensions/tests => tests}/testapp/urls.py (100%) diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..1907d71c8 --- /dev/null +++ b/conftest.py @@ -0,0 +1,92 @@ +from django.conf import settings + + +def pytest_configure(): + import sys + import tempfile + + try: + import django # NOQA + except ImportError: + print("Error: missing test dependency:") + print(" django library is needed to run test suite") + print(" you can install it with 'pip install django'") + print(" or use tox to automatically handle test dependencies") + sys.exit(1) + + try: + import shortuuid # NOQA + except ImportError: + print("Error: missing test dependency:") + print(" shortuuid library is needed to run test suite") + print(" you can install it with 'pip install shortuuid'") + print(" or use tox to automatically handle test dependencies") + sys.exit(1) + + try: + import dateutil # NOQA + except ImportError: + print("Error: missing test dependency:") + print(" dateutil library is needed to run test suite") + print(" you can install it with 'pip install python-dateutil'") + print(" or use tox to automatically handle test dependencies") + sys.exit(1) + + try: + import six # NOQA + except ImportError: + print("Error: missing test dependency:") + print(" six library is needed to run test suite") + print(" you can install it with 'pip install six'") + print(" or use tox to automatically handle test dependencies") + sys.exit(1) + + # Dynamically configure the Django settings with the minimum necessary to + # get Django running tests. + KEY_LOCS = {} + try: + # If KeyCzar is available, set up the environment. + from keyczar import keyczart, keyinfo + + # Create an RSA private key. + keys_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_rsa_dir") + keyczart.Create(keys_dir, "test", keyinfo.DECRYPT_AND_ENCRYPT, asymmetric=True) + keyczart.AddKey(keys_dir, "PRIMARY", size=4096) + KEY_LOCS['DECRYPT_AND_ENCRYPT'] = keys_dir + + # Create an RSA public key. + pub_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_pub_dir") + keyczart.PubKey(keys_dir, pub_dir) + KEY_LOCS['ENCRYPT'] = pub_dir + except ImportError: + pass + + settings.configure( + INSTALLED_APPS=[ + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.admin', + 'django.contrib.sessions', + 'tests.testapp', + 'django_extensions', + ], + MIDDLEWARE_CLASSES=( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + ), + # Django replaces this, but it still wants it. *shrugs* + DATABASE_ENGINE='django.db.backends.sqlite3', + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } + }, + MEDIA_ROOT='/tmp/django_extensions_test_media/', + MEDIA_PATH='/media/', + ROOT_URLCONF='tests.urls', + DEBUG=True, + TEMPLATE_DEBUG=True, + ENCRYPTED_FIELD_KEYS_DIR=KEY_LOCS, + ) diff --git a/django_extensions/tests/__init__.py b/django_extensions/tests/__init__.py deleted file mode 100644 index c1bdd479a..000000000 --- a/django_extensions/tests/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -from django.db import models # NOQA -from django_extensions.tests.test_dumpscript import DumpScriptTests -from django_extensions.tests.utils import TruncateLetterTests -from django_extensions.tests.json_field import JsonFieldTest -from django_extensions.tests.uuid_field import (UUIDFieldTest, - PostgreSQLUUIDFieldTest) -from django_extensions.tests.shortuuid_field import ShortUUIDFieldTest -from django_extensions.tests.fields import AutoSlugFieldTest -from django_extensions.tests.management_command import CommandTest, \ - ShowTemplateTagsTests, UpdatePermissionsTests, CommandSignalTests -from django_extensions.tests.test_templatetags import TemplateTagsTests -from django_extensions.tests.test_clean_pyc import CleanPycTests -from django_extensions.tests.test_compile_pyc import CompilePycTests - -__test_classes__ = [ - DumpScriptTests, JsonFieldTest, UUIDFieldTest, AutoSlugFieldTest, - CommandTest, ShowTemplateTagsTests, TruncateLetterTests, TemplateTagsTests, - ShortUUIDFieldTest, PostgreSQLUUIDFieldTest, CleanPycTests, CompilePycTests, - UpdatePermissionsTests, CommandSignalTests -] - -try: - from django_extensions.tests.encrypted_fields import EncryptedFieldsTestCase - __test_classes__.append(EncryptedFieldsTestCase) -except ImportError: - pass diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..a5184d93f --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,26 @@ +from django.db import models # NOQA +from .test_dumpscript import DumpScriptTests +from .test_utils import TruncateLetterTests +from .test_json_field import JsonFieldTest +from .test_uuid_field import (UUIDFieldTest, + PostgreSQLUUIDFieldTest) +from .test_shortuuid_field import ShortUUIDFieldTest +from .test_fields import AutoSlugFieldTest +from .test_management_command import CommandTest, \ + ShowTemplateTagsTests, UpdatePermissionsTests, CommandSignalTests +from .test_templatetags import TemplateTagsTests +from .test_clean_pyc import CleanPycTests +from .test_compile_pyc import CompilePycTests + +__test_classes__ = [ + DumpScriptTests, JsonFieldTest, UUIDFieldTest, AutoSlugFieldTest, + CommandTest, ShowTemplateTagsTests, TruncateLetterTests, TemplateTagsTests, + ShortUUIDFieldTest, PostgreSQLUUIDFieldTest, CleanPycTests, CompilePycTests, + UpdatePermissionsTests, CommandSignalTests +] + +try: + from .encrypted_fields import EncryptedFieldsTestCase + __test_classes__.append(EncryptedFieldsTestCase) +except ImportError: + pass diff --git a/django_extensions/tests/management/__init__.py b/tests/management/__init__.py similarity index 100% rename from django_extensions/tests/management/__init__.py rename to tests/management/__init__.py diff --git a/django_extensions/tests/management/commands/__init__.py b/tests/management/commands/__init__.py similarity index 100% rename from django_extensions/tests/management/commands/__init__.py rename to tests/management/commands/__init__.py diff --git a/django_extensions/tests/management/commands/error_raising_command.py b/tests/management/commands/error_raising_command.py similarity index 100% rename from django_extensions/tests/management/commands/error_raising_command.py rename to tests/management/commands/error_raising_command.py diff --git a/django_extensions/tests/test_clean_pyc.py b/tests/test_clean_pyc.py similarity index 100% rename from django_extensions/tests/test_clean_pyc.py rename to tests/test_clean_pyc.py diff --git a/django_extensions/tests/test_compile_pyc.py b/tests/test_compile_pyc.py similarity index 100% rename from django_extensions/tests/test_compile_pyc.py rename to tests/test_compile_pyc.py diff --git a/django_extensions/tests/test_dumpscript.py b/tests/test_dumpscript.py similarity index 95% rename from django_extensions/tests/test_dumpscript.py rename to tests/test_dumpscript.py index 4da5291e5..bc02757b1 100644 --- a/django_extensions/tests/test_dumpscript.py +++ b/tests/test_dumpscript.py @@ -3,8 +3,8 @@ from django.core.management import call_command -from django_extensions.tests.testapp.models import Name, Note, Person -from django_extensions.tests.fields import FieldTestCase +from .testapp.models import Name, Note, Person +from .test_fields import FieldTestCase if sys.version_info[:2] >= (2, 6): import ast as compiler # NOQA diff --git a/django_extensions/tests/encrypted_fields.py b/tests/test_encrypted_fields.py similarity index 98% rename from django_extensions/tests/encrypted_fields.py rename to tests/test_encrypted_fields.py index d9c187ffe..51c430bf9 100644 --- a/django_extensions/tests/encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -5,8 +5,8 @@ from django.db import connection, models from django.db.models import loading -from django_extensions.tests.models import Secret -from django_extensions.tests.fields import FieldTestCase +from .testapp.models import Secret +from .test_fields import FieldTestCase # Only perform encrypted fields tests if keyczar is present. Resolves # http://github.com/django-extensions/django-extensions/issues/#issue/17 diff --git a/django_extensions/tests/fields.py b/tests/test_fields.py similarity index 93% rename from django_extensions/tests/fields.py rename to tests/test_fields.py index 16e683f2b..e39424736 100644 --- a/django_extensions/tests/fields.py +++ b/tests/test_fields.py @@ -1,12 +1,14 @@ +import pytest + import django from django.conf import settings from django.core.management import call_command from django.db.models import loading from django.db import models -from django.utils import unittest +from django.test import TestCase from django_extensions.db.fields import AutoSlugField -from django_extensions.tests.testapp.models import SluggedTestModel, ChildSluggedTestModel +from .testapp.models import SluggedTestModel, ChildSluggedTestModel if django.VERSION[:2] >= (1, 7): from django.db import migrations # NOQA @@ -15,7 +17,7 @@ import django_extensions # NOQA -class FieldTestCase(unittest.TestCase): +class FieldTestCase(TestCase): def setUp(self): self.old_installed_apps = settings.INSTALLED_APPS #settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) @@ -129,9 +131,9 @@ def testInheritanceCreatesNextSlug(self): o = SluggedTestModel(title='foo') o.save() self.assertEqual(o.slug, 'foo-3') - - @unittest.skipIf(django.VERSION[0] <= 1 and django.VERSION[1] <= 6, - "Migrations are handled by south in Django <1.7") + + @pytest.mark.skipif(django.VERSION < (1, 7), + reason="Migrations are handled by south in Django <1.7") def test_17_migration(self): """ Tests making migrations with Django 1.7+'s migration framework diff --git a/django_extensions/tests/json_field.py b/tests/test_json_field.py similarity index 79% rename from django_extensions/tests/json_field.py rename to tests/test_json_field.py index ace83bdba..a62627dd5 100644 --- a/django_extensions/tests/json_field.py +++ b/tests/test_json_field.py @@ -1,5 +1,5 @@ -from django_extensions.tests.fields import FieldTestCase -from django_extensions.tests.testapp.models import JSONFieldTestModel +from .test_fields import FieldTestCase +from .testapp.models import JSONFieldTestModel class JsonFieldTest(FieldTestCase): diff --git a/django_extensions/tests/management_command.py b/tests/test_management_command.py similarity index 100% rename from django_extensions/tests/management_command.py rename to tests/test_management_command.py diff --git a/django_extensions/tests/test_models.py b/tests/test_models.py similarity index 96% rename from django_extensions/tests/test_models.py rename to tests/test_models.py index 3d4f68d48..044a5a1fc 100644 --- a/django_extensions/tests/test_models.py +++ b/tests/test_models.py @@ -1,7 +1,7 @@ from django.test import TestCase from django_extensions.db.models import ActivatorModel -from django_extensions.tests.testapp.models import Post +from .testapp.models import Post class ActivatorModelTestCase(TestCase): diff --git a/django_extensions/tests/shortuuid_field.py b/tests/test_shortuuid_field.py similarity index 90% rename from django_extensions/tests/shortuuid_field.py rename to tests/test_shortuuid_field.py index d3ec136fd..8f883421e 100644 --- a/django_extensions/tests/shortuuid_field.py +++ b/tests/test_shortuuid_field.py @@ -4,7 +4,7 @@ from django.db.models import loading from django.utils import unittest -from django_extensions.tests.testapp.models import ShortUUIDTestModel_field, ShortUUIDTestModel_pk, ShortUUIDTestAgregateModel, ShortUUIDTestManyToManyModel +from .testapp.models import ShortUUIDTestModel_field, ShortUUIDTestModel_pk, ShortUUIDTestAgregateModel, ShortUUIDTestManyToManyModel class ShortUUIDFieldTest(unittest.TestCase): diff --git a/django_extensions/tests/test_templatetags.py b/tests/test_templatetags.py similarity index 100% rename from django_extensions/tests/test_templatetags.py rename to tests/test_templatetags.py diff --git a/django_extensions/tests/utils.py b/tests/test_utils.py similarity index 100% rename from django_extensions/tests/utils.py rename to tests/test_utils.py diff --git a/django_extensions/tests/uuid_field.py b/tests/test_uuid_field.py similarity index 91% rename from django_extensions/tests/uuid_field.py rename to tests/test_uuid_field.py index 761c4069c..f52889454 100644 --- a/django_extensions/tests/uuid_field.py +++ b/tests/test_uuid_field.py @@ -4,8 +4,8 @@ import six from django_extensions.db.fields import PostgreSQLUUIDField -from django_extensions.tests.fields import FieldTestCase -from django_extensions.tests.testapp.models import UUIDTestModel_field, UUIDTestModel_pk, UUIDTestAgregateModel, UUIDTestManyToManyModel +from .test_fields import FieldTestCase +from .testapp.models import UUIDTestModel_field, UUIDTestModel_pk, UUIDTestAgregateModel, UUIDTestManyToManyModel class UUIDFieldTest(FieldTestCase): diff --git a/django_extensions/tests/testapp/__init__.py b/tests/testapp/__init__.py similarity index 100% rename from django_extensions/tests/testapp/__init__.py rename to tests/testapp/__init__.py diff --git a/django_extensions/tests/testapp/models.py b/tests/testapp/models.py similarity index 100% rename from django_extensions/tests/testapp/models.py rename to tests/testapp/models.py diff --git a/django_extensions/tests/testapp/urls.py b/tests/testapp/urls.py similarity index 100% rename from django_extensions/tests/testapp/urls.py rename to tests/testapp/urls.py diff --git a/tox.ini b/tox.ini index 219242e89..4138ddc3a 100644 --- a/tox.ini +++ b/tox.ini @@ -11,9 +11,9 @@ envlist = {py27,py32,py33,py34,pypy,pypy3}-django{17,18alpha,master} [testenv] -commands = {envpython} setup.py test +commands = py.test {posargs} -deps = +deps = django14: Django>=1.4,<1.5 django15: Django>=1.5,<1.6 django16: Django>=1.6,<1.7 @@ -32,4 +32,3 @@ commands = python setup.py flake8 deps = flake8 commands = python setup.py flake8 - From 3b0493f3450d198655e1225cb68ae3637bd592d6 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Sun, 15 Feb 2015 17:58:20 +0100 Subject: [PATCH 02/17] Fix FieldTestCase for pytest --- .editorconfig | 18 ++++ run_tests.py | 146 ------------------------------- tests/__init__.py | 8 +- tests/test_clean_pyc.py | 4 +- tests/test_dumpscript.py | 11 +-- tests/test_encrypted_fields.py | 22 +---- tests/test_fields.py | 18 +++- tests/test_management_command.py | 2 +- tests/test_shortuuid_field.py | 17 +--- tox.ini | 24 ++--- 10 files changed, 61 insertions(+), 209 deletions(-) create mode 100644 .editorconfig delete mode 100755 run_tests.py diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..c3533d2ef --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# http://editorconfig.org +# Source: pydanny cookicutter-django repo + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{py,rst,ini}] +indent_style = space +indent_size = 4 + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/run_tests.py b/run_tests.py deleted file mode 100755 index 2679feb4b..000000000 --- a/run_tests.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env python - -import sys -import shutil -import tempfile - -try: - import django -except ImportError: - print("Error: missing test dependency:") - print(" django library is needed to run test suite") - print(" you can install it with 'pip install django'") - print(" or use tox to automatically handle test dependencies") - sys.exit(1) - -try: - import shortuuid -except ImportError: - print("Error: missing test dependency:") - print(" shortuuid library is needed to run test suite") - print(" you can install it with 'pip install shortuuid'") - print(" or use tox to automatically handle test dependencies") - sys.exit(1) - -try: - import dateutil -except ImportError: - print("Error: missing test dependency:") - print(" dateutil library is needed to run test suite") - print(" you can install it with 'pip install python-dateutil'") - print(" or use tox to automatically handle test dependencies") - sys.exit(1) - -try: - import six -except ImportError: - print("Error: missing test dependency:") - print(" six library is needed to run test suite") - print(" you can install it with 'pip install six'") - print(" or use tox to automatically handle test dependencies") - sys.exit(1) - -__test_libs__ = [ - django, - shortuuid, - dateutil, - six -] - -from django.conf import settings - - -def main(): - # Dynamically configure the Django settings with the minimum necessary to - # get Django running tests. - KEY_LOCS = {} - try: - try: - # If KeyCzar is available, set up the environment. - from keyczar import keyczart, keyinfo - - # Create an RSA private key. - keys_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_rsa_dir") - keyczart.Create(keys_dir, "test", keyinfo.DECRYPT_AND_ENCRYPT, asymmetric=True) - keyczart.AddKey(keys_dir, "PRIMARY", size=4096) - KEY_LOCS['DECRYPT_AND_ENCRYPT'] = keys_dir - - # Create an RSA public key. - pub_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_pub_dir") - keyczart.PubKey(keys_dir, pub_dir) - KEY_LOCS['ENCRYPT'] = pub_dir - except ImportError: - pass - - settings.configure( - INSTALLED_APPS=[ - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.admin', - 'django.contrib.sessions', - 'django_extensions.tests.testapp', - 'django_extensions', - ], - MIDDLEWARE_CLASSES=( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - ), - # Django replaces this, but it still wants it. *shrugs* - DATABASE_ENGINE='django.db.backends.sqlite3', - DATABASES={ - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:', - } - }, - MEDIA_ROOT='/tmp/django_extensions_test_media/', - MEDIA_PATH='/media/', - ROOT_URLCONF='django_extensions.tests.urls', - DEBUG=True, - TEMPLATE_DEBUG=True, - ENCRYPTED_FIELD_KEYS_DIR=KEY_LOCS, - ) - - if django.VERSION >= (1, 7): - django.setup() - - apps = ['django_extensions'] - if django.VERSION >= (1, 6): - apps.append('django_extensions.tests.testapp') - apps.append('django_extensions.tests') - - from django.core.management import call_command - from django.test.utils import get_runner - - try: - from django.contrib.auth import get_user_model - except ImportError: - USERNAME_FIELD = "username" - else: - USERNAME_FIELD = get_user_model().USERNAME_FIELD - - DjangoTestRunner = get_runner(settings) - - class TestRunner(DjangoTestRunner): - def setup_databases(self, *args, **kwargs): - result = super(TestRunner, self).setup_databases(*args, **kwargs) - kwargs = { - "interactive": False, - "email": "admin@doesnotexit.com", - USERNAME_FIELD: "admin", - } - call_command("createsuperuser", **kwargs) - return result - - failures = TestRunner(verbosity=2, interactive=True).run_tests(apps) - sys.exit(failures) - - finally: - for name, path in KEY_LOCS.items(): - # cleanup crypto key temp dirs - shutil.rmtree(path) - - -if __name__ == '__main__': - main() diff --git a/tests/__init__.py b/tests/__init__.py index a5184d93f..104338424 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,12 +2,12 @@ from .test_dumpscript import DumpScriptTests from .test_utils import TruncateLetterTests from .test_json_field import JsonFieldTest -from .test_uuid_field import (UUIDFieldTest, - PostgreSQLUUIDFieldTest) +from .test_uuid_field import (UUIDFieldTest, PostgreSQLUUIDFieldTest) from .test_shortuuid_field import ShortUUIDFieldTest from .test_fields import AutoSlugFieldTest -from .test_management_command import CommandTest, \ - ShowTemplateTagsTests, UpdatePermissionsTests, CommandSignalTests +from .test_management_command import (CommandTest, ShowTemplateTagsTests, + UpdatePermissionsTests, + CommandSignalTests) from .test_templatetags import TemplateTagsTests from .test_clean_pyc import CleanPycTests from .test_compile_pyc import CompilePycTests diff --git a/tests/test_clean_pyc.py b/tests/test_clean_pyc.py index 6a19cc9cb..b15fa5c8d 100644 --- a/tests/test_clean_pyc.py +++ b/tests/test_clean_pyc.py @@ -35,7 +35,7 @@ def test_removes_pyc_files(self): def test_takes_path(self): out = six.StringIO() - project_root = os.path.join(get_project_root(), 'tests', 'testapp') + project_root = os.path.join('tests', 'testapp') call_command('compile_pyc', path=project_root) pyc_glob = self._find_pyc(project_root) self.assertTrue(len(pyc_glob) > 0) @@ -45,7 +45,7 @@ def test_takes_path(self): def test_removes_pyo_files(self): out = six.StringIO() - project_root = os.path.join(get_project_root(), 'tests', 'testapp') + project_root = os.path.join('tests', 'testapp') call_command('compile_pyc', path=project_root) pyc_glob = self._find_pyc(project_root) self.assertTrue(len(pyc_glob) > 0) diff --git a/tests/test_dumpscript.py b/tests/test_dumpscript.py index bc02757b1..70232c2f5 100644 --- a/tests/test_dumpscript.py +++ b/tests/test_dumpscript.py @@ -1,3 +1,4 @@ +import ast import sys import six @@ -6,11 +7,6 @@ from .testapp.models import Name, Note, Person from .test_fields import FieldTestCase -if sys.version_info[:2] >= (2, 6): - import ast as compiler # NOQA -else: - import compiler # NOQA - class DumpScriptTests(FieldTestCase): def setUp(self): @@ -34,7 +30,6 @@ def test_runs(self): call_command('dumpscript', 'django_extensions') self.assertTrue('Gabriel' in sys.stdout.getvalue()) - #---------------------------------------------------------------------- def test_replaced_stdout(self): # check if stdout can be replaced sys.stdout = six.StringIO() @@ -46,7 +41,6 @@ def test_replaced_stdout(self): self.assertEqual(0, len(sys.stdout.getvalue())) # there should not be any output to sys.stdout tmp_out.close() - #---------------------------------------------------------------------- def test_replaced_stderr(self): # check if stderr can be replaced, without changing stdout n = Name(name='Fred') @@ -59,7 +53,6 @@ def test_replaced_stderr(self): self.assertEqual(0, len(sys.stderr.getvalue())) # there should not be any output to sys.stderr tmp_err.close() - #---------------------------------------------------------------------- def test_valid_syntax(self): n1 = Name(name='John') n1.save() @@ -77,7 +70,7 @@ def test_valid_syntax(self): p2.notes.add(note1, note2) tmp_out = six.StringIO() call_command('dumpscript', 'django_extensions', stdout=tmp_out) - ast_syntax_tree = compiler.parse(tmp_out.getvalue()) + ast_syntax_tree = ast.parse(tmp_out.getvalue()) if hasattr(ast_syntax_tree, 'body'): self.assertTrue(len(ast_syntax_tree.body) > 1) else: diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index 51c430bf9..4bcc7040e 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -1,9 +1,9 @@ from contextlib import contextmanager import functools +import pytest from django.conf import settings from django.db import connection, models -from django.db.models import loading from .testapp.models import Secret from .test_fields import FieldTestCase @@ -94,21 +94,12 @@ def secret_model(): #differences-between-proxy-inheritance-and-unmanaged-models """ - # Store Django's cached model, if present, so we can restore when the - # manager exits. - orig_model = None - try: - orig_model = loading.cache.app_models['tests']['secret'] - del loading.cache.app_models['tests']['secret'] - except KeyError: - pass - try: # Create a new class that shadows tests.models.Secret. attrs = { 'name': EncryptedCharField("Name", max_length=Secret._meta.get_field('name').max_length), 'text': EncryptedTextField("Text"), - '__module__': 'django_extensions.tests.models', + '__module__': 'tests.testapp.models', 'Meta': type('Meta', (object, ), { 'managed': False, 'db_table': Secret._meta.db_table @@ -119,14 +110,9 @@ def secret_model(): except: raise # Reraise any exceptions. - finally: - # Restore Django's model cache. - try: - loading.cache.app_models['tests']['secret'] = orig_model - except KeyError: - pass - +@pytest.mark.skipif(keyczar_active is False, + reason="Encrypted fields needs that keyczar is installed") class EncryptedFieldsTestCase(FieldTestCase): @run_if_active def testCharFieldCreate(self): diff --git a/tests/test_fields.py b/tests/test_fields.py index e39424736..35f55d28c 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -3,11 +3,11 @@ import django from django.conf import settings from django.core.management import call_command -from django.db.models import loading from django.db import models from django.test import TestCase from django_extensions.db.fields import AutoSlugField + from .testapp.models import SluggedTestModel, ChildSluggedTestModel if django.VERSION[:2] >= (1, 7): @@ -17,12 +17,24 @@ import django_extensions # NOQA +@pytest.mark.django_db class FieldTestCase(TestCase): def setUp(self): self.old_installed_apps = settings.INSTALLED_APPS #settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) #settings.INSTALLED_APPS.append('django_extensions.tests.testapp') - loading.cache.loaded = False + + # Create a superuser + try: + from django.contrib.auth import get_user_model # NOQA + except ImportError: + from django.contrib.auth.models import User # NOQA + else: + User = get_user_model() + + User.objects.create_superuser(username='admin', + email='admin@admin.com', + password='password') # Don't migrate if south is installed migrate = 'south' not in settings.INSTALLED_APPS @@ -131,7 +143,7 @@ def testInheritanceCreatesNextSlug(self): o = SluggedTestModel(title='foo') o.save() self.assertEqual(o.slug, 'foo-3') - + @pytest.mark.skipif(django.VERSION < (1, 7), reason="Migrations are handled by south in Django <1.7") def test_17_migration(self): diff --git a/tests/test_management_command.py b/tests/test_management_command.py index 04c82165d..86340c54c 100644 --- a/tests/test_management_command.py +++ b/tests/test_management_command.py @@ -41,7 +41,7 @@ def test_error_logging(self): # Ensure command errors are properly logged and reraised from django_extensions.management.base import logger logger.addHandler(MockLoggingHandler()) - module_path = "django_extensions.tests.management.commands.error_raising_command" + module_path = "tests.management.commands.error_raising_command" module = importlib.import_module(module_path) error_raising_command = module.Command() self.assertRaises(Exception, error_raising_command.execute) diff --git a/tests/test_shortuuid_field.py b/tests/test_shortuuid_field.py index 8f883421e..9ceb3ee91 100644 --- a/tests/test_shortuuid_field.py +++ b/tests/test_shortuuid_field.py @@ -1,23 +1,10 @@ import six -from django.conf import settings -from django.core.management import call_command -from django.db.models import loading -from django.utils import unittest +from .test_fields import FieldTestCase from .testapp.models import ShortUUIDTestModel_field, ShortUUIDTestModel_pk, ShortUUIDTestAgregateModel, ShortUUIDTestManyToManyModel -class ShortUUIDFieldTest(unittest.TestCase): - def setUp(self): - self.old_installed_apps = settings.INSTALLED_APPS - settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) - settings.INSTALLED_APPS.append('django_extensions.tests') - loading.cache.loaded = False - call_command('syncdb', verbosity=0) - - def tearDown(self): - settings.INSTALLED_APPS = self.old_installed_apps - +class ShortUUIDFieldTest(FieldTestCase): def testUUIDFieldCreate(self): j = ShortUUIDTestModel_field.objects.create(a=6, uuid_field=six.u('vytxeTZskVKR7C7WgdSP3d')) self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3d')) diff --git a/tox.ini b/tox.ini index 4138ddc3a..66b503e4e 100644 --- a/tox.ini +++ b/tox.ini @@ -6,22 +6,24 @@ [tox] envlist = {py27,py34}-flake8, - {py26,py27}-django14, - {py26,py27,py32,py33,py34}-django{15,16}, - {py27,py32,py33,py34,pypy,pypy3}-django{17,18alpha,master} + {py26,py27}-dj14, + {py26,py27,py32,py33,py34}-dj{15,16}, + {py27,py32,py33,py34,pypy,pypy3}-dj{17,18a,master} [testenv] commands = py.test {posargs} deps = - django14: Django>=1.4,<1.5 - django15: Django>=1.5,<1.6 - django16: Django>=1.6,<1.7 - django17: Django>=1.7,<1.8 - django18alpha: https://www.djangoproject.com/download/1.8a1/tarball/ - djangomaster: https://github.com/django/django/zipball/master - shortuuid==0.4 - python-dateutil + dj14: Django>=1.4,<1.5 + dj15: Django>=1.5,<1.6 + dj16: Django>=1.6,<1.7 + dj17: Django>=1.7,<1.8 + dj18a: https://www.djangoproject.com/download/1.8a1/tarball/ + djmaster: https://github.com/django/django/zipball/master + shortuuid==0.4 + python-dateutil + pytest-django==2.8.0 + py27: python-keyczar [testenv:py27-flake8] deps = From fc28dec680b21da25f00bf2a1bc74062f5891db3 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Sun, 15 Feb 2015 19:27:46 +0100 Subject: [PATCH 03/17] Skip tests for encrypted fields if django<1.7 --- tests/test_encrypted_fields.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index 4bcc7040e..408e5a89f 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -1,7 +1,9 @@ from contextlib import contextmanager import functools + import pytest +import django from django.conf import settings from django.db import connection, models @@ -111,7 +113,7 @@ def secret_model(): raise # Reraise any exceptions. -@pytest.mark.skipif(keyczar_active is False, +@pytest.mark.skipif(keyczar_active is False or django.VERSION < (1, 7), reason="Encrypted fields needs that keyczar is installed") class EncryptedFieldsTestCase(FieldTestCase): @run_if_active From 98056ab4e3877e07e42c542f36a0eab9bb2dcaac Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Sun, 15 Feb 2015 21:11:18 +0100 Subject: [PATCH 04/17] Fix TOXENV var in travis --- .travis.yml | 72 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f766278e..4ee3b8ffa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,46 +5,46 @@ sudo: false env: - TOX_ENV=py27-flake8 - TOX_ENV=py34-flake8 - - TOX_ENV=py26-django14 - - TOX_ENV=py27-django14 - - TOX_ENV=py26-django15 - - TOX_ENV=py26-django16 - - TOX_ENV=py27-django15 - - TOX_ENV=py27-django16 - - TOX_ENV=py32-django15 - - TOX_ENV=py32-django16 - - TOX_ENV=py33-django15 - - TOX_ENV=py33-django16 - - TOX_ENV=py34-django15 - - TOX_ENV=py34-django16 - - TOX_ENV=py27-django17 - - TOX_ENV=py27-django18alpha - - TOX_ENV=py27-djangomaster - - TOX_ENV=py32-django17 - - TOX_ENV=py32-django18alpha - - TOX_ENV=py32-djangomaster - - TOX_ENV=py33-django17 - - TOX_ENV=py33-django18alpha - - TOX_ENV=py33-djangomaster - - TOX_ENV=py34-django17 - - TOX_ENV=py34-django18alpha - - TOX_ENV=py34-djangomaster - - TOX_ENV=pypy-django17 - - TOX_ENV=pypy-django18alpha - - TOX_ENV=pypy-djangomaster - - TOX_ENV=pypy3-django17 - - TOX_ENV=pypy3-django18alpha - - TOX_ENV=pypy3-djangomaster + - TOX_ENV=py26-dj14 + - TOX_ENV=py27-dj14 + - TOX_ENV=py26-dj15 + - TOX_ENV=py26-dj16 + - TOX_ENV=py27-dj15 + - TOX_ENV=py27-dj16 + - TOX_ENV=py32-dj15 + - TOX_ENV=py32-dj16 + - TOX_ENV=py33-dj15 + - TOX_ENV=py33-dj16 + - TOX_ENV=py34-dj15 + - TOX_ENV=py34-dj16 + - TOX_ENV=py27-dj17 + - TOX_ENV=py27-dj18a + - TOX_ENV=py27-djmaster + - TOX_ENV=py32-dj17 + - TOX_ENV=py32-dj18a + - TOX_ENV=py32-djmaster + - TOX_ENV=py33-dj17 + - TOX_ENV=py33-dj18a + - TOX_ENV=py33-djmaster + - TOX_ENV=py34-dj17 + - TOX_ENV=py34-dj18a + - TOX_ENV=py34-djmaster + - TOX_ENV=pypy-dj17 + - TOX_ENV=pypy-dj18a + - TOX_ENV=pypy-djmaster + - TOX_ENV=pypy3-dj17 + - TOX_ENV=pypy3-dj18a + - TOX_ENV=pypy3-djmaster matrix: fast_finish: true allow_failures: - - env: TOX_ENV=py34-djangomaster - - env: TOX_ENV=py33-djangomaster - - env: TOX_ENV=py32-djangomaster - - env: TOX_ENV=py27-djangomaster - - env: TOX_ENV=pypy-djangomaster - - env: TOX_ENV=pypy3-djangomaster + - env: TOX_ENV=py34-djmaster + - env: TOX_ENV=py33-djmaster + - env: TOX_ENV=py32-djmaster + - env: TOX_ENV=py27-djmaster + - env: TOX_ENV=pypy-djmaster + - env: TOX_ENV=pypy3-djmaster install: - pip install tox From 4a3fc2226e82f018e2286ef133de2916b34d86f8 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Sun, 15 Feb 2015 21:11:49 +0100 Subject: [PATCH 05/17] Use django TestCase in test_dumpscript --- tests/test_dumpscript.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/test_dumpscript.py b/tests/test_dumpscript.py index 70232c2f5..6f1e6f19a 100644 --- a/tests/test_dumpscript.py +++ b/tests/test_dumpscript.py @@ -3,26 +3,16 @@ import six from django.core.management import call_command +from django.test import TestCase from .testapp.models import Name, Note, Person -from .test_fields import FieldTestCase -class DumpScriptTests(FieldTestCase): +class DumpScriptTests(TestCase): def setUp(self): - super(DumpScriptTests, self).setUp() - - self.real_stdout = sys.stdout - self.real_stderr = sys.stderr sys.stdout = six.StringIO() sys.stderr = six.StringIO() - def tearDown(self): - super(DumpScriptTests, self).tearDown() - - sys.stdout = self.real_stdout - sys.stderr = self.real_stderr - def test_runs(self): # lame test...does it run? n = Name(name='Gabriel') From 1a7c9a987dab741d813c4a285e2922e45b11c03f Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Sun, 15 Feb 2015 21:40:35 +0100 Subject: [PATCH 06/17] Remove old uuid tests for python<2.5 --- tests/test_utils.py | 49 --------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 23935b66e..1e8d9eb11 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,16 +1,9 @@ # -*- coding: utf-8 -*- -import sys import six from django.test import TestCase -from django.utils.unittest import skipIf from django_extensions.utils.text import truncate_letters -try: - import uuid - assert uuid -except ImportError: - from django_extensions.utils import uuid class TruncateLetterTests(TestCase): @@ -32,45 +25,3 @@ def test_with_non_ascii_characters(self): six.u('\u5ce0 (\u3068\u3046\u3052 t\u014dg...'), truncate_letters("峠 (とうげ tōge - mountain pass)", 10) ) - - -class UUIDTests(TestCase): - @skipIf(sys.version_info >= (2, 5, 0), 'uuid already in stdlib') - def test_uuid3(self): - # make a UUID using an MD5 hash of a namespace UUID and a name - self.assertEqual( - uuid.UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e'), - uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') - ) - - @skipIf(sys.version_info >= (2, 5, 0), 'uuid already in stdlib') - def test_uuid5(self): - # make a UUID using a SHA-1 hash of a namespace UUID and a name - self.assertEqual( - uuid.UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d'), - uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org') - ) - - @skipIf(sys.version_info >= (2, 5, 0), 'uuid already in stdlib') - def test_uuid_str(self): - # make a UUID from a string of hex digits (braces and hyphens ignored) - x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') - # convert a UUID to a string of hex digits in standard form - self.assertEqual('00010203-0405-0607-0809-0a0b0c0d0e0f', str(x)) - - @skipIf(sys.version_info >= (2, 5, 0), 'uuid already in stdlib') - def test_uuid_bytes(self): - # make a UUID from a string of hex digits (braces and hyphens ignored) - x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') - # get the raw 16 bytes of the UUID - self.assertEqual( - '\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f', - x.bytes - ) - - @skipIf(sys.version_info >= (2, 5, 0), 'uuid already in stdlib') - def test_make_uuid_from_byte_string(self): - self.assertEqual( - uuid.UUID(bytes='\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f'), - uuid.UUID('00010203-0405-0607-0809-0a0b0c0d0e0f') - ) From 189c5521fbee35b5d164011b41bacc3c28fc939d Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 17:09:13 +0100 Subject: [PATCH 07/17] Refactored test_fields --- tests/__init__.py | 2 +- ...test_fields.py => test_autoslug_fields.py} | 60 ++++++------------- tests/test_encrypted_fields.py | 2 +- tests/test_json_field.py | 2 +- tests/test_shortuuid_field.py | 2 +- tests/test_uuid_field.py | 2 +- tests/utils.py | 18 ++++++ 7 files changed, 40 insertions(+), 48 deletions(-) rename tests/{test_fields.py => test_autoslug_fields.py} (77%) create mode 100644 tests/utils.py diff --git a/tests/__init__.py b/tests/__init__.py index 104338424..be1c5c93e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,7 +4,7 @@ from .test_json_field import JsonFieldTest from .test_uuid_field import (UUIDFieldTest, PostgreSQLUUIDFieldTest) from .test_shortuuid_field import ShortUUIDFieldTest -from .test_fields import AutoSlugFieldTest +from .test_autoslug_fields import AutoSlugFieldTest from .test_management_command import (CommandTest, ShowTemplateTagsTests, UpdatePermissionsTests, CommandSignalTests) diff --git a/tests/test_fields.py b/tests/test_autoslug_fields.py similarity index 77% rename from tests/test_fields.py rename to tests/test_autoslug_fields.py index 35f55d28c..8b5da5730 100644 --- a/tests/test_fields.py +++ b/tests/test_autoslug_fields.py @@ -1,60 +1,21 @@ import pytest import django -from django.conf import settings -from django.core.management import call_command from django.db import models from django.test import TestCase from django_extensions.db.fields import AutoSlugField from .testapp.models import SluggedTestModel, ChildSluggedTestModel +from .utils import FieldTestCase -if django.VERSION[:2] >= (1, 7): +if django.VERSION >= (1, 7): from django.db import migrations # NOQA from django.db.migrations.writer import MigrationWriter # NOQA from django.utils import six # NOQA import django_extensions # NOQA -@pytest.mark.django_db -class FieldTestCase(TestCase): - def setUp(self): - self.old_installed_apps = settings.INSTALLED_APPS - #settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) - #settings.INSTALLED_APPS.append('django_extensions.tests.testapp') - - # Create a superuser - try: - from django.contrib.auth import get_user_model # NOQA - except ImportError: - from django.contrib.auth.models import User # NOQA - else: - User = get_user_model() - - User.objects.create_superuser(username='admin', - email='admin@admin.com', - password='password') - - # Don't migrate if south is installed - migrate = 'south' not in settings.INSTALLED_APPS - call_command('syncdb', verbosity=0, migrate=migrate) - - def tearDown(self): - settings.INSTALLED_APPS = self.old_installed_apps - - def safe_exec(self, string, value=None): - l = {} - try: - exec(string, globals(), l) - except Exception as e: - if value: - self.fail("Could not exec %r (from value %r): %s" % (string.strip(), value, e)) - else: - self.fail("Could not exec %r: %s" % (string.strip(), e)) - return l - - class AutoSlugFieldTest(FieldTestCase): def tearDown(self): super(AutoSlugFieldTest, self).tearDown() @@ -144,8 +105,21 @@ def testInheritanceCreatesNextSlug(self): o.save() self.assertEqual(o.slug, 'foo-3') - @pytest.mark.skipif(django.VERSION < (1, 7), - reason="Migrations are handled by south in Django <1.7") +@pytest.mark.skipif(django.VERSION < (1, 7), + reason="Migrations are handled by south in Django <1.7") +class TestMigration(TestCase): + def safe_exec(self, string, value=None): + l = {} + try: + exec(string, globals(), l) + except Exception as e: + if value: + self.fail("Could not exec %r (from value %r): %s" % (string.strip(), value, e)) + else: + self.fail("Could not exec %r: %s" % (string.strip(), e)) + return l + + def test_17_migration(self): """ Tests making migrations with Django 1.7+'s migration framework diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index 408e5a89f..3895eb046 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -8,7 +8,7 @@ from django.db import connection, models from .testapp.models import Secret -from .test_fields import FieldTestCase +from .utils import FieldTestCase # Only perform encrypted fields tests if keyczar is present. Resolves # http://github.com/django-extensions/django-extensions/issues/#issue/17 diff --git a/tests/test_json_field.py b/tests/test_json_field.py index a62627dd5..7320b7815 100644 --- a/tests/test_json_field.py +++ b/tests/test_json_field.py @@ -1,4 +1,4 @@ -from .test_fields import FieldTestCase +from .utils import FieldTestCase from .testapp.models import JSONFieldTestModel diff --git a/tests/test_shortuuid_field.py b/tests/test_shortuuid_field.py index 9ceb3ee91..fddff3a97 100644 --- a/tests/test_shortuuid_field.py +++ b/tests/test_shortuuid_field.py @@ -1,5 +1,5 @@ import six -from .test_fields import FieldTestCase +from .utils import FieldTestCase from .testapp.models import ShortUUIDTestModel_field, ShortUUIDTestModel_pk, ShortUUIDTestAgregateModel, ShortUUIDTestManyToManyModel diff --git a/tests/test_uuid_field.py b/tests/test_uuid_field.py index f52889454..05a064048 100644 --- a/tests/test_uuid_field.py +++ b/tests/test_uuid_field.py @@ -4,7 +4,7 @@ import six from django_extensions.db.fields import PostgreSQLUUIDField -from .test_fields import FieldTestCase +from .utils import FieldTestCase from .testapp.models import UUIDTestModel_field, UUIDTestModel_pk, UUIDTestAgregateModel, UUIDTestManyToManyModel diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 000000000..43447875f --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,18 @@ +import pytest + +import django +from django.conf import settings +from django.core.management import call_command +from django.test import TestCase + +if django.VERSION >= (1, 7): + from django.db import migrations # NOQA + from django.db import models # NOQA + from django.db.migrations.writer import MigrationWriter # NOQA + from django.utils import six # NOQA + import django_extensions # NOQA + +@pytest.mark.usefixtures("admin_user") +class FieldTestCase(TestCase): + """A Django TestCase with an admin user""" + pass From 3dfbf810600d0b0bd020f59a175d06febd953dd3 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 17:27:55 +0100 Subject: [PATCH 08/17] Use django TestCase in test_uuid_field --- tests/test_uuid_field.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_uuid_field.py b/tests/test_uuid_field.py index 05a064048..2aa53103b 100644 --- a/tests/test_uuid_field.py +++ b/tests/test_uuid_field.py @@ -3,12 +3,14 @@ import six +from django.test import TestCase + from django_extensions.db.fields import PostgreSQLUUIDField -from .utils import FieldTestCase + from .testapp.models import UUIDTestModel_field, UUIDTestModel_pk, UUIDTestAgregateModel, UUIDTestManyToManyModel -class UUIDFieldTest(FieldTestCase): +class UUIDFieldTest(TestCase): def testUUIDFieldCreate(self): j = UUIDTestModel_field.objects.create(a=6, uuid_field=six.u('550e8400-e29b-41d4-a716-446655440000')) self.assertEqual(j.uuid_field, six.u('550e8400-e29b-41d4-a716-446655440000')) @@ -30,7 +32,7 @@ def testUUIDFieldManyToManyCreate(self): self.assertEqual(j.pk, six.u('550e8400-e29b-41d4-a716-446655440010')) -class PostgreSQLUUIDFieldTest(FieldTestCase): +class PostgreSQLUUIDFieldTest(TestCase): def test_uuid_casting(self): # As explain by postgres documentation # http://www.postgresql.org/docs/9.1/static/datatype-uuid.html From 2deba5ce2584e834e99bdceccb41006d98bfc587 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 17:31:07 +0100 Subject: [PATCH 09/17] Use django TestCase in test_shortuuid_field --- tests/test_shortuuid_field.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_shortuuid_field.py b/tests/test_shortuuid_field.py index fddff3a97..f9ee577e9 100644 --- a/tests/test_shortuuid_field.py +++ b/tests/test_shortuuid_field.py @@ -1,10 +1,11 @@ import six -from .utils import FieldTestCase + +from django.test import TestCase from .testapp.models import ShortUUIDTestModel_field, ShortUUIDTestModel_pk, ShortUUIDTestAgregateModel, ShortUUIDTestManyToManyModel -class ShortUUIDFieldTest(FieldTestCase): +class ShortUUIDFieldTest(TestCase): def testUUIDFieldCreate(self): j = ShortUUIDTestModel_field.objects.create(a=6, uuid_field=six.u('vytxeTZskVKR7C7WgdSP3d')) self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3d')) From f2af6891935e8714a853c299fb85d35926c00f9e Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 17:32:44 +0100 Subject: [PATCH 10/17] Use django TestCase in test_json_field --- tests/test_json_field.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_json_field.py b/tests/test_json_field.py index 7320b7815..7ca3b77a9 100644 --- a/tests/test_json_field.py +++ b/tests/test_json_field.py @@ -1,8 +1,9 @@ -from .utils import FieldTestCase +from django.test import TestCase + from .testapp.models import JSONFieldTestModel -class JsonFieldTest(FieldTestCase): +class JsonFieldTest(TestCase): def testCharFieldCreate(self): j = JSONFieldTestModel.objects.create(a=6, j_field=dict(foo='bar')) self.assertEqual(j.a, 6) From 013cebd4cdb37f24fe274a85a89fd41d48f27fb8 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 20:35:57 +0100 Subject: [PATCH 11/17] Add pytest-xdist in tox deps to speedup tests --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 66b503e4e..4fd7f5f1a 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,7 @@ deps = shortuuid==0.4 python-dateutil pytest-django==2.8.0 + pytest-xdist py27: python-keyczar [testenv:py27-flake8] From 7130dfd4e84ea137dd0c2177073e9e617a485fe2 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 20:39:40 +0100 Subject: [PATCH 12/17] Remove run_if_active context manager in test_encrypted_files --- tests/test_encrypted_fields.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index 3895eb046..1c24ffd7c 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -1,5 +1,4 @@ from contextlib import contextmanager -import functools import pytest @@ -19,18 +18,6 @@ except ImportError: keyczar_active = False - -def run_if_active(func): - "Method decorator that only runs a test if KeyCzar is available." - - @functools.wraps(func) - def inner(self): - if not keyczar_active: - return - return func(self) - return inner - - # Locations of both private and public keys. KEY_LOCS = getattr(settings, 'ENCRYPTED_FIELD_KEYS_DIR', {}) @@ -116,7 +103,6 @@ def secret_model(): @pytest.mark.skipif(keyczar_active is False or django.VERSION < (1, 7), reason="Encrypted fields needs that keyczar is installed") class EncryptedFieldsTestCase(FieldTestCase): - @run_if_active def testCharFieldCreate(self): """ Uses a private key to encrypt data on model creation. @@ -134,7 +120,6 @@ def testCharFieldCreate(self): decrypted_val = crypt.Decrypt(db_val[len(EncryptedCharField.prefix):]) self.assertEqual(test_val, decrypted_val) - @run_if_active def testCharFieldRead(self): """ Uses a private key to encrypt data on model creation. @@ -148,7 +133,6 @@ def testCharFieldRead(self): retrieved_secret = model.objects.get(id=secret.id) self.assertEqual(test_val, retrieved_secret.name) - @run_if_active def testTextFieldCreate(self): """ Uses a private key to encrypt data on model creation. @@ -165,7 +149,6 @@ def testTextFieldCreate(self): decrypted_val = crypt.Decrypt(db_val[len(EncryptedCharField.prefix):]) self.assertEqual(test_val, decrypted_val) - @run_if_active def testTextFieldRead(self): """ Uses a private key to encrypt data on model creation. @@ -179,7 +162,6 @@ def testTextFieldRead(self): retrieved_secret = model.objects.get(id=secret.id) self.assertEqual(test_val, retrieved_secret.text) - @run_if_active def testCannotDecrypt(self): """ Uses a public key to encrypt data on model creation. @@ -193,7 +175,6 @@ def testCannotDecrypt(self): self.assertNotEqual(test_val, retrieved_secret.name) self.assertTrue(retrieved_secret.name.startswith(EncryptedCharField.prefix)) - @run_if_active def testUnacceptablePurpose(self): """ Tries to create an encrypted field with a mode mismatch. @@ -208,7 +189,6 @@ def testUnacceptablePurpose(self): # definition time, so any code in here would never get run. pass - @run_if_active def testDecryptionForbidden(self): """ Uses a private key to encrypt data, but decryption is not allowed. @@ -223,7 +203,6 @@ def testDecryptionForbidden(self): self.assertNotEqual(test_val, retrieved_secret.name) self.assertTrue(retrieved_secret.name.startswith(EncryptedCharField.prefix)) - @run_if_active def testEncryptPublicDecryptPrivate(self): """ Uses a public key to encrypt, and a private key to decrypt data. From 73317f00e3721febc79c8dcb2b34018fa2e72e1d Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 21:19:53 +0100 Subject: [PATCH 13/17] Removed tests/utils file and cleanup --- .editorconfig | 2 +- tests/__init__.py | 26 -------------------------- tests/test_autoslug_fields.py | 6 +++--- tests/test_encrypted_fields.py | 11 +++++++++-- tests/utils.py | 18 ------------------ 5 files changed, 13 insertions(+), 50 deletions(-) delete mode 100644 tests/utils.py diff --git a/.editorconfig b/.editorconfig index c3533d2ef..5c99f6582 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,5 @@ # http://editorconfig.org -# Source: pydanny cookicutter-django repo +# Source: pydanny cookiecutter-django repo root = true diff --git a/tests/__init__.py b/tests/__init__.py index be1c5c93e..e69de29bb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,26 +0,0 @@ -from django.db import models # NOQA -from .test_dumpscript import DumpScriptTests -from .test_utils import TruncateLetterTests -from .test_json_field import JsonFieldTest -from .test_uuid_field import (UUIDFieldTest, PostgreSQLUUIDFieldTest) -from .test_shortuuid_field import ShortUUIDFieldTest -from .test_autoslug_fields import AutoSlugFieldTest -from .test_management_command import (CommandTest, ShowTemplateTagsTests, - UpdatePermissionsTests, - CommandSignalTests) -from .test_templatetags import TemplateTagsTests -from .test_clean_pyc import CleanPycTests -from .test_compile_pyc import CompilePycTests - -__test_classes__ = [ - DumpScriptTests, JsonFieldTest, UUIDFieldTest, AutoSlugFieldTest, - CommandTest, ShowTemplateTagsTests, TruncateLetterTests, TemplateTagsTests, - ShortUUIDFieldTest, PostgreSQLUUIDFieldTest, CleanPycTests, CompilePycTests, - UpdatePermissionsTests, CommandSignalTests -] - -try: - from .encrypted_fields import EncryptedFieldsTestCase - __test_classes__.append(EncryptedFieldsTestCase) -except ImportError: - pass diff --git a/tests/test_autoslug_fields.py b/tests/test_autoslug_fields.py index 8b5da5730..05d944c7a 100644 --- a/tests/test_autoslug_fields.py +++ b/tests/test_autoslug_fields.py @@ -7,7 +7,6 @@ from django_extensions.db.fields import AutoSlugField from .testapp.models import SluggedTestModel, ChildSluggedTestModel -from .utils import FieldTestCase if django.VERSION >= (1, 7): from django.db import migrations # NOQA @@ -16,7 +15,8 @@ import django_extensions # NOQA -class AutoSlugFieldTest(FieldTestCase): +@pytest.mark.usefixtures("admin_user") +class AutoSlugFieldTest(TestCase): def tearDown(self): super(AutoSlugFieldTest, self).tearDown() @@ -105,6 +105,7 @@ def testInheritanceCreatesNextSlug(self): o.save() self.assertEqual(o.slug, 'foo-3') + @pytest.mark.skipif(django.VERSION < (1, 7), reason="Migrations are handled by south in Django <1.7") class TestMigration(TestCase): @@ -119,7 +120,6 @@ def safe_exec(self, string, value=None): self.fail("Could not exec %r: %s" % (string.strip(), e)) return l - def test_17_migration(self): """ Tests making migrations with Django 1.7+'s migration framework diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index 1c24ffd7c..19a45db0f 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -5,9 +5,9 @@ import django from django.conf import settings from django.db import connection, models +from django.test import TestCase from .testapp.models import Secret -from .utils import FieldTestCase # Only perform encrypted fields tests if keyczar is present. Resolves # http://github.com/django-extensions/django-extensions/issues/#issue/17 @@ -102,7 +102,14 @@ def secret_model(): @pytest.mark.skipif(keyczar_active is False or django.VERSION < (1, 7), reason="Encrypted fields needs that keyczar is installed") -class EncryptedFieldsTestCase(FieldTestCase): +@pytest.mark.usefixtures("admin_user") +class EncryptedFieldsTestCase(TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + def testCharFieldCreate(self): """ Uses a private key to encrypt data on model creation. diff --git a/tests/utils.py b/tests/utils.py deleted file mode 100644 index 43447875f..000000000 --- a/tests/utils.py +++ /dev/null @@ -1,18 +0,0 @@ -import pytest - -import django -from django.conf import settings -from django.core.management import call_command -from django.test import TestCase - -if django.VERSION >= (1, 7): - from django.db import migrations # NOQA - from django.db import models # NOQA - from django.db.migrations.writer import MigrationWriter # NOQA - from django.utils import six # NOQA - import django_extensions # NOQA - -@pytest.mark.usefixtures("admin_user") -class FieldTestCase(TestCase): - """A Django TestCase with an admin user""" - pass From 089419f08cbda5c6476320195c10f7e3b52ee806 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Mon, 16 Feb 2015 23:47:15 +0100 Subject: [PATCH 14/17] Cleanup keyczar keys tempdir --- tests/test_encrypted_fields.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index 19a45db0f..e4b4b9974 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -22,6 +22,16 @@ KEY_LOCS = getattr(settings, 'ENCRYPTED_FIELD_KEYS_DIR', {}) +@pytest.fixture(scope="class") +def clean(request): + def cleanup(): + import shutil + for name, path in KEY_LOCS.items(): + # cleanup crypto key temp dirs + shutil.rmtree(path) + request.addfinalizer(cleanup) + + @contextmanager def keys(purpose, mode=None): """ @@ -102,7 +112,7 @@ def secret_model(): @pytest.mark.skipif(keyczar_active is False or django.VERSION < (1, 7), reason="Encrypted fields needs that keyczar is installed") -@pytest.mark.usefixtures("admin_user") +@pytest.mark.usefixtures("admin_user", "clean") class EncryptedFieldsTestCase(TestCase): def setUp(self): pass From bb4c80bfe073ccd8f46f4ed3b1fb2add9e910932 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Tue, 17 Feb 2015 10:11:13 +0100 Subject: [PATCH 15/17] Include creation keyczar keys in test_encrypted_files --- conftest.py | 19 --------------- tests/test_encrypted_fields.py | 44 ++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/conftest.py b/conftest.py index 1907d71c8..8105b1671 100644 --- a/conftest.py +++ b/conftest.py @@ -43,24 +43,6 @@ def pytest_configure(): # Dynamically configure the Django settings with the minimum necessary to # get Django running tests. - KEY_LOCS = {} - try: - # If KeyCzar is available, set up the environment. - from keyczar import keyczart, keyinfo - - # Create an RSA private key. - keys_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_rsa_dir") - keyczart.Create(keys_dir, "test", keyinfo.DECRYPT_AND_ENCRYPT, asymmetric=True) - keyczart.AddKey(keys_dir, "PRIMARY", size=4096) - KEY_LOCS['DECRYPT_AND_ENCRYPT'] = keys_dir - - # Create an RSA public key. - pub_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_pub_dir") - keyczart.PubKey(keys_dir, pub_dir) - KEY_LOCS['ENCRYPT'] = pub_dir - except ImportError: - pass - settings.configure( INSTALLED_APPS=[ 'django.contrib.auth', @@ -88,5 +70,4 @@ def pytest_configure(): ROOT_URLCONF='tests.urls', DEBUG=True, TEMPLATE_DEBUG=True, - ENCRYPTED_FIELD_KEYS_DIR=KEY_LOCS, ) diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index e4b4b9974..da517ae67 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -1,3 +1,4 @@ +import tempfile from contextlib import contextmanager import pytest @@ -19,15 +20,28 @@ keyczar_active = False # Locations of both private and public keys. -KEY_LOCS = getattr(settings, 'ENCRYPTED_FIELD_KEYS_DIR', {}) +KEY_LOCS = {} @pytest.fixture(scope="class") -def clean(request): +def keyczar_keys(request): + # If KeyCzar is available, set up the environment. + if keyczar_active: + # Create an RSA private key. + keys_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_rsa_dir") + keyczart.Create(keys_dir, "test", keyinfo.DECRYPT_AND_ENCRYPT, asymmetric=True) + keyczart.AddKey(keys_dir, "PRIMARY", size=4096) + KEY_LOCS['DECRYPT_AND_ENCRYPT'] = keys_dir + + # Create an RSA public key. + pub_dir = tempfile.mkdtemp("django_extensions_tests_keyzcar_pub_dir") + keyczart.PubKey(keys_dir, pub_dir) + KEY_LOCS['ENCRYPT'] = pub_dir + + # cleanup crypto key temp dirs def cleanup(): import shutil for name, path in KEY_LOCS.items(): - # cleanup crypto key temp dirs shutil.rmtree(path) request.addfinalizer(cleanup) @@ -112,15 +126,9 @@ def secret_model(): @pytest.mark.skipif(keyczar_active is False or django.VERSION < (1, 7), reason="Encrypted fields needs that keyczar is installed") -@pytest.mark.usefixtures("admin_user", "clean") +@pytest.mark.usefixtures("admin_user", "keyczar_keys") class EncryptedFieldsTestCase(TestCase): - def setUp(self): - pass - - def tearDown(self): - pass - - def testCharFieldCreate(self): + def test_char_field_create(self): """ Uses a private key to encrypt data on model creation. Verifies the data is encrypted in the database and can be decrypted. @@ -137,7 +145,7 @@ def testCharFieldCreate(self): decrypted_val = crypt.Decrypt(db_val[len(EncryptedCharField.prefix):]) self.assertEqual(test_val, decrypted_val) - def testCharFieldRead(self): + def test_char_field_read(self): """ Uses a private key to encrypt data on model creation. Verifies the data is decrypted when reading the value back from the @@ -150,7 +158,7 @@ def testCharFieldRead(self): retrieved_secret = model.objects.get(id=secret.id) self.assertEqual(test_val, retrieved_secret.name) - def testTextFieldCreate(self): + def test_text_field_create(self): """ Uses a private key to encrypt data on model creation. Verifies the data is encrypted in the database and can be decrypted. @@ -166,7 +174,7 @@ def testTextFieldCreate(self): decrypted_val = crypt.Decrypt(db_val[len(EncryptedCharField.prefix):]) self.assertEqual(test_val, decrypted_val) - def testTextFieldRead(self): + def test_text_field_read(self): """ Uses a private key to encrypt data on model creation. Verifies the data is decrypted when reading the value back from the @@ -179,7 +187,7 @@ def testTextFieldRead(self): retrieved_secret = model.objects.get(id=secret.id) self.assertEqual(test_val, retrieved_secret.text) - def testCannotDecrypt(self): + def test_cannot_decrypt(self): """ Uses a public key to encrypt data on model creation. Verifies that the data cannot be decrypted using the same key. @@ -192,7 +200,7 @@ def testCannotDecrypt(self): self.assertNotEqual(test_val, retrieved_secret.name) self.assertTrue(retrieved_secret.name.startswith(EncryptedCharField.prefix)) - def testUnacceptablePurpose(self): + def test_unacceptable_purpose(self): """ Tries to create an encrypted field with a mode mismatch. A purpose of "DECRYPT_AND_ENCRYPT" cannot be used with a public key, @@ -206,7 +214,7 @@ def testUnacceptablePurpose(self): # definition time, so any code in here would never get run. pass - def testDecryptionForbidden(self): + def test_decryption_forbidden(self): """ Uses a private key to encrypt data, but decryption is not allowed. ENCRYPTED_FIELD_MODE is explicitly set to ENCRYPT, meaning data should @@ -220,7 +228,7 @@ def testDecryptionForbidden(self): self.assertNotEqual(test_val, retrieved_secret.name) self.assertTrue(retrieved_secret.name.startswith(EncryptedCharField.prefix)) - def testEncryptPublicDecryptPrivate(self): + def test_encrypt_public_decrypt_private(self): """ Uses a public key to encrypt, and a private key to decrypt data. """ From 919bfb6c3e46e73636329fc0721cb1782ab4608e Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Tue, 17 Feb 2015 10:27:13 +0100 Subject: [PATCH 16/17] Refactor imports in test files --- tests/test_autoslug_fields.py | 4 ++-- tests/test_clean_pyc.py | 7 ++++--- tests/test_compile_pyc.py | 5 +++-- tests/test_dumpscript.py | 2 +- tests/test_encrypted_fields.py | 1 + tests/test_management_command.py | 8 +++++--- tests/test_models.py | 2 +- tests/test_shortuuid_field.py | 7 ++++++- tests/test_templatetags.py | 1 - tests/test_utils.py | 1 - tests/test_uuid_field.py | 11 +++++++---- 11 files changed, 30 insertions(+), 19 deletions(-) diff --git a/tests/test_autoslug_fields.py b/tests/test_autoslug_fields.py index 05d944c7a..f2c0686e6 100644 --- a/tests/test_autoslug_fields.py +++ b/tests/test_autoslug_fields.py @@ -3,10 +3,10 @@ import django from django.db import models from django.test import TestCase - from django_extensions.db.fields import AutoSlugField -from .testapp.models import SluggedTestModel, ChildSluggedTestModel +from .testapp.models import ChildSluggedTestModel, SluggedTestModel + if django.VERSION >= (1, 7): from django.db import migrations # NOQA diff --git a/tests/test_clean_pyc.py b/tests/test_clean_pyc.py index b15fa5c8d..09885923b 100644 --- a/tests/test_clean_pyc.py +++ b/tests/test_clean_pyc.py @@ -1,9 +1,10 @@ +import fnmatch import os -import six import shutil -import fnmatch -from django.test import TestCase +import six + from django.core.management import call_command +from django.test import TestCase from django_extensions.management.utils import get_project_root diff --git a/tests/test_compile_pyc.py b/tests/test_compile_pyc.py index 6ccd9487f..2e729ee4a 100644 --- a/tests/test_compile_pyc.py +++ b/tests/test_compile_pyc.py @@ -1,8 +1,9 @@ +import fnmatch import os import six -import fnmatch -from django.test import TestCase + from django.core.management import call_command +from django.test import TestCase from django_extensions.management.utils import get_project_root diff --git a/tests/test_dumpscript.py b/tests/test_dumpscript.py index 6f1e6f19a..6446df5d0 100644 --- a/tests/test_dumpscript.py +++ b/tests/test_dumpscript.py @@ -1,6 +1,6 @@ import ast -import sys import six +import sys from django.core.management import call_command from django.test import TestCase diff --git a/tests/test_encrypted_fields.py b/tests/test_encrypted_fields.py index da517ae67..a9e378033 100644 --- a/tests/test_encrypted_fields.py +++ b/tests/test_encrypted_fields.py @@ -10,6 +10,7 @@ from .testapp.models import Secret + # Only perform encrypted fields tests if keyczar is present. Resolves # http://github.com/django-extensions/django-extensions/issues/#issue/17 try: diff --git a/tests/test_management_command.py b/tests/test_management_command.py index 86340c54c..457a7eafa 100644 --- a/tests/test_management_command.py +++ b/tests/test_management_command.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- -import sys import logging +import sys + +from django.core.management import call_command +from django.test import TestCase + try: from cStringIO import StringIO # NOQA @@ -12,8 +16,6 @@ except ImportError: from django.utils import importlib # NOQA -from django.core.management import call_command -from django.test import TestCase class MockLoggingHandler(logging.Handler): diff --git a/tests/test_models.py b/tests/test_models.py index 044a5a1fc..859ffa6a5 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,6 +1,6 @@ from django.test import TestCase - from django_extensions.db.models import ActivatorModel + from .testapp.models import Post diff --git a/tests/test_shortuuid_field.py b/tests/test_shortuuid_field.py index f9ee577e9..66aefc218 100644 --- a/tests/test_shortuuid_field.py +++ b/tests/test_shortuuid_field.py @@ -2,7 +2,12 @@ from django.test import TestCase -from .testapp.models import ShortUUIDTestModel_field, ShortUUIDTestModel_pk, ShortUUIDTestAgregateModel, ShortUUIDTestManyToManyModel +from .testapp.models import ( + ShortUUIDTestAgregateModel, + ShortUUIDTestManyToManyModel, + ShortUUIDTestModel_field, + ShortUUIDTestModel_pk, +) class ShortUUIDFieldTest(TestCase): diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 70e23d70a..ff729529c 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -1,7 +1,6 @@ import six from django.test import TestCase - from django_extensions.templatetags.widont import widont, widont_html diff --git a/tests/test_utils.py b/tests/test_utils.py index 1e8d9eb11..bbf59233f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,7 +2,6 @@ import six from django.test import TestCase - from django_extensions.utils.text import truncate_letters diff --git a/tests/test_uuid_field.py b/tests/test_uuid_field.py index 2aa53103b..5eeab827b 100644 --- a/tests/test_uuid_field.py +++ b/tests/test_uuid_field.py @@ -1,13 +1,16 @@ import re -import uuid - import six +import uuid from django.test import TestCase - from django_extensions.db.fields import PostgreSQLUUIDField -from .testapp.models import UUIDTestModel_field, UUIDTestModel_pk, UUIDTestAgregateModel, UUIDTestManyToManyModel +from .testapp.models import ( + UUIDTestAgregateModel, + UUIDTestManyToManyModel, + UUIDTestModel_field, + UUIDTestModel_pk, +) class UUIDFieldTest(TestCase): From f49265279805d1ed94e39cdaa20912c89908e015 Mon Sep 17 00:00:00 2001 From: Benjamin ABEL Date: Tue, 17 Feb 2015 10:36:58 +0100 Subject: [PATCH 17/17] Converts test functions names to underscore --- tests/test_autoslug_fields.py | 18 +++++++++--------- tests/test_json_field.py | 6 +++--- tests/test_shortuuid_field.py | 8 ++++---- tests/test_uuid_field.py | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/test_autoslug_fields.py b/tests/test_autoslug_fields.py index f2c0686e6..8ca90a09c 100644 --- a/tests/test_autoslug_fields.py +++ b/tests/test_autoslug_fields.py @@ -22,12 +22,12 @@ def tearDown(self): SluggedTestModel.objects.all().delete() - def testAutoCreateSlug(self): + def test_auto_create_slug(self): m = SluggedTestModel(title='foo') m.save() self.assertEqual(m.slug, 'foo') - def testAutoCreateNextSlug(self): + def test_auto_create_next_slug(self): m = SluggedTestModel(title='foo') m.save() @@ -35,18 +35,18 @@ def testAutoCreateNextSlug(self): m.save() self.assertEqual(m.slug, 'foo-2') - def testAutoCreateSlugWithNumber(self): + def test_auto_create_slug_with_number(self): m = SluggedTestModel(title='foo 2012') m.save() self.assertEqual(m.slug, 'foo-2012') - def testAutoUpdateSlugWithNumber(self): + def test_auto_update_slug_with_number(self): m = SluggedTestModel(title='foo 2012') m.save() m.save() self.assertEqual(m.slug, 'foo-2012') - def testUpdateSlug(self): + def test_update_slug(self): m = SluggedTestModel(title='foo') m.save() self.assertEqual(m.slug, 'foo') @@ -67,7 +67,7 @@ def testUpdateSlug(self): self.assertEqual(m.title, 'bar') self.assertEqual(m.slug, 'foo-2012') - def testSimpleSlugSource(self): + def test_simple_slug_source(self): m = SluggedTestModel(title='-foo') m.save() self.assertEqual(m.slug, 'foo') @@ -79,7 +79,7 @@ def testSimpleSlugSource(self): n.save() self.assertEqual(n.slug, 'foo-2') - def testEmptySlugSource(self): + def test_empty_slug_source(self): # regression test m = SluggedTestModel(title='') @@ -93,7 +93,7 @@ def testEmptySlugSource(self): n.save() self.assertEqual(n.slug, '-3') - def testInheritanceCreatesNextSlug(self): + def test_inheritance_creates_next_slug(self): m = SluggedTestModel(title='foo') m.save() @@ -108,7 +108,7 @@ def testInheritanceCreatesNextSlug(self): @pytest.mark.skipif(django.VERSION < (1, 7), reason="Migrations are handled by south in Django <1.7") -class TestMigration(TestCase): +class MigrationTest(TestCase): def safe_exec(self, string, value=None): l = {} try: diff --git a/tests/test_json_field.py b/tests/test_json_field.py index 7ca3b77a9..ae93ce46e 100644 --- a/tests/test_json_field.py +++ b/tests/test_json_field.py @@ -4,15 +4,15 @@ class JsonFieldTest(TestCase): - def testCharFieldCreate(self): + def test_char_field_create(self): j = JSONFieldTestModel.objects.create(a=6, j_field=dict(foo='bar')) self.assertEqual(j.a, 6) - def testDefault(self): + def test_default(self): j = JSONFieldTestModel.objects.create(a=1) self.assertEqual(j.j_field, {}) - def testEmptyList(self): + def test_empty_list(self): j = JSONFieldTestModel.objects.create(a=6, j_field=[]) self.assertTrue(isinstance(j.j_field, list)) self.assertEqual(j.j_field, []) diff --git a/tests/test_shortuuid_field.py b/tests/test_shortuuid_field.py index 66aefc218..7b47ad3dc 100644 --- a/tests/test_shortuuid_field.py +++ b/tests/test_shortuuid_field.py @@ -11,22 +11,22 @@ class ShortUUIDFieldTest(TestCase): - def testUUIDFieldCreate(self): + def test_UUID_field_create(self): j = ShortUUIDTestModel_field.objects.create(a=6, uuid_field=six.u('vytxeTZskVKR7C7WgdSP3d')) self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3d')) - def testUUIDField_pkCreate(self): + def test_UUID_field_pk_create(self): j = ShortUUIDTestModel_pk.objects.create(uuid_field=six.u('vytxeTZskVKR7C7WgdSP3d')) self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3d')) self.assertEqual(j.pk, six.u('vytxeTZskVKR7C7WgdSP3d')) - def testUUIDField_pkAgregateCreate(self): + def test_UUID_field_pk_agregate_create(self): j = ShortUUIDTestAgregateModel.objects.create(a=6) self.assertEqual(j.a, 6) self.assertIsInstance(j.pk, six.string_types) self.assertTrue(len(j.pk) < 23) - def testUUIDFieldManyToManyCreate(self): + def test_UUID_field_manytomany_create(self): j = ShortUUIDTestManyToManyModel.objects.create(uuid_field=six.u('vytxeTZskVKR7C7WgdSP3e')) self.assertEqual(j.uuid_field, six.u('vytxeTZskVKR7C7WgdSP3e')) self.assertEqual(j.pk, six.u('vytxeTZskVKR7C7WgdSP3e')) diff --git a/tests/test_uuid_field.py b/tests/test_uuid_field.py index 5eeab827b..2f158d73e 100644 --- a/tests/test_uuid_field.py +++ b/tests/test_uuid_field.py @@ -14,22 +14,22 @@ class UUIDFieldTest(TestCase): - def testUUIDFieldCreate(self): + def test_UUID_field_create(self): j = UUIDTestModel_field.objects.create(a=6, uuid_field=six.u('550e8400-e29b-41d4-a716-446655440000')) self.assertEqual(j.uuid_field, six.u('550e8400-e29b-41d4-a716-446655440000')) - def testUUIDField_pkCreate(self): + def test_UUID_field_pk_create(self): j = UUIDTestModel_pk.objects.create(uuid_field=six.u('550e8400-e29b-41d4-a716-446655440000')) self.assertEqual(j.uuid_field, six.u('550e8400-e29b-41d4-a716-446655440000')) self.assertEqual(j.pk, six.u('550e8400-e29b-41d4-a716-446655440000')) - def testUUIDField_pkAgregateCreate(self): + def test_UUID_field_pk_agregate_create(self): j = UUIDTestAgregateModel.objects.create(a=6, uuid_field=six.u('550e8400-e29b-41d4-a716-446655440001')) self.assertEqual(j.a, 6) self.assertIsInstance(j.pk, six.string_types) self.assertEqual(len(j.pk), 36) - def testUUIDFieldManyToManyCreate(self): + def test_UUID_field_manytomany_create(self): j = UUIDTestManyToManyModel.objects.create(uuid_field=six.u('550e8400-e29b-41d4-a716-446655440010')) self.assertEqual(j.uuid_field, six.u('550e8400-e29b-41d4-a716-446655440010')) self.assertEqual(j.pk, six.u('550e8400-e29b-41d4-a716-446655440010'))