The methods on the auth manager obey database hints
(self)
| 1974 | databases = {"default", "other"} |
| 1975 | |
| 1976 | def test_auth_manager(self): |
| 1977 | "The methods on the auth manager obey database hints" |
| 1978 | # Create one user using default allocation policy |
| 1979 | User.objects.create_user("alice", "alice@example.com") |
| 1980 | |
| 1981 | # Create another user, explicitly specifying the database |
| 1982 | User.objects.db_manager("default").create_user("bob", "bob@example.com") |
| 1983 | |
| 1984 | # The second user only exists on the other database |
| 1985 | alice = User.objects.using("other").get(username="alice") |
| 1986 | |
| 1987 | self.assertEqual(alice.username, "alice") |
| 1988 | self.assertEqual(alice._state.db, "other") |
| 1989 | |
| 1990 | with self.assertRaises(User.DoesNotExist): |
| 1991 | User.objects.using("default").get(username="alice") |
| 1992 | |
| 1993 | # The second user only exists on the default database |
| 1994 | bob = User.objects.using("default").get(username="bob") |
| 1995 | |
| 1996 | self.assertEqual(bob.username, "bob") |
| 1997 | self.assertEqual(bob._state.db, "default") |
| 1998 | |
| 1999 | with self.assertRaises(User.DoesNotExist): |
| 2000 | User.objects.using("other").get(username="bob") |
| 2001 | |
| 2002 | # That is... there is one user on each database |
| 2003 | self.assertEqual(User.objects.using("default").count(), 1) |
| 2004 | self.assertEqual(User.objects.using("other").count(), 1) |
| 2005 | |
| 2006 | def test_dumpdata(self): |
| 2007 | "dumpdata honors allow_migrate restrictions on the router" |
nothing calls this directly
no test coverage detected