diff options
author | k <xddd@xddd.home> | 2017-10-13 21:29:00 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2017-10-13 21:29:12 -0400 |
commit | 399a8db33b14a1f707912ac48a185fb0a1204913 (patch) | |
tree | 7a2ddb2198c918a4d61d7c4b05ffe61b739bfa02 /tests/model_inheritance | |
parent | 9dd405973cc39c00e50e28869808fb0797fea2b4 (diff) | |
download | django-399a8db33b14a1f707912ac48a185fb0a1204913.tar.gz |
Fixed #28695 -- Allowed models to use __init_subclass__().
Diffstat (limited to 'tests/model_inheritance')
-rw-r--r-- | tests/model_inheritance/tests.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index e1eca65742..88f1e623c4 100644 --- a/tests/model_inheritance/tests.py +++ b/tests/model_inheritance/tests.py @@ -1,9 +1,11 @@ +import unittest from operator import attrgetter from django.core.exceptions import FieldError, ValidationError from django.db import connection, models from django.test import SimpleTestCase, TestCase from django.test.utils import CaptureQueriesContext, isolate_apps +from django.utils.version import PY36 from .models import ( Base, Chef, CommonInfo, GrandChild, GrandParent, ItalianRestaurant, @@ -156,6 +158,23 @@ class ModelInheritanceTests(TestCase): self.assertIs(C._meta.parents[A], C._meta.get_field('a')) + @unittest.skipUnless(PY36, 'init_subclass is new in Python 3.6') + @isolate_apps('model_inheritance') + def test_init_subclass(self): + saved_kwargs = {} + + class A: + def __init_subclass__(cls, **kwargs): + super().__init_subclass__() + saved_kwargs.update(kwargs) + + kwargs = {'x': 1, 'y': 2, 'z': 3} + + class B(A, models.Model, **kwargs): + pass + + self.assertEqual(saved_kwargs, kwargs) + class ModelInheritanceDataTests(TestCase): @classmethod |