MCPcopy
hub / github.com/django/django / test_dumpdata

Method test_dumpdata

tests/multiple_database/tests.py:2006–2026  ·  view source on GitHub ↗

dumpdata honors allow_migrate restrictions on the router

(self)

Source from the content-addressed store, hash-verified

2004 self.assertEqual(User.objects.using("other").count(), 1)
2005
2006 def test_dumpdata(self):
2007 "dumpdata honors allow_migrate restrictions on the router"
2008 User.objects.create_user("alice", "alice@example.com")
2009 User.objects.db_manager("default").create_user("bob", "bob@example.com")
2010
2011 # dumping the default database doesn't try to include auth because
2012 # allow_migrate prohibits auth on default
2013 new_io = StringIO()
2014 management.call_command(
2015 "dumpdata", "auth", format="json", database="default", stdout=new_io
2016 )
2017 command_output = new_io.getvalue().strip()
2018 self.assertEqual(command_output, "[]")
2019
2020 # dumping the other database does include auth
2021 new_io = StringIO()
2022 management.call_command(
2023 "dumpdata", "auth", format="json", database="other", stdout=new_io
2024 )
2025 command_output = new_io.getvalue().strip()
2026 self.assertIn('"email": "alice@example.com"', command_output)
2027
2028
2029class AntiPetRouter:

Callers

nothing calls this directly

Calls 3

db_managerMethod · 0.80
create_userMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected