|
7 | 7 |
|
8 | 8 | from ansible_base.lib.testing.util import StaticResourceAPIClient
|
9 | 9 | from ansible_base.lib.utils.response import get_relative_url
|
10 |
| -from ansible_base.resource_registry.models import Resource |
| 10 | +from ansible_base.rbac.models import RoleDefinition |
| 11 | +from ansible_base.resource_registry.models import Resource, ResourceType |
11 | 12 | from ansible_base.resource_registry.models.service_identifier import service_id
|
12 |
| -from ansible_base.resource_registry.tasks.sync import ResourceSyncHTTPError, SyncExecutor |
| 13 | +from ansible_base.resource_registry.tasks.sync import ManifestItem, ResourceSyncHTTPError, SyncExecutor, _attempt_create_resource |
13 | 14 |
|
14 | 15 |
|
15 | 16 | @pytest.fixture(scope="function")
|
@@ -178,6 +179,36 @@ def test_resource_sync_update_conflict(static_api_client, stdout, resource_to_up
|
178 | 179 | assert Resource.objects.get(ansible_id=new_id).name == "was_renamed"
|
179 | 180 |
|
180 | 181 |
|
| 182 | +@pytest.mark.django_db |
| 183 | +def test_resource_sync_create_local_role_definition(static_api_client, stdout, resource_to_update): |
| 184 | + item_data = {"name": "Organization Inventory Role", "content_type": "shared.organization", "managed": True, "permissions": []} |
| 185 | + manifest_item = ManifestItem(str(uuid4()), str(uuid4()), item_data) |
| 186 | + result = _attempt_create_resource( |
| 187 | + manifest_item=manifest_item, |
| 188 | + resource_data=item_data, |
| 189 | + resource_type=ResourceType.objects.get(name='shared.roledefinition'), |
| 190 | + resource_service_id=str(uuid4()), |
| 191 | + api_client=static_api_client, # unused |
| 192 | + ) |
| 193 | + assert result.status == 'created' |
| 194 | + |
| 195 | + |
| 196 | +@pytest.mark.django_db |
| 197 | +def test_resource_sync_create_non_local_role_definition(static_api_client, stdout, resource_to_update): |
| 198 | + item_data = {"name": "Remote Role", "content_type": "shared.foo_type", "managed": True, "permissions": []} |
| 199 | + manifest_item = ManifestItem(str(uuid4()), str(uuid4()), item_data) |
| 200 | + result = _attempt_create_resource( |
| 201 | + manifest_item=manifest_item, |
| 202 | + resource_data=item_data, |
| 203 | + resource_type=ResourceType.objects.get(name='shared.roledefinition'), |
| 204 | + resource_service_id=str(uuid4()), |
| 205 | + api_client=static_api_client, # unused |
| 206 | + ) |
| 207 | + assert result.status == 'noop' |
| 208 | + |
| 209 | + assert not RoleDefinition.objects.filter(name="Remote Role").exists() |
| 210 | + |
| 211 | + |
181 | 212 | @pytest.mark.django_db
|
182 | 213 | def test_resource_sync_create_conflict(static_api_client, stdout, resource_to_update):
|
183 | 214 | # Update the ansible ID on the local resources so that it causes a conflict to happen.
|
|
0 commit comments