diff options
| author | Simon Charette <charette.s@gmail.com> | 2015-11-17 00:39:28 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-01-06 20:00:07 -0500 |
| commit | a08fda2111d811aa53f11218fa03f3300dfff4cb (patch) | |
| tree | 0263cf99adf17c5123b3a53c686f637d5b40eda4 /tests/invalid_models_tests | |
| parent | 3096f4b0829a005c67a14cc4bb6d345aa32672a1 (diff) | |
Fixed #25746 -- Isolated inlined test models registration.
Thanks to Tim for the review.
Diffstat (limited to 'tests/invalid_models_tests')
| -rw-r--r-- | tests/invalid_models_tests/base.py | 18 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_backend_specific.py | 8 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_custom_fields.py | 7 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_deprecated_fields.py | 7 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_models.py | 20 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 42 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_relative_fields.py | 70 |
7 files changed, 79 insertions, 93 deletions
diff --git a/tests/invalid_models_tests/base.py b/tests/invalid_models_tests/base.py deleted file mode 100644 index 9459b313d6..0000000000 --- a/tests/invalid_models_tests/base.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding: utf-8 -*- -from __future__ import unicode_literals - -from django.apps import apps -from django.test import SimpleTestCase - - -class IsolatedModelsTestCase(SimpleTestCase): - - def setUp(self): - # The unmanaged models need to be removed after the test in order to - # prevent bad interactions with the flush operation in other tests. - self._old_models = apps.app_configs['invalid_models_tests'].models.copy() - - def tearDown(self): - apps.app_configs['invalid_models_tests'].models = self._old_models - apps.all_models['invalid_models_tests'] = self._old_models - apps.clear_cache() diff --git a/tests/invalid_models_tests/test_backend_specific.py b/tests/invalid_models_tests/test_backend_specific.py index 5be1d6f691..fd73853a03 100644 --- a/tests/invalid_models_tests/test_backend_specific.py +++ b/tests/invalid_models_tests/test_backend_specific.py @@ -3,9 +3,8 @@ from __future__ import unicode_literals from django.core.checks import Error from django.db import connections, models -from django.test import mock - -from .base import IsolatedModelsTestCase +from django.test import SimpleTestCase, mock +from django.test.utils import isolate_apps def dummy_allow_migrate(db, app_label, **hints): @@ -14,7 +13,8 @@ def dummy_allow_migrate(db, app_label, **hints): return db == 'default' -class BackendSpecificChecksTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class BackendSpecificChecksTests(SimpleTestCase): @mock.patch('django.db.models.fields.router.allow_migrate', new=dummy_allow_migrate) def test_check_field(self): diff --git a/tests/invalid_models_tests/test_custom_fields.py b/tests/invalid_models_tests/test_custom_fields.py index 03e65b599b..4c379e70f5 100644 --- a/tests/invalid_models_tests/test_custom_fields.py +++ b/tests/invalid_models_tests/test_custom_fields.py @@ -1,9 +1,10 @@ from django.db import models +from django.test import SimpleTestCase +from django.test.utils import isolate_apps -from .base import IsolatedModelsTestCase - -class CustomFieldTest(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class CustomFieldTest(SimpleTestCase): def test_none_column(self): class NoColumnField(models.AutoField): diff --git a/tests/invalid_models_tests/test_deprecated_fields.py b/tests/invalid_models_tests/test_deprecated_fields.py index fa646515b3..7826596895 100644 --- a/tests/invalid_models_tests/test_deprecated_fields.py +++ b/tests/invalid_models_tests/test_deprecated_fields.py @@ -1,10 +1,11 @@ from django.core import checks from django.db import models +from django.test import SimpleTestCase +from django.test.utils import isolate_apps -from .base import IsolatedModelsTestCase - -class DeprecatedFieldsTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class DeprecatedFieldsTests(SimpleTestCase): def test_IPAddressField_deprecated(self): class IPAddressModel(models.Model): ip = models.IPAddressField() diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index 8e1f515b13..5764764341 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -6,9 +6,8 @@ import unittest from django.conf import settings from django.core.checks import Error from django.db import connections, models -from django.test.utils import override_settings - -from .base import IsolatedModelsTestCase +from django.test import SimpleTestCase +from django.test.utils import isolate_apps, override_settings def get_max_column_name_length(): @@ -31,7 +30,8 @@ def get_max_column_name_length(): return (allowed_len, db_alias) -class IndexTogetherTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class IndexTogetherTests(SimpleTestCase): def test_non_iterable(self): class Model(models.Model): @@ -146,7 +146,8 @@ class IndexTogetherTests(IsolatedModelsTestCase): # unique_together tests are very similar to index_together tests. -class UniqueTogetherTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class UniqueTogetherTests(SimpleTestCase): def test_non_iterable(self): class Model(models.Model): @@ -251,7 +252,8 @@ class UniqueTogetherTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class FieldNamesTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class FieldNamesTests(SimpleTestCase): def test_ending_with_underscore(self): class Model(models.Model): @@ -434,7 +436,8 @@ class FieldNamesTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class ShadowingFieldsTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class ShadowingFieldsTests(SimpleTestCase): def test_field_name_clash_with_child_accessor(self): class Parent(models.Model): @@ -558,7 +561,8 @@ class ShadowingFieldsTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class OtherModelTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class OtherModelTests(SimpleTestCase): def test_unique_primary_key(self): invalid_id = models.IntegerField(primary_key=False) diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index 033970aae4..2a7e912f8c 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -5,14 +5,13 @@ import unittest from django.core.checks import Error, Warning as DjangoWarning from django.db import connection, models -from django.test import TestCase -from django.test.utils import override_settings +from django.test import SimpleTestCase, TestCase +from django.test.utils import isolate_apps, override_settings from django.utils.timezone import now -from .base import IsolatedModelsTestCase - -class AutoFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class AutoFieldTests(SimpleTestCase): def test_valid_case(self): class Model(models.Model): @@ -46,7 +45,8 @@ class AutoFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class BooleanFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class BooleanFieldTests(SimpleTestCase): def test_nullable_boolean_field(self): class Model(models.Model): @@ -65,7 +65,8 @@ class BooleanFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class CharFieldTests(IsolatedModelsTestCase, TestCase): +@isolate_apps('invalid_models_tests') +class CharFieldTests(TestCase): def test_valid_field(self): class Model(models.Model): @@ -216,7 +217,8 @@ class CharFieldTests(IsolatedModelsTestCase, TestCase): self.assertEqual(errors, expected) -class DateFieldTests(IsolatedModelsTestCase, TestCase): +@isolate_apps('invalid_models_tests') +class DateFieldTests(TestCase): def test_auto_now_and_auto_now_add_raise_error(self): class Model(models.Model): @@ -282,7 +284,8 @@ class DateFieldTests(IsolatedModelsTestCase, TestCase): self.test_fix_default_value() -class DateTimeFieldTests(IsolatedModelsTestCase, TestCase): +@isolate_apps('invalid_models_tests') +class DateTimeFieldTests(TestCase): def test_fix_default_value(self): class Model(models.Model): @@ -326,7 +329,8 @@ class DateTimeFieldTests(IsolatedModelsTestCase, TestCase): self.test_fix_default_value() -class DecimalFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class DecimalFieldTests(SimpleTestCase): def test_required_attributes(self): class Model(models.Model): @@ -420,7 +424,8 @@ class DecimalFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class FileFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class FileFieldTests(SimpleTestCase): def test_valid_case(self): class Model(models.Model): @@ -464,7 +469,8 @@ class FileFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class FilePathFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class FilePathFieldTests(SimpleTestCase): def test_forbidden_files_and_folders(self): class Model(models.Model): @@ -483,7 +489,8 @@ class FilePathFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class GenericIPAddressFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class GenericIPAddressFieldTests(SimpleTestCase): def test_non_nullable_blank(self): class Model(models.Model): @@ -503,7 +510,8 @@ class GenericIPAddressFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class ImageFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class ImageFieldTests(SimpleTestCase): def test_pillow_installed(self): try: @@ -530,7 +538,8 @@ class ImageFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class IntegerFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class IntegerFieldTests(SimpleTestCase): def test_max_length_warning(self): class Model(models.Model): @@ -549,7 +558,8 @@ class IntegerFieldTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class TimeFieldTests(IsolatedModelsTestCase, TestCase): +@isolate_apps('invalid_models_tests') +class TimeFieldTests(TestCase): def test_fix_default_value(self): class Model(models.Model): diff --git a/tests/invalid_models_tests/test_relative_fields.py b/tests/invalid_models_tests/test_relative_fields.py index f157f2beb8..c2895f681f 100644 --- a/tests/invalid_models_tests/test_relative_fields.py +++ b/tests/invalid_models_tests/test_relative_fields.py @@ -3,21 +3,19 @@ from __future__ import unicode_literals import warnings -from django.apps.registry import Apps from django.core.checks import Error, Warning as DjangoWarning from django.db import models from django.db.models.fields.related import ForeignObject from django.test import ignore_warnings -from django.test.testcases import skipIfDBFeature -from django.test.utils import override_settings +from django.test.testcases import SimpleTestCase, skipIfDBFeature +from django.test.utils import isolate_apps, override_settings from django.utils import six from django.utils.deprecation import RemovedInDjango20Warning from django.utils.version import get_docs_version -from .base import IsolatedModelsTestCase - -class RelativeFieldTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class RelativeFieldTests(SimpleTestCase): def test_valid_foreign_key_without_accessor(self): class Target(models.Model): @@ -133,23 +131,18 @@ class RelativeFieldTests(IsolatedModelsTestCase): ] self.assertEqual(errors, expected) - def test_foreign_key_to_isolated_apps_model(self): + @isolate_apps('invalid_models_tests') + def test_foreign_key_to_isolate_apps_model(self): """ #25723 - Referenced model registration lookup should be run against the field's model registry. """ - test_apps = Apps(['invalid_models_tests']) - class OtherModel(models.Model): - class Meta: - apps = test_apps + pass class Model(models.Model): foreign_key = models.ForeignKey('OtherModel', models.CASCADE) - class Meta: - apps = test_apps - field = Model._meta.get_field('foreign_key') self.assertEqual(field.check(from_model=Model), []) @@ -170,23 +163,18 @@ class RelativeFieldTests(IsolatedModelsTestCase): ] self.assertEqual(errors, expected) - def test_many_to_many_to_isolated_apps_model(self): + @isolate_apps('invalid_models_tests') + def test_many_to_many_to_isolate_apps_model(self): """ #25723 - Referenced model registration lookup should be run against the field's model registry. """ - test_apps = Apps(['invalid_models_tests']) - class OtherModel(models.Model): - class Meta: - apps = test_apps + pass class Model(models.Model): m2m = models.ManyToManyField('OtherModel') - class Meta: - apps = test_apps - field = Model._meta.get_field('m2m') self.assertEqual(field.check(from_model=Model), []) @@ -329,30 +317,22 @@ class RelativeFieldTests(IsolatedModelsTestCase): ] self.assertEqual(errors, expected) - def test_many_to_many_through_isolated_apps_model(self): + @isolate_apps('invalid_models_tests') + def test_many_to_many_through_isolate_apps_model(self): """ #25723 - Through model registration lookup should be run against the field's model registry. """ - test_apps = Apps(['invalid_models_tests']) - class GroupMember(models.Model): person = models.ForeignKey('Person', models.CASCADE) group = models.ForeignKey('Group', models.CASCADE) - class Meta: - apps = test_apps - class Person(models.Model): - class Meta: - apps = test_apps + pass class Group(models.Model): members = models.ManyToManyField('Person', through='GroupMember') - class Meta: - apps = test_apps - field = Group._meta.get_field('members') self.assertEqual(field.check(from_model=Group), []) @@ -790,7 +770,8 @@ class RelativeFieldTests(IsolatedModelsTestCase): self.assertFalse(errors) -class AccessorClashTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class AccessorClashTests(SimpleTestCase): def test_fk_to_integer(self): self._test_accessor_clash( @@ -902,7 +883,8 @@ class AccessorClashTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class ReverseQueryNameClashTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class ReverseQueryNameClashTests(SimpleTestCase): def test_fk_to_integer(self): self._test_reverse_query_name_clash( @@ -958,7 +940,8 @@ class ReverseQueryNameClashTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class ExplicitRelatedNameClashTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class ExplicitRelatedNameClashTests(SimpleTestCase): def test_fk_to_integer(self): self._test_explicit_related_name_clash( @@ -1022,7 +1005,8 @@ class ExplicitRelatedNameClashTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class ExplicitRelatedQueryNameClashTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class ExplicitRelatedQueryNameClashTests(SimpleTestCase): def test_fk_to_integer(self): self._test_explicit_related_query_name_clash( @@ -1086,7 +1070,8 @@ class ExplicitRelatedQueryNameClashTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class SelfReferentialM2MClashTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class SelfReferentialM2MClashTests(SimpleTestCase): def test_clash_between_accessors(self): class Model(models.Model): @@ -1181,7 +1166,8 @@ class SelfReferentialM2MClashTests(IsolatedModelsTestCase): self.assertEqual(errors, []) -class SelfReferentialFKClashTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class SelfReferentialFKClashTests(SimpleTestCase): def test_accessor_clash(self): class Model(models.Model): @@ -1244,7 +1230,8 @@ class SelfReferentialFKClashTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class ComplexClashTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class ComplexClashTests(SimpleTestCase): # New tests should not be included here, because this is a single, # self-contained sanity check, not a test of everything. @@ -1358,7 +1345,8 @@ class ComplexClashTests(IsolatedModelsTestCase): self.assertEqual(errors, expected) -class M2mThroughFieldsTests(IsolatedModelsTestCase): +@isolate_apps('invalid_models_tests') +class M2mThroughFieldsTests(SimpleTestCase): def test_m2m_field_argument_validation(self): """ Tests that ManyToManyField accepts the ``through_fields`` kwarg |
