mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-23 09:18:49 +02:00
cleanup
This commit is contained in:
@@ -1472,11 +1472,14 @@ class ScriptUploadTest(APITestCase):
|
|||||||
"""POST with data_source + data_file (JSON) creates a ScriptModule with the correct file_path."""
|
"""POST with data_source + data_file (JSON) creates a ScriptModule with the correct file_path."""
|
||||||
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
|
self.add_permissions('extras.add_scriptmodule', 'core.add_managedfile')
|
||||||
mock_storage = MagicMock()
|
mock_storage = MagicMock()
|
||||||
mock_storage.open.return_value.__enter__ = MagicMock(return_value=MagicMock())
|
# Patch storages in both the serializer (for _sync_data_file) and the model
|
||||||
mock_storage.open.return_value.__exit__ = MagicMock(return_value=False)
|
# (for ManagedFile.sync_data(), which is called by SyncedDataMixin.clean() during
|
||||||
with patch('extras.api.serializers_.scripts.storages') as mock_storages:
|
# ValidatedModelSerializer.validate() → full_clean()).
|
||||||
mock_storages.create_storage.return_value = mock_storage
|
with patch('extras.api.serializers_.scripts.storages') as mock_ser_storages, \
|
||||||
mock_storages.backends = {'scripts': {}}
|
patch('core.models.files.storages') as mock_model_storages:
|
||||||
|
for m in (mock_ser_storages, mock_model_storages):
|
||||||
|
m.create_storage.return_value = mock_storage
|
||||||
|
m.backends = {'scripts': {}}
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
self.url_list,
|
self.url_list,
|
||||||
{'data_source': self.data_source.pk, 'data_file': self.data_file.pk},
|
{'data_source': self.data_source.pk, 'data_file': self.data_file.pk},
|
||||||
|
|||||||
Reference in New Issue
Block a user