MCPcopy
hub / github.com/django/django / TestRouter

Class TestRouter

tests/multiple_database/routers.py:4–25  ·  view source on GitHub ↗

Vaguely behave like primary/replica, but the databases aren't assumed to propagate changes.

Source from the content-addressed store, hash-verified

2
3
4class TestRouter:
5 """
6 Vaguely behave like primary/replica, but the databases aren't assumed to
7 propagate changes.
8 """
9
10 def db_for_read(self, model, instance=None, **hints):
11 if instance:
12 return instance._state.db or "other"
13 return "other"
14
15 def db_for_write(self, model, **hints):
16 return DEFAULT_DB_ALIAS
17
18 def allow_relation(self, obj1, obj2, **hints):
19 return obj1._state.db in ("default", "other") and obj2._state.db in (
20 "default",
21 "other",
22 )
23
24 def allow_migrate(self, db, app_label, **hints):
25 return True
26
27
28class AuthRouter:

Callers 3

test_router_init_argMethod · 0.70
test_partial_routerMethod · 0.70

Calls

no outgoing calls

Tested by 3

test_router_init_argMethod · 0.56
test_partial_routerMethod · 0.56