diff options
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/tests.py | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 5aafdb2844..cc6639b032 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -251,24 +251,29 @@ class ForeignKeyTests(test.TestCase): def test_abstract_model_app_relative_foreign_key(self): test_apps = Apps(['model_fields', 'model_fields.tests']) - class Refered(models.Model): - class Meta: - apps = test_apps - app_label = 'model_fields' - class AbstractReferent(models.Model): reference = models.ForeignKey('Refered', on_delete=models.CASCADE) class Meta: + apps = test_apps app_label = 'model_fields' abstract = True - class ConcreteReferent(AbstractReferent): - class Meta: - apps = test_apps - app_label = 'tests' + def assert_app_model_resolved(label): + class Refered(models.Model): + class Meta: + apps = test_apps + app_label = label + + class ConcreteReferent(AbstractReferent): + class Meta: + apps = test_apps + app_label = label + + self.assertEqual(ConcreteReferent._meta.get_field('reference').related_model, Refered) - self.assertEqual(ConcreteReferent._meta.get_field('reference').related_model, Refered) + assert_app_model_resolved('model_fields') + assert_app_model_resolved('tests') class ManyToManyFieldTests(test.SimpleTestCase): @@ -295,33 +300,38 @@ class ManyToManyFieldTests(test.SimpleTestCase): def test_abstract_model_app_relative_foreign_key(self): test_apps = Apps(['model_fields', 'model_fields.tests']) - class Refered(models.Model): + class AbstractReferent(models.Model): + reference = models.ManyToManyField('Refered', through='Through') + class Meta: apps = test_apps app_label = 'model_fields' + abstract = True - class Through(models.Model): - refered = models.ForeignKey('Refered', on_delete=models.CASCADE) - referent = models.ForeignKey('tests.ConcreteReferent', on_delete=models.CASCADE) + def assert_app_model_resolved(label): + class Refered(models.Model): + class Meta: + apps = test_apps + app_label = label - class Meta: - apps = test_apps - app_label = 'model_fields' + class Through(models.Model): + refered = models.ForeignKey('Refered', on_delete=models.CASCADE) + referent = models.ForeignKey('ConcreteReferent', on_delete=models.CASCADE) - class AbstractReferent(models.Model): - reference = models.ManyToManyField('Refered', through='Through') + class Meta: + apps = test_apps + app_label = label - class Meta: - app_label = 'model_fields' - abstract = True + class ConcreteReferent(AbstractReferent): + class Meta: + apps = test_apps + app_label = label - class ConcreteReferent(AbstractReferent): - class Meta: - apps = test_apps - app_label = 'tests' + self.assertEqual(ConcreteReferent._meta.get_field('reference').related_model, Refered) + self.assertEqual(ConcreteReferent.reference.through, Through) - self.assertEqual(ConcreteReferent._meta.get_field('reference').related_model, Refered) - self.assertEqual(ConcreteReferent.reference.through, Through) + assert_app_model_resolved('model_fields') + assert_app_model_resolved('tests') class TextFieldTests(test.TestCase): |
