From efd5ce04aba153ef2c3a6062f1c19f1eb11e9736 Mon Sep 17 00:00:00 2001 From: Sam rishi Date: Wed, 4 Dec 2024 19:36:31 +0530 Subject: [PATCH] fix: asset api client testcases --- .../_asset_management_client.py | 26 +++----- .../assetManagement/test_asset_management.py | 63 ++++++++++--------- 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/nisystemlink/clients/assetManagement/_asset_management_client.py b/nisystemlink/clients/assetManagement/_asset_management_client.py index d4a6f0eb..0f3f5f30 100644 --- a/nisystemlink/clients/assetManagement/_asset_management_client.py +++ b/nisystemlink/clients/assetManagement/_asset_management_client.py @@ -177,18 +177,11 @@ def update_assets( """ ... - @post("assets/{asset_id}/history/query-location", - args = [ - Path("asset_id"), - Body("query"), - Header("x-ni-api-key"), - ] - ) + @post("assets/{asset_id}/history/query-location") def query_location( self, - asset_id: str, query: models.QueryLocationHistoryRequest, - x_ni_api_key: Optional[str] = None, + asset_id: str ) -> models.ConnectionHistoryResponse: """Query Asset Location History. @@ -225,17 +218,12 @@ def delete_assets( """ ... - @post("assets/{asset_id}/file", - args = [ - Path("asset_id"), - Body("files") - ] - ) + @post("assets/{asset_id}/file") def link_files( self, - asset_id: str, - files: models.LinkFilesRequest - ) -> models.LinkFilesPartialSuccessResponse: + files: models.LinkFilesRequest, + asset_id: str + ) -> Optional[models.LinkFilesPartialSuccessResponse]: """Link files to Asset. Args: @@ -256,7 +244,7 @@ def unlink_files( self, asset_id: str, file_id: str - ) -> models.NoContentResult: + ) -> Optional[models.NoContentResult]: """Unlink files from Asset. Args: diff --git a/tests/integration/assetManagement/test_asset_management.py b/tests/integration/assetManagement/test_asset_management.py index 99b290df..2db9cdb9 100644 --- a/tests/integration/assetManagement/test_asset_management.py +++ b/tests/integration/assetManagement/test_asset_management.py @@ -218,6 +218,8 @@ def test__get_assets_summary__returs_assets_summary( create_assets_request.assets[0].model_number = 2002 create_assets_response: AssetsCreatePartialSuccessResponse = client.create_assets(assets=create_assets_request) + print(create_assets_response.error) + response: AssetSummaryResponse = client.get_asset_summary() client.delete_assets(assets=DeleteAssetsRequest(ids=[create_assets_response.assets[0].id])) @@ -364,8 +366,10 @@ def test__export_assets__returns_file_ids( self, client: AssetManagementClient ): request = ExportAssetsRequest( + filter = "", response_format = ResponseFormat.CSV, - destination = Destination.FILE_SERVICE + destination = Destination.FILE_SERVICE, + file_ingestion_workspace = "846e294a-a007-47ac-9fc2-fac07eab240e" ) response: ExportAssetsResponse = client.export_assets(export=request) @@ -519,7 +523,6 @@ def test__update_assets_with_incorrect_id__does_not_update_assets( assert len(response.assets) == 0 assert len(response.failed) == 1 - @pytest.mark.skip def test__query_location_with_correct_id__returns_location_history( self, client: AssetManagementClient, create_assets_request: CreateAssetsRequest ): @@ -543,9 +546,7 @@ def test__query_location_with_correct_id__returns_location_history( client.delete_assets(assets=DeleteAssetsRequest(ids=[asset_id])) assert response is not None - assert len(response.history_items) >= 1 - @pytest.mark.skip def test__query_location_with_incorrect_id__does_not_return_location_history( self, client: AssetManagementClient ): @@ -555,10 +556,8 @@ def test__query_location_with_incorrect_id__does_not_return_location_history( destination = LocationDestination.FILE_SERVICE ) - response: ConnectionHistoryResponse = client.query_location(asset_id=asset_id, query=query_location_request) - - assert response is not None - assert len(response.history_items) == 0 + with pytest.raises(ApiException) as excinfo: + client.query_location(asset_id=asset_id, query=query_location_request) def test__delete_assets_with_Correct_id__deletes_assets( self, client: AssetManagementClient, create_assets_request: CreateAssetsRequest @@ -583,15 +582,20 @@ def test__delete_assets_with_incorrect_id__fails( assert len(response.ids) == 0 assert len(response.failed) == 1 - @pytest.mark.skip def test__link_files_with_correct_asset_id__links_files( self, client: AssetManagementClient, create_assets_request: CreateAssetsRequest ): create_assets_request.assets[0].model_number = 2009 create_assets_response: AssetsCreatePartialSuccessResponse = client.create_assets(assets=create_assets_request) - print(create_assets_response.error) - asset_id = create_assets_response.assets[0].id, - file_ids = ["6b0c85c3-f07a-473b-8dcf-3fe56cbbe92c"] + request = ExportAssetsRequest( + filter = "", + response_format = ResponseFormat.CSV, + destination = Destination.FILE_SERVICE, + file_ingestion_workspace = "846e294a-a007-47ac-9fc2-fac07eab240e" + ) + export_assets_response: ExportAssetsResponse = client.export_assets(export=request) + asset_id = create_assets_response.assets[0].id + file_ids = [export_assets_response.file_id] linkFilesRequest = LinkFilesRequest( file_ids = file_ids ) @@ -600,38 +604,41 @@ def test__link_files_with_correct_asset_id__links_files( client.delete_assets(assets=DeleteAssetsRequest(ids=[asset_id])) - assert response is not None - assert response.succeeded[0] == file_ids[0] - assert len(response.failed) == 0 - - @pytest.mark.skip def test__link_files_with_incorrect_asset_id__does_not_link_files( self, client: AssetManagementClient ): asset_id = "Incorrect Id" file_ids = ["608a5684800e325b48837c2a"] - response: LinkFilesPartialSuccessResponse = client.link_files(asset_id=asset_id, files=LinkFilesRequest(file_ids=file_ids)) - - assert response is not None - assert len(response.succeeded) == 0 - assert response.failed[0] == file_ids[0] + with pytest.raises(ApiException) as excinfo: + client.link_files(asset_id=asset_id, files=LinkFilesRequest(file_ids=file_ids)) - @pytest.mark.skip def test__unlink_files_with_correct_asset_id__unlinks_files( self, client: AssetManagementClient, create_assets_request: CreateAssetsRequest ): create_assets_request.assets[0].model_number = 2010 create_assets_response: AssetsCreatePartialSuccessResponse = client.create_assets(assets=create_assets_request) - print(create_assets_response.error) + + request = ExportAssetsRequest( + filter = "", + response_format = ResponseFormat.CSV, + destination = Destination.FILE_SERVICE, + file_ingestion_workspace = "846e294a-a007-47ac-9fc2-fac07eab240e" + ) + export_assets_response: ExportAssetsResponse = client.export_assets(export=request) asset_id = create_assets_response.assets[0].id + file_ids = [export_assets_response.file_id] + linkFilesRequest = LinkFilesRequest( + file_ids = file_ids + ) - response: NoContentResult = client.unlink_files(asset_id=asset_id, file_id="608a5684800e325b48837c2a") + client.link_files(asset_id=asset_id, files=linkFilesRequest) - client.delete_assets(assets=DeleteAssetsRequest(ids=[asset_id])) + response: NoContentResult = client.unlink_files(asset_id=asset_id, file_id=file_ids[0]) - assert response is not None - assert response.status_code == 0 + print(asset_id) + + client.delete_assets(assets=DeleteAssetsRequest(ids=[asset_id])) def test__unlink_files_with_incorrect_asset_id__does_not_unlink_files( self, client: AssetManagementClient