| 
6 | 6 | from rest_framework.exceptions import ValidationError  | 
7 | 7 | 
 
  | 
8 | 8 | from ansible_base.lib.utils.response import get_relative_url  | 
9 |  | -from ansible_base.rbac.models import RoleDefinition  | 
 | 9 | +from ansible_base.rbac.models import DABPermission, RoleDefinition  | 
10 | 10 | from ansible_base.rbac.permission_registry import permission_registry  | 
 | 11 | +from ansible_base.rbac.remote import RemoteObject  | 
11 | 12 | from ansible_base.rbac.validators import LocalValidators, permissions_allowed_for_role  | 
12 | 13 | from test_app.models import Credential, Inventory, Organization  | 
13 | 14 | 
 
  | 
@@ -146,13 +147,23 @@ def test_no_change_permission_without_view(enabled):  | 
146 | 147 | @pytest.mark.parametrize('cls', permission_registry.all_registered_models)  | 
147 | 148 | def test_db_model_validators_match(cls):  | 
148 | 149 |     "This is a code transition test, making sure new DB-backed methods match model-backed methods"  | 
 | 150 | + | 
 | 151 | +    # Load in some remote types and permissions to make test meaningful  | 
 | 152 | +    org_ct = permission_registry.content_type_model.objects.get_for_model(Organization)  | 
 | 153 | +    foo_ct = permission_registry.content_type_model.objects.create(service='foo', model='foo', app_label='foo', parent_content_type=org_ct)  | 
 | 154 | +    DABPermission.objects.create(codename='foo_foo', content_type=foo_ct)  | 
 | 155 | + | 
149 | 156 |     db_perms = permissions_allowed_for_role(cls)  | 
150 | 157 |     model_perms = LocalValidators.permissions_allowed_for_role(cls)  | 
151 | 158 | 
 
  | 
152 | 159 |     # convert data structure into sets because this test does not care about ordering  | 
153 | 160 |     for perms_structure in (db_perms, model_perms):  | 
154 | 161 |         tmp_structure = deepcopy(perms_structure)  | 
155 | 162 |         for main_model, codenames_list in tmp_structure.items():  | 
 | 163 | +            if issubclass(main_model, RemoteObject):  | 
 | 164 | +                # obviously the model method will not track permissions valid for remote model  | 
 | 165 | +                perms_structure.pop(main_model)  | 
 | 166 | +                continue  | 
156 | 167 |             perms_structure[main_model] = set(codenames_list)  | 
157 | 168 | 
 
  | 
158 | 169 |     assert db_perms == model_perms  | 
0 commit comments