From ce993efda876b19569267badb6af5fd0e80cdee3 Mon Sep 17 00:00:00 2001 From: Craig de Stigter Date: Thu, 29 May 2014 10:26:57 +1200 Subject: Fixed #22690 -- Added a check for proxy models containing fields. Removed the FieldError raised by ModelBase.__new__ in this case. --- tests/proxy_models/tests.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'tests/proxy_models') 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): -- cgit v1.3