Skip to content

Commit c4d1c66

Browse files
committed
Fix router tests
1 parent 27d4b8e commit c4d1c66

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

tests/encryption_/routers.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
from django.db import connection
2-
3-
41
class EncryptedRouter:
52
"""
63
Routes database operations for encrypted models to the encrypted DB.
74
"""
85

96
def db_for_read(self, model, **hints):
10-
with connection.schema_editor() as editor:
11-
if model and getattr(editor._get_encrypted_fields_map(model), False):
12-
return "encrypted"
13-
return None
7+
return "encrypted"
148

159
def db_for_write(self, model, **hints):
16-
with connection.schema_editor() as editor:
17-
if model and getattr(editor._get_encrypted_fields_map(model), False):
18-
return "encrypted"
19-
return None
10+
return "encrypted"
2011

2112
def allow_migrate(self, db, app_label, model_name=None, **hints):
22-
model = hints.get("model")
23-
with connection.schema_editor() as editor:
24-
if model and getattr(editor._get_encrypted_fields_map(model), False):
25-
return db == "encrypted"
26-
return None
13+
return "encrypted"

tests/encryption_/tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
from .routers import EncryptedRouter
66

77

8-
@override_settings(DATABASE_ROUTERS=[EncryptedRouter])
8+
@override_settings(DATABASE_ROUTERS=[EncryptedRouter()])
99
class EncryptedModelTests(TestCase):
10+
databases = {"default", "encrypted"}
11+
1012
@classmethod
1113
def setUpTestData(cls):
1214
cls.person = Person(ssn="123-45-6789")

0 commit comments

Comments
 (0)