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