Skip to content

Commit

Permalink
fix: asset api client testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam rishi committed Dec 4, 2024
1 parent 9abf768 commit efd5ce0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 47 deletions.
26 changes: 7 additions & 19 deletions nisystemlink/clients/assetManagement/_asset_management_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -256,7 +244,7 @@ def unlink_files(
self,
asset_id: str,
file_id: str
) -> models.NoContentResult:
) -> Optional[models.NoContentResult]:
"""Unlink files from Asset.
Args:
Expand Down
63 changes: 35 additions & 28 deletions tests/integration/assetManagement/test_asset_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
):
Expand All @@ -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
):
Expand All @@ -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
Expand All @@ -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
)
Expand All @@ -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
Expand Down

0 comments on commit efd5ce0

Please sign in to comment.