mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-31 14:43:36 +02:00
Require data_file when data_source is specified
data_source alone is not a valid creation payload — a data_file must also be provided to identify which file within the source to sync. Add the corresponding validation error and a test to cover the case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -57,9 +57,13 @@ class ScriptModuleSerializer(ValidatedModelSerializer):
|
||||
raise serializers.ValidationError(
|
||||
_("Cannot upload a file and sync from a data source.")
|
||||
)
|
||||
if self.instance is None and not upload_file and not has_data_file and not has_data_source:
|
||||
if has_data_source and not has_data_file:
|
||||
raise serializers.ValidationError(
|
||||
_("Must upload a file or provide a data source or data file to sync.")
|
||||
_("A data file must be specified when syncing from a data source.")
|
||||
)
|
||||
if self.instance is None and not upload_file and not has_data_file:
|
||||
raise serializers.ValidationError(
|
||||
_("Must upload a file or provide a data source and data file to sync.")
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
@@ -1441,6 +1441,17 @@ class ScriptUploadTest(APITestCase):
|
||||
)
|
||||
self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def test_data_source_without_data_file_fails(self):
|
||||
"""data_source alone (without data_file) must be rejected."""
|
||||
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
|
||||
response = self.client.post(
|
||||
self.url_list,
|
||||
{'data_source': 1},
|
||||
format='multipart',
|
||||
**self.header,
|
||||
)
|
||||
self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def test_upload_script_module_without_file_fails(self):
|
||||
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
|
||||
response = self.client.post(self.url_list, {}, format='json', **self.header)
|
||||
|
||||
Reference in New Issue
Block a user