              '<Article: Who needs to use compressed data?>',
              '<Article: Python program becomes self aware>'
          ])
  
      def test_loading_using(self):
          # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
          management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default', commit=False)
          management.call_command('loaddata', 'db_fixture_2', verbosity=0, using='default', commit=False)
          self.assertQuerysetEqual(Article.objects.all(), [
              '<Article: Who needs more than one database?>',
 
</s> remove                                             obj.save(using=using)
 </s> add                                             try:
                                                obj.save(using=using)
                                            except (DatabaseError, IntegrityError), e:
                                                msg = "Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % {
                                                        'app_label': obj.object._meta.app_label,
                                                        'object_name': obj.object._meta.object_name,
                                                        'pk': obj.object.pk,
                                                        'error_msg': e
                                                    }
                                                raise e.__class__, e.__class__(msg), sys.exc_info()[2] </s> remove from django.db import connections, router, transaction, DEFAULT_DB_ALIAS
 </s> add from django.db import (connections, router, transaction, DEFAULT_DB_ALIAS,
      IntegrityError, DatabaseError)
    def test_loaddata_error_message(self):
        """
        Verifies that loading a fixture which contains an invalid object
        outputs an error message which contains the pk of the object
        that triggered the error.
        """
        new_io = StringIO.StringIO()
        management.call_command('loaddata', 'invalid.json', verbosity=0, stderr=new_io, commit=False)
        output = new_io.getvalue().strip().split('\n')
        self.assertRegexpMatches(output[-1], "IntegrityError: Could not load fixtures.Article\(pk=1\): .*$")

              '<Article: Who needs to use compressed data?>',
              '<Article: Python program becomes self aware>'
          ])
  
    def test_loaddata_error_message(self):
        """
        Verifies that loading a fixture which contains an invalid object
        outputs an error message which contains the pk of the object
        that triggered the error.
        """
        new_io = StringIO.StringIO()
        management.call_command('loaddata', 'invalid.json', verbosity=0, stderr=new_io, commit=False)
        output = new_io.getvalue().strip().split('\n')
        self.assertRegexpMatches(output[-1], "IntegrityError: Could not load fixtures.Article\(pk=1\): .*$")

      def test_loading_using(self):
          # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
          management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default', commit=False)
          management.call_command('loaddata', 'db_fixture_2', verbosity=0, using='default', commit=False)
          self.assertQuerysetEqual(Article.objects.all(), [
              '<Article: Who needs more than one database?>',
keep keep keep add keep keep keep keep keep keep
 Fixed #16026 -- loaddata now identifies which object triggered an error.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@16873 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
tests/modeltests/fixtures/tests.py