mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 16:28:43 -03:30
block updates to constructed source type
This commit is contained in:
@@ -2244,6 +2244,8 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
|||||||
obj = super(InventorySourceSerializer, self).update(obj, validated_data)
|
obj = super(InventorySourceSerializer, self).update(obj, validated_data)
|
||||||
if deprecated_fields:
|
if deprecated_fields:
|
||||||
self._update_deprecated_fields(deprecated_fields, obj)
|
self._update_deprecated_fields(deprecated_fields, obj)
|
||||||
|
if obj.source == 'constructed':
|
||||||
|
raise serializers.ValidationError({'error': _("Cannot edit source of type constructed.")})
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
# TODO: remove when old 'credential' fields are removed
|
# TODO: remove when old 'credential' fields are removed
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ from awx.api.versioning import reverse
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def constructed_inventory(organization, inventory):
|
def constructed_inventory(organization):
|
||||||
inv_source = Inventory.objects.create(name='dummy2', kind='constructed', organization=organization)
|
"""
|
||||||
|
creates a new constructed inventory source
|
||||||
return inv_source
|
"""
|
||||||
|
return Inventory.objects.create(name='dummy2', kind='constructed', organization=organization)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@@ -15,8 +16,8 @@ def test_constructed_inventory_post(post, organization, admin_user):
|
|||||||
inventory1 = Inventory.objects.create(name='dummy1', kind='constructed', organization=organization)
|
inventory1 = Inventory.objects.create(name='dummy1', kind='constructed', organization=organization)
|
||||||
inventory2 = Inventory.objects.create(name='dummy2', kind='constructed', organization=organization)
|
inventory2 = Inventory.objects.create(name='dummy2', kind='constructed', organization=organization)
|
||||||
resp = post(
|
resp = post(
|
||||||
url=reverse('api:inventory_input_inventories', kwargs={'pk': inventory1.id}),
|
url=reverse('api:inventory_input_inventories', kwargs={'pk': inventory1.pk}),
|
||||||
data={'id': inventory2.id},
|
data={'id': inventory2.pk},
|
||||||
user=admin_user,
|
user=admin_user,
|
||||||
expect=405,
|
expect=405,
|
||||||
)
|
)
|
||||||
@@ -26,7 +27,7 @@ def test_constructed_inventory_post(post, organization, admin_user):
|
|||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_add_constructed_inventory_source(post, admin_user, constructed_inventory):
|
def test_add_constructed_inventory_source(post, admin_user, constructed_inventory):
|
||||||
resp = post(
|
resp = post(
|
||||||
url=reverse('api:inventory_inventory_sources_list', kwargs={'pk': constructed_inventory.id}),
|
url=reverse('api:inventory_inventory_sources_list', kwargs={'pk': constructed_inventory.pk}),
|
||||||
data={'name': 'dummy1', 'source': 'constructed'},
|
data={'name': 'dummy1', 'source': 'constructed'},
|
||||||
user=admin_user,
|
user=admin_user,
|
||||||
expect=400,
|
expect=400,
|
||||||
@@ -54,3 +55,16 @@ def test_add_constructed_inventory_group(post, admin_user, constructed_inventory
|
|||||||
expect=400,
|
expect=400,
|
||||||
)
|
)
|
||||||
assert resp.status_code == 400
|
assert resp.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_edit_constructed_inventory_source(patch, admin_user, inventory):
|
||||||
|
inventory.inventory_sources.create(name="dummysrc", source="constructed")
|
||||||
|
inv_id = inventory.inventory_sources.get(name='dummysrc').id
|
||||||
|
resp = patch(
|
||||||
|
reverse('api:inventory_source_detail', kwargs={'pk': inv_id}),
|
||||||
|
data={'description': inventory.name},
|
||||||
|
user=admin_user,
|
||||||
|
expect=400,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 400
|
||||||
|
|||||||
Reference in New Issue
Block a user