Commit 38530700 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

[1.3.X] Fixed #16681 -- Refactored the invalid_models unit test so that it can...

[1.3.X] Fixed #16681 -- Refactored the invalid_models unit test so that 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
parent 3e7d79b6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ answer newbie questions, and generally made Django that much better:
    Sean Brant
    Andrew Brehaut <http://brehaut.net/blog>
    David Brenneman <http://davidbrenneman.com>
    Anthony Briggs <anthony.briggs@gmail.com>
    brut.alll@gmail.com
    bthomas
    btoll@bestweb.net
+0 −0

Empty file added.

+330 −0

File added.

Preview size limit exceeded, changes collapsed.

+0 −330

File changed.

Preview size limit exceeded, changes collapsed.

+37 −0
Original line number Diff line number Diff line
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))

Loading