From 0217ba6e149e2e45c438ea28e3aeb7ae1eb77d75 Mon Sep 17 00:00:00 2001 From: Andrei Moldovan Date: Mon, 11 May 2026 15:49:48 +0300 Subject: [PATCH 1/7] Transform string into part Co-authored-by: Copilot --- nisystemlink/clients/file/_file_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nisystemlink/clients/file/_file_client.py b/nisystemlink/clients/file/_file_client.py index 0a757e0b..a7479013 100644 --- a/nisystemlink/clients/file/_file_client.py +++ b/nisystemlink/clients/file/_file_client.py @@ -327,13 +327,13 @@ def upload_file( ApiException: if unable to communicate with the File Service. """ if metadata: - metadata_str = json.dumps(metadata) + metadata_part = (None, json.dumps(metadata), "application/json") else: - metadata_str = None + metadata_part = None file_id = self.__upload_file( file=file, - metadata=metadata_str, + metadata=metadata_part, id=id, workspace=workspace, ) From 9af8ef6c636d40269709ce4b34ea9622933bccbe Mon Sep 17 00:00:00 2001 From: Andrei Moldovan Date: Tue, 12 May 2026 08:46:33 +0300 Subject: [PATCH 2/7] applied suggestions --- nisystemlink/clients/file/_file_client.py | 2 +- tests/integration/file/test_file_client.py | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/nisystemlink/clients/file/_file_client.py b/nisystemlink/clients/file/_file_client.py index a7479013..46852e1f 100644 --- a/nisystemlink/clients/file/_file_client.py +++ b/nisystemlink/clients/file/_file_client.py @@ -292,7 +292,7 @@ def __upload_file( Args: file: The file to upload. - metadata: JSON Dictionary with key/value pairs + metadata: PART Dictionary with key/value pairs id: Specify an unique (among all file) 24-digit Hex string ID of the file once it is uploaded. Defaults to None. workspace: The id of the workspace the file belongs to. Defaults to None. diff --git a/tests/integration/file/test_file_client.py b/tests/integration/file/test_file_client.py index d3aaaf2f..5f2d7bb0 100644 --- a/tests/integration/file/test_file_client.py +++ b/tests/integration/file/test_file_client.py @@ -91,6 +91,32 @@ def test__api_info__returns(self, client: FileClient): api_info = client.api_info() assert len(api_info.model_dump()) != 0 + def test__upload_file_with_metadata__succeeds( + self, client: FileClient, binary_file_data: BinaryIO, random_filename_extension: str + ): + file_name = random_filename_extension + metadata = {"CustomProp": "CustomValue"} + + # Upload the file with metadata + file_id = client.upload_file(file=binary_file_data, metadata=metadata) + + # Verify the file was created with correct metadata + files = client.get_files(ids=[file_id]) + assert files.total_count == 1 + assert len(files.available_files) == 1 + assert files.available_files[0].id == file_id + assert files.available_files[0].properties is not None + assert files.available_files[0].properties["Name"] == file_name + assert ( + len(files.available_files[0].properties.keys()) == len(metadata) + 1 + ) # Name + 1 custom property + + client.delete_file(id=file_id) + + # confirm that file was deleted + files = client.get_files(ids=[file_id]) + assert files.total_count == 0 + def test__upload_get_delete_files__succeeds( self, client: FileClient, test_file, random_filename_extension ): From b3cc6d46fbe4b3d61ac5b137fef24f21aaf9f31a Mon Sep 17 00:00:00 2001 From: Andrei Moldovan <122430621+AMoldova-NI@users.noreply.github.com> Date: Tue, 12 May 2026 09:59:26 +0300 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- nisystemlink/clients/file/_file_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nisystemlink/clients/file/_file_client.py b/nisystemlink/clients/file/_file_client.py index 46852e1f..a4601285 100644 --- a/nisystemlink/clients/file/_file_client.py +++ b/nisystemlink/clients/file/_file_client.py @@ -292,7 +292,9 @@ def __upload_file( Args: file: The file to upload. - metadata: PART Dictionary with key/value pairs + metadata: Multipart part for file metadata, typically ``None`` or a + ``(None, json_string, "application/json")`` tuple where + ``json_string`` contains the metadata key/value pairs. id: Specify an unique (among all file) 24-digit Hex string ID of the file once it is uploaded. Defaults to None. workspace: The id of the workspace the file belongs to. Defaults to None. From 3e214ffdd62bb0386626baead56ed907e3db02a4 Mon Sep 17 00:00:00 2001 From: Andrei Moldovan Date: Tue, 19 May 2026 13:08:21 +0300 Subject: [PATCH 4/7] applied suggestions --- tests/integration/file/test_file_client.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/integration/file/test_file_client.py b/tests/integration/file/test_file_client.py index 5f2d7bb0..ceb4d750 100644 --- a/tests/integration/file/test_file_client.py +++ b/tests/integration/file/test_file_client.py @@ -33,7 +33,7 @@ def client(enterprise_config) -> FileClient: return FileClient(enterprise_config) -@pytest.fixture(scope="class") +@pytest.fixture def binary_file_data() -> BinaryIO: """Test Binary file content.""" return io.BytesIO(TEST_FILE_DATA) @@ -44,10 +44,10 @@ def test_file(client: FileClient): """Fixture to return a factory that uploads a file.""" file_ids = [] - def _test_file(file_name: str = TEST_FILE_NAME, cleanup: bool = True) -> str: + def _test_file(file_name: str = TEST_FILE_NAME, cleanup: bool = True, metadata: dict = None) -> str: test_file = io.BytesIO(TEST_FILE_DATA) test_file.name = file_name - file_id = client.upload_file(file=test_file) + file_id = client.upload_file(file=test_file, metadata=metadata) if cleanup: file_ids.append(file_id) @@ -97,8 +97,7 @@ def test__upload_file_with_metadata__succeeds( file_name = random_filename_extension metadata = {"CustomProp": "CustomValue"} - # Upload the file with metadata - file_id = client.upload_file(file=binary_file_data, metadata=metadata) + file_id = test_file(file_name=file_name, metadata=metadata) # Verify the file was created with correct metadata files = client.get_files(ids=[file_id]) @@ -111,12 +110,6 @@ def test__upload_file_with_metadata__succeeds( len(files.available_files[0].properties.keys()) == len(metadata) + 1 ) # Name + 1 custom property - client.delete_file(id=file_id) - - # confirm that file was deleted - files = client.get_files(ids=[file_id]) - assert files.total_count == 0 - def test__upload_get_delete_files__succeeds( self, client: FileClient, test_file, random_filename_extension ): @@ -131,12 +124,6 @@ def test__upload_get_delete_files__succeeds( assert files.available_files[0].properties is not None assert files.available_files[0].properties["Name"] == random_filename_extension - client.delete_file(id=file_id) - - # confirm that file was deleted - files = client.get_files(ids=[file_id]) - assert files.total_count == 0 - def test__delete_file__invalid_id_raises( self, client: FileClient, invalid_file_id: str ): From 0febeaff27e394d59ce2f4e229963ac968730589 Mon Sep 17 00:00:00 2001 From: Andrei Moldovan Date: Tue, 26 May 2026 14:05:12 +0300 Subject: [PATCH 5/7] fiel format --- tests/integration/file/test_file_client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/integration/file/test_file_client.py b/tests/integration/file/test_file_client.py index ceb4d750..f3cf180d 100644 --- a/tests/integration/file/test_file_client.py +++ b/tests/integration/file/test_file_client.py @@ -44,7 +44,9 @@ def test_file(client: FileClient): """Fixture to return a factory that uploads a file.""" file_ids = [] - def _test_file(file_name: str = TEST_FILE_NAME, cleanup: bool = True, metadata: dict = None) -> str: + def _test_file( + file_name: str = TEST_FILE_NAME, cleanup: bool = True, metadata: dict = None + ) -> str: test_file = io.BytesIO(TEST_FILE_DATA) test_file.name = file_name file_id = client.upload_file(file=test_file, metadata=metadata) @@ -92,7 +94,10 @@ def test__api_info__returns(self, client: FileClient): assert len(api_info.model_dump()) != 0 def test__upload_file_with_metadata__succeeds( - self, client: FileClient, binary_file_data: BinaryIO, random_filename_extension: str + self, + client: FileClient, + binary_file_data: BinaryIO, + random_filename_extension: str, ): file_name = random_filename_extension metadata = {"CustomProp": "CustomValue"} From 92100073fc048543ba16104a3343f047311153e6 Mon Sep 17 00:00:00 2001 From: Andrei Moldovan <122430621+AMoldova-NI@users.noreply.github.com> Date: Fri, 29 May 2026 08:28:04 +0300 Subject: [PATCH 6/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tests/integration/file/test_file_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/file/test_file_client.py b/tests/integration/file/test_file_client.py index f3cf180d..832dfb86 100644 --- a/tests/integration/file/test_file_client.py +++ b/tests/integration/file/test_file_client.py @@ -96,7 +96,7 @@ def test__api_info__returns(self, client: FileClient): def test__upload_file_with_metadata__succeeds( self, client: FileClient, - binary_file_data: BinaryIO, + test_file, random_filename_extension: str, ): file_name = random_filename_extension From a7eb8ed7b141a1d408af8dab75b89dbcaa39943e Mon Sep 17 00:00:00 2001 From: Andrei Moldovan Date: Fri, 29 May 2026 08:31:40 +0300 Subject: [PATCH 7/7] mypy fix --- tests/integration/file/test_file_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/file/test_file_client.py b/tests/integration/file/test_file_client.py index f3cf180d..9e6f3bf5 100644 --- a/tests/integration/file/test_file_client.py +++ b/tests/integration/file/test_file_client.py @@ -45,7 +45,7 @@ def test_file(client: FileClient): file_ids = [] def _test_file( - file_name: str = TEST_FILE_NAME, cleanup: bool = True, metadata: dict = None + file_name: str = TEST_FILE_NAME, cleanup: bool = True, metadata: dict = {} ) -> str: test_file = io.BytesIO(TEST_FILE_DATA) test_file.name = file_name