File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ class PostgresTableLockMode(Enum):
19
19
EXCLUSIVE = "EXCLUSIVE"
20
20
ACCESS_EXCLUSIVE = "ACCESS EXCLUSIVE"
21
21
22
+ @property
23
+ def alias (self ) -> str :
24
+ return (
25
+ "" .join ([word .title () for word in self .name .lower ().split ("_" )])
26
+ + "Lock"
27
+ )
28
+
22
29
23
30
def postgres_lock_table (
24
31
table_name : str ,
Original file line number Diff line number Diff line change @@ -66,18 +66,17 @@ def test_postgres_lock_table_in_schema():
66
66
assert lock_signature not in get_table_locks ()
67
67
68
68
69
+ @pytest .mark .parametrize ("lock_mode" , list (PostgresTableLockMode ))
69
70
@pytest .mark .django_db (transaction = True )
70
- def test_postgres_lock_mode (mocked_model ):
71
+ def test_postgres_lock_model (mocked_model , lock_mode ):
71
72
lock_signature = (
72
73
"public" ,
73
74
mocked_model ._meta .db_table ,
74
- "AccessExclusiveLock" ,
75
+ lock_mode . alias ,
75
76
)
76
77
77
78
with transaction .atomic ():
78
- postgres_lock_model (
79
- mocked_model , PostgresTableLockMode .ACCESS_EXCLUSIVE
80
- )
79
+ postgres_lock_model (mocked_model , lock_mode )
81
80
assert lock_signature in get_table_locks ()
82
81
83
82
assert lock_signature not in get_table_locks ()
You can’t perform that action at this time.
0 commit comments