dumpdata honors allow_migrate restrictions on the router
(self)
| 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 | |
| 2029 | class AntiPetRouter: |
nothing calls this directly
no test coverage detected