summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-08-20 14:07:02 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-08-20 14:07:02 +0000
commit3fc9d7e3907f0f8506601ff34add9215fdc69b45 (patch)
treec79d19ff4b754ffb29abde5ff01cee9ed9fb475e /tests
parent1d291ff733587b96299ec2874fb2edb90fbfc11d (diff)
[1.2.X] Fixed #14068 -- Corrected error handling in loaddata when an allow_syncdb method is defined on the router. Thanks to Xavier Ordoquy for the report.
Backport of r13612 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13613 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/multiple_database/fixtures/pets.json18
-rw-r--r--tests/regressiontests/multiple_database/tests.py28
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/regressiontests/multiple_database/fixtures/pets.json b/tests/regressiontests/multiple_database/fixtures/pets.json
new file mode 100644
index 0000000000..89756a3e5b
--- /dev/null
+++ b/tests/regressiontests/multiple_database/fixtures/pets.json
@@ -0,0 +1,18 @@
+[
+ {
+ "pk": 1,
+ "model": "multiple_database.pet",
+ "fields": {
+ "name": "Mr Bigglesworth",
+ "owner": 1
+ }
+ },
+ {
+ "pk": 2,
+ "model": "multiple_database.pet",
+ "fields": {
+ "name": "Spot",
+ "owner": 2
+ }
+ }
+] \ No newline at end of file
diff --git a/tests/regressiontests/multiple_database/tests.py b/tests/regressiontests/multiple_database/tests.py
index 6675fdcc6c..2547e1eae2 100644
--- a/tests/regressiontests/multiple_database/tests.py
+++ b/tests/regressiontests/multiple_database/tests.py
@@ -1569,11 +1569,31 @@ class UserProfileTestCase(TestCase):
self.assertEquals(alice.get_profile().flavor, 'chocolate')
self.assertEquals(bob.get_profile().flavor, 'crunchy frog')
+class AntiPetRouter(object):
+ # A router that only expresses an opinion on syncdb,
+ # passing pets to the 'other' database
+
+ def allow_syncdb(self, db, model):
+ "Make sure the auth app only appears on the 'other' db"
+ if db == 'other':
+ return model._meta.object_name == 'Pet'
+ else:
+ return model._meta.object_name != 'Pet'
+ return None
class FixtureTestCase(TestCase):
multi_db = True
fixtures = ['multidb-common', 'multidb']
+ def setUp(self):
+ # Install the anti-pet router
+ self.old_routers = router.routers
+ router.routers = [AntiPetRouter()]
+
+ def tearDown(self):
+ # Restore the 'other' database as an independent database
+ router.routers = self.old_routers
+
def test_fixture_loading(self):
"Multi-db fixtures are loaded correctly"
# Check that "Pro Django" exists on the default database, but not on other database
@@ -1611,6 +1631,14 @@ class FixtureTestCase(TestCase):
except Book.DoesNotExist:
self.fail('"The Definitive Guide to Django" should exist on both databases')
+ def test_pseudo_empty_fixtures(self):
+ "A fixture can contain entries, but lead to nothing in the database; this shouldn't raise an error (ref #14068)"
+ new_io = StringIO()
+ management.call_command('loaddata', 'pets', stdout=new_io, stderr=new_io)
+ command_output = new_io.getvalue().strip()
+ # No objects will actually be loaded
+ self.assertTrue("Installed 0 object(s) (of 2) from 1 fixture(s)" in command_output)
+
class PickleQuerySetTestCase(TestCase):
multi_db = True