Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.3.X] Fixed #16681 -- Refactored the invalid_models unit test so th…
…at it can be invoked manually. Thanks to Anthony Briggs for the report and patch. Backport of r16661 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16674 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
1 parent
3e7d79b
commit 3853070
Showing
6 changed files
with
372 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
330 changes: 330 additions & 0 deletions
330
tests/modeltests/invalid_models/invalid_models/models.py
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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)) | |||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters