diff options
Diffstat (limited to 'tests/multiple_database')
| -rw-r--r-- | tests/multiple_database/tests.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 337ebae75e..9587030a46 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -1302,6 +1302,34 @@ class QueryTestCase(TestCase): title="Dive into Water", published=datetime.date(2009, 5, 4), extra_arg=True ) + @override_settings(DATABASE_ROUTERS=["multiple_database.tests.TestRouter"]) + def test_contenttype_in_separate_db(self): + ContentType.objects.using("other").all().delete() + book_other = Book.objects.using("other").create( + title="Test title other", published=datetime.date(2009, 5, 4) + ) + book_default = Book.objects.using("default").create( + title="Test title default", published=datetime.date(2009, 5, 4) + ) + book_type = ContentType.objects.using("default").get( + app_label="multiple_database", model="book" + ) + + book = book_type.get_object_for_this_type(title=book_other.title) + self.assertEqual(book, book_other) + book = book_type.get_object_for_this_type(using="other", title=book_other.title) + self.assertEqual(book, book_other) + + with self.assertRaises(Book.DoesNotExist): + book_type.get_object_for_this_type(title=book_default.title) + book = book_type.get_object_for_this_type( + using="default", title=book_default.title + ) + self.assertEqual(book, book_default) + + all_books = book_type.get_all_objects_for_this_type() + self.assertCountEqual(all_books, [book_other]) + class ConnectionRouterTestCase(SimpleTestCase): @override_settings( |
