Ticket #18011: tests_regressiontests_fixtures_regress_tests.diff

File tests_regressiontests_fixtures_regress_tests.diff, 1.7 KB (added by hoffmaje, 13 years ago)
  • tests/regressiontests/fixtures_regress/tests.py

     
    1212from django.core import management
    1313from django.core.management.base import CommandError
    1414from django.core.management.commands.dumpdata import sort_dependencies
     15from django.db import IntegrityError
    1516from django.db import transaction
    1617from django.db.models import signals
    1718from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
     
    375376        self.assertEqual(Book.objects.all()[0].id, 1)
    376377        self.assertEqual(Person.objects.all()[0].id, 4)
    377378
    378     def test_loaddata_raises_error_when_fixture_has_invalid_foreign_key(self):
     379    def test_loaddata_raises_IntegrityError_when_fixture_has_invalid_foreign_key(self):
    379380        """
    380381        Regression for #3615 - Ensure data with nonexistent child key references raises error
    381382        """
    382         stderr = StringIO()
    383         management.call_command(
    384             'loaddata',
    385             'forward_ref_bad_data.json',
    386             verbosity=0,
    387             commit=False,
    388             stderr=stderr,
    389         )
    390         self.assertTrue(
    391             stderr.getvalue().startswith('Problem installing fixture')
    392         )
     383        with self.assertRaisesRegexp(IntegrityError, '[.]*has an invalid foreign key[.]*'):
     384            management.call_command(
     385                'loaddata',
     386                'forward_ref_bad_data.json',
     387                verbosity=0,
     388                commit=False,
     389            )
    393390
    394391    _cur_dir = os.path.dirname(os.path.abspath(__file__))
    395392
Back to Top