1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #16681 -- Refactored the invalid_models unit test so that it can be invoked manually. Thanks to Anthony Briggs for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2011-08-23 04:25:07 +00:00
parent 966bbd4d56
commit 1e72b1c5c1
6 changed files with 372 additions and 390 deletions

View File

@@ -0,0 +1,37 @@
import sys
from django.utils import unittest
class InvalidModelTestCase(unittest.TestCase):
"""Import an appliation with invalid models and test the exceptions."""
def test_invalid_models(self):
from django.core.management.validation import get_validation_errors
from django.db.models.loading import load_app
from cStringIO import StringIO
try:
module = load_app("modeltests.invalid_models.invalid_models")
except Exception, e:
self.fail('Unable to load invalid model module')
# Make sure sys.stdout is not a tty so that we get errors without
# coloring attached (makes matching the results easier). We restore
# sys.stderr afterwards.
orig_stdout = sys.stdout
s = StringIO()
sys.stdout = s
count = get_validation_errors(s, module)
sys.stdout = orig_stdout
s.seek(0)
error_log = s.read()
actual = error_log.split('\n')
expected = module.model_errors.split('\n')
unexpected = [err for err in actual if err not in expected]
missing = [err for err in expected if err not in actual]
self.assertFalse(unexpected, "Unexpected Errors: " + '\n'.join(unexpected))
self.assertFalse(missing, "Missing Errors: " + '\n'.join(missing))