summaryrefslogtreecommitdiff
path: root/tests/proxy_models/tests.py
diff options
context:
space:
mode:
authorCraig de Stigter <craig.destigter@koordinates.com>2014-05-29 10:26:57 +1200
committerTim Graham <timograham@gmail.com>2014-06-02 09:34:31 -0400
commit724e6008722acb9b69ea3d1749ac8c1125837d03 (patch)
tree6b19665edc93f0174344ca783fd8d229dfb31ce7 /tests/proxy_models/tests.py
parent160fd6c7c1699e0be89d9a48f4cc9386bab0e9de (diff)
[1.7.x] Fixed #22690 -- Added a check for proxy models containing fields.
Removed the FieldError raised by ModelBase.__new__ in this case. Backport of ce993efda8 from master
Diffstat (limited to 'tests/proxy_models/tests.py')
-rw-r--r--tests/proxy_models/tests.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
index 0f2b5349be..dc7d75a5ef 100644
--- a/tests/proxy_models/tests.py
+++ b/tests/proxy_models/tests.py
@@ -4,7 +4,7 @@ from django.apps import apps
from django.contrib import admin
from django.contrib.contenttypes.models import ContentType
from django.core import management
-from django.core.exceptions import FieldError
+from django.core import checks
from django.db import models, DEFAULT_DB_ALIAS
from django.db.models import signals
from django.test import TestCase, override_settings
@@ -143,13 +143,25 @@ class ProxyModelTests(TestCase):
self.assertRaises(TypeError, build_no_base_classes)
def test_new_fields(self):
- def build_new_fields():
- class NoNewFields(Person):
- newfield = models.BooleanField()
+ class NoNewFields(Person):
+ newfield = models.BooleanField()
- class Meta:
- proxy = True
- self.assertRaises(FieldError, build_new_fields)
+ class Meta:
+ proxy = True
+ # don't register this model in the app_cache for the current app,
+ # otherwise the check fails when other tests are being run.
+ app_label = 'no_such_app'
+
+ errors = NoNewFields.check()
+ expected = [
+ checks.Error(
+ "Proxy model 'NoNewFields' contains model fields.",
+ hint=None,
+ obj=None,
+ id='models.E017',
+ )
+ ]
+ self.assertEqual(errors, expected)
@override_settings(TEST_SWAPPABLE_MODEL='proxy_models.AlternateModel')
def test_swappable(self):