From 39e1901910b04781e3b526f405236e1cffa2016d Mon Sep 17 00:00:00 2001 From: Adam Arnesen Date: Thu, 15 Feb 2024 13:53:09 -0600 Subject: [PATCH] fix linting and type errors --- examples/spec/update_and_delete_specs.py | 2 +- tests/integration/spec/test_spec.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/spec/update_and_delete_specs.py b/examples/spec/update_and_delete_specs.py index 0a558e87..9e91a6b5 100644 --- a/examples/spec/update_and_delete_specs.py +++ b/examples/spec/update_and_delete_specs.py @@ -42,7 +42,7 @@ update_response = client.update_specs( specs=UpdateSpecificationsRequest(specs=[modified_spec]) ) -if update_response.updated_specs: +if update_response and update_response.updated_specs: print(f"New spec1 version: {update_response.updated_specs[0].version}") # query again to see new version diff --git a/tests/integration/spec/test_spec.py b/tests/integration/spec/test_spec.py index 9fed99e1..16dba9a3 100644 --- a/tests/integration/spec/test_spec.py +++ b/tests/integration/spec/test_spec.py @@ -1,5 +1,5 @@ import uuid -from typing import List, Optional +from typing import List import pytest from nisystemlink.clients.core._http_configuration import HttpConfiguration @@ -9,6 +9,7 @@ ConditionRange, ConditionType, CreateSpecificationRequestObject, + CreateSpecificationResponseObject, CreateSpecificationsPartialSuccessResponse, CreateSpecificationsRequest, DeleteSpecificationsRequest, @@ -32,16 +33,19 @@ def create_specs(client: SpecClient): """Fixture to return a factory that creates specs.""" responses: List[CreateSpecificationsPartialSuccessResponse] = [] - def _create_specs(new_specs: Optional[CreateSpecificationsRequest]) -> str: + def _create_specs( + new_specs: CreateSpecificationsRequest, + ) -> CreateSpecificationsPartialSuccessResponse: response = client.create_specs(new_specs) responses.append(response) return response yield _create_specs - created_specs = [] + created_specs: List[CreateSpecificationResponseObject] = [] for response in responses: - created_specs = created_specs + response.created_specs + if response.created_specs: + created_specs = created_specs + response.created_specs client.delete_specs( DeleteSpecificationsRequest(ids=[spec.id for spec in created_specs]) ) @@ -176,6 +180,7 @@ def test__delete_existing_spec__succeeds(self, client: SpecClient): type=Type.FUNCTIONAL, ) response = client.create_specs(CreateSpecificationsRequest(specs=[spec])) + assert response.created_specs created_spec = response.created_specs[0] delete_response = client.delete_specs( @@ -186,6 +191,8 @@ def test__delete_existing_spec__succeeds(self, client: SpecClient): def test__delete_non_existant_spec__delete_fails(self, client: SpecClient): bad_id = "DEADBEEF" delete_response = client.delete_specs(DeleteSpecificationsRequest(ids=[bad_id])) + assert delete_response + assert delete_response.failed_spec_ids assert bad_id in delete_response.failed_spec_ids def test__update_single_same_version__version_updates( @@ -219,7 +226,8 @@ def test__update_single_same_version__version_updates( update_response = client.update_specs( specs=UpdateSpecificationsRequest(specs=[update_spec]) ) - assert update_response is not None + assert update_response + assert update_response.updated_specs assert len(update_response.updated_specs) == 1 updated_spec = update_response.updated_specs[0] assert updated_spec.version == 1 @@ -230,6 +238,7 @@ def test__query_product__all_returned( request = QuerySpecificationsRequest(productIds=["TestProduct"]) response = client.query_specs(request) + assert response.specs assert len(response.specs) == 3 def test__query_spec_name__two_returned( @@ -239,6 +248,7 @@ def test__query_spec_name__two_returned( product_ids=["TestProduct"], filter='name.Contains("voltage")' ) response = client.query_specs(request) + assert response.specs assert len(response.specs) == 2 def test__query_spec_category_one_returned( @@ -248,6 +258,7 @@ def test__query_spec_category_one_returned( product_ids=["TestProduct"], filter='category == "Noise Thresholds"' ) response = client.query_specs(request) + assert response.specs assert len(response.specs) == 1 def test__query_input_voltage__conditions_match( @@ -257,6 +268,8 @@ def test__query_input_voltage__conditions_match( product_ids=["TestProduct"], filter='name == "input voltage"' ) response = client.query_specs(request) + assert response.specs assert len(response.specs) == 1 voltage_spec = response.specs[0] + assert voltage_spec.conditions assert len(voltage_spec.conditions) == 2