summaryrefslogtreecommitdiff
path: root/tests/model_regress
diff options
context:
space:
mode:
authorMatt Westcott <matt@west.co.tt>2019-03-14 18:23:50 +0100
committerTim Graham <timograham@gmail.com>2019-03-14 21:05:23 -0400
commit58ad030d05fa50cfed327368ab61defca3303e02 (patch)
tree4f378393844f8d2d41909fac3a1676f1040e2bff /tests/model_regress
parentf976ab1b117574db78d884c94e549a6b8e4c9f9b (diff)
downloaddjango-58ad030d05fa50cfed327368ab61defca3303e02.tar.gz
Fixed #30254 -- Allowed model metaclasses to access the attribute dict in __init__().
Regression in a68ea231012434b522ce45c513d84add516afa60.
Diffstat (limited to 'tests/model_regress')
-rw-r--r--tests/model_regress/tests.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/model_regress/tests.py b/tests/model_regress/tests.py
index e3977ee316..28eed87008 100644
--- a/tests/model_regress/tests.py
+++ b/tests/model_regress/tests.py
@@ -2,9 +2,10 @@ import datetime
from operator import attrgetter
from django.core.exceptions import ValidationError
-from django.db import router
+from django.db import models, router
from django.db.models.sql import InsertQuery
from django.test import TestCase, skipUnlessDBFeature
+from django.test.utils import isolate_apps
from django.utils.timezone import get_fixed_timezone
from .models import (
@@ -217,6 +218,23 @@ class ModelTests(TestCase):
m3 = Model3.objects.get(model2=1000)
m3.model2
+ @isolate_apps('model_regress')
+ def test_metaclass_can_access_attribute_dict(self):
+ """
+ Model metaclasses have access to the class attribute dict in
+ __init__() (#30254).
+ """
+ class HorseBase(models.base.ModelBase):
+ def __init__(cls, name, bases, attrs):
+ super(HorseBase, cls).__init__(name, bases, attrs)
+ cls.horns = (1 if 'magic' in attrs else 0)
+
+ class Horse(models.Model, metaclass=HorseBase):
+ name = models.CharField(max_length=255)
+ magic = True
+
+ self.assertEqual(Horse.horns, 1)
+
class ModelValidationTest(TestCase):
def test_pk_validation(self):