summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamian Posener <750763+deains@users.noreply.github.com>2022-02-07 15:06:25 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-09 13:31:49 +0100
commit09e499a39eec9342cb594bfd27939cfd1046f797 (patch)
treee7203ae3fed67802c159db6d1725971a17c8b654 /tests
parent2d472ad05c7fb2a5fe405be46af2062cdb5eaeee (diff)
Fixed #33501 -- Made order_with_respect_to respect database routers.
Diffstat (limited to 'tests')
-rw-r--r--tests/order_with_respect_to/base_tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/order_with_respect_to/base_tests.py b/tests/order_with_respect_to/base_tests.py
index 0767d5080f..c895074e42 100644
--- a/tests/order_with_respect_to/base_tests.py
+++ b/tests/order_with_respect_to/base_tests.py
@@ -6,6 +6,8 @@ from operator import attrgetter
class BaseOrderWithRespectToTests:
+ databases = {"default", "other"}
+
# Hook to allow subclasses to run these tests with alternate models.
Answer = None
Post = None
@@ -108,3 +110,15 @@ class BaseOrderWithRespectToTests:
a1.delete()
new_answer = self.Answer.objects.create(text="Black", question=q1)
self.assertSequenceEqual(q1.answer_set.all(), [a2, a4, new_answer])
+
+ def test_database_routing(self):
+ class WriteToOtherRouter:
+ def db_for_write(self, model, **hints):
+ return "other"
+
+ with self.settings(DATABASE_ROUTERS=[WriteToOtherRouter()]):
+ with self.assertNumQueries(0, using="default"), self.assertNumQueries(
+ 1,
+ using="other",
+ ):
+ self.q1.set_answer_order([3, 1, 2, 4])