mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-31 22:53:21 +02:00
Align API validation messages with UI; restore complete checks
- Match UI error messages for upload+data_file conflict and no-source case - Keep API-only guards for upload+data_source and data_source-without-data_file - Restore test_upload_with_data_source_fails Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,7 @@ class ScriptModuleSerializer(ValidatedModelSerializer):
|
|||||||
|
|
||||||
if upload_file and has_data_file:
|
if upload_file and has_data_file:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
_("Cannot upload a file and sync from an existing data file.")
|
_("Cannot upload a file and sync from an existing file")
|
||||||
)
|
)
|
||||||
if upload_file and has_data_source:
|
if upload_file and has_data_source:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
@@ -63,7 +63,7 @@ class ScriptModuleSerializer(ValidatedModelSerializer):
|
|||||||
)
|
)
|
||||||
if self.instance is None and not upload_file and not has_data_file:
|
if self.instance is None and not upload_file and not has_data_file:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
_("Must upload a file or provide a data source and data file to sync.")
|
_("Must upload a file or select a data file to sync")
|
||||||
)
|
)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -1431,8 +1431,6 @@ class ScriptUploadTest(APITestCase):
|
|||||||
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
|
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
|
||||||
script_content = b"from extras.scripts import Script\nclass TestScript(Script):\n pass\n"
|
script_content = b"from extras.scripts import Script\nclass TestScript(Script):\n pass\n"
|
||||||
upload_file = SimpleUploadedFile('test_upload.py', script_content, content_type='text/plain')
|
upload_file = SimpleUploadedFile('test_upload.py', script_content, content_type='text/plain')
|
||||||
# data_source is intentionally a raw value to exercise the multipart path where DRF's
|
|
||||||
# nested-serializer HTML parser drops the field; validation must still catch the conflict.
|
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
self.url_list,
|
self.url_list,
|
||||||
{'upload_file': upload_file, 'data_source': 1},
|
{'upload_file': upload_file, 'data_source': 1},
|
||||||
|
|||||||
Reference in New Issue
Block a user