Skip to content

Commit 6613bda

Browse files
committed
Add parity tests for new and old methods
1 parent d27dae9 commit 6613bda

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test_app/tests/rbac/test_validators.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
from copy import deepcopy
23

34
import pytest
45
from django.test.utils import override_settings
@@ -7,6 +8,7 @@
78
from ansible_base.lib.utils.response import get_relative_url
89
from ansible_base.rbac.models import RoleDefinition
910
from ansible_base.rbac.permission_registry import permission_registry
11+
from ansible_base.rbac.validators import LocalValidators, permissions_allowed_for_role
1012
from test_app.models import Credential, Inventory, Organization
1113

1214

@@ -138,3 +140,19 @@ def test_no_change_permission_without_view(enabled):
138140
)
139141
if enabled:
140142
assert 'needs to include view, got:' in str(exc)
143+
144+
145+
@pytest.mark.django_db
146+
@pytest.mark.parametrize('cls', permission_registry.all_registered_models)
147+
def test_db_model_validators_match(cls):
148+
"This is a code transition test, making sure new DB-backed methods match model-backed methods"
149+
db_perms = permissions_allowed_for_role(cls)
150+
model_perms = LocalValidators.permissions_allowed_for_role(cls)
151+
152+
# convert data structure into sets because this test does not care about ordering
153+
for perms_structure in (db_perms, model_perms):
154+
tmp_structure = deepcopy(perms_structure)
155+
for main_model, codenames_list in tmp_structure.items():
156+
perms_structure[main_model] = set(codenames_list)
157+
158+
assert db_perms == model_perms

0 commit comments

Comments
 (0)