File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 11import contextlib
2+ from copy import deepcopy
23
34import pytest
45from django .test .utils import override_settings
78from ansible_base .lib .utils .response import get_relative_url
89from ansible_base .rbac .models import RoleDefinition
910from ansible_base .rbac .permission_registry import permission_registry
11+ from ansible_base .rbac .validators import LocalValidators , permissions_allowed_for_role
1012from 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
You can’t perform that action at this time.
0 commit comments