diff options
author | Craig de Stigter <craig.destigter@koordinates.com> | 2014-05-29 10:26:57 +1200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2014-06-02 09:32:38 -0400 |
commit | ce993efda876b19569267badb6af5fd0e80cdee3 (patch) | |
tree | f5c4c8be1dc0ff7dd02ed52c4b856423c4bb00d8 /tests/proxy_models | |
parent | 5046c110cfbf5e867fec47c8c68677a76c9e1b68 (diff) | |
download | django-ce993efda876b19569267badb6af5fd0e80cdee3.tar.gz |
Fixed #22690 -- Added a check for proxy models containing fields.
Removed the FieldError raised by ModelBase.__new__ in this case.
Diffstat (limited to 'tests/proxy_models')
-rw-r--r-- | tests/proxy_models/tests.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py index 0052ff4630..7cb5bdf441 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 Meta: - proxy = True - self.assertRaises(FieldError, build_new_fields) + class NoNewFields(Person): + newfield = models.BooleanField() + + 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): |