Coverage for apps/proscai/routers.py: 69%
20 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-27 19:23 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-27 19:23 -0600
1class CustomRouter:
2 """
3 auth and contenttypes applications.
4 """
6 route_app_labels = ["proscai", "proxy_models"]
8 def db_for_read(self, model, **hints):
9 """
10 Attempts to read auth and contenttypes models go to auth_db.
11 """
12 if model._meta.app_label in self.route_app_labels: 12 ↛ 13line 12 didn't jump to line 13, because the condition on line 12 was never true
13 return "proscai"
14 return "default"
16 def db_for_write(self, model, **hints):
17 """
18 Attempts to write auth and contenttypes models go to auth_db.
19 """
20 if model._meta.app_label in self.route_app_labels: 20 ↛ 21line 20 didn't jump to line 21, because the condition on line 20 was never true
21 return "proscai"
22 return "default"
24 def allow_relation(self, obj1, obj2, **hints):
25 """
26 Allow relations if a model in the auth or contenttypes apps is
27 involved.
28 """
29 if obj1._meta.app_label not in self.route_app_labels and obj2._meta.app_label not in self.route_app_labels: 29 ↛ 31line 29 didn't jump to line 31, because the condition on line 29 was never false
30 return True
31 elif obj1._meta.app_label in self.route_app_labels and obj2._meta.app_label in self.route_app_labels:
32 return True
33 return None
35 def allow_migrate(self, db, app_label=None, model_name=None, **hints):
36 """
37 Make sure the auth and contenttypes apps only appear in the
38 'auth_db' database.
39 """
40 if app_label in self.route_app_labels:
41 return db == "proscai"
42 return "default"