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:
37
tests/modeltests/invalid_models/tests.py
Normal file
37
tests/modeltests/invalid_models/tests.py
Normal 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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user