Skip to content

Commit

Permalink
fix linting and type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adamarnesen committed Feb 15, 2024
1 parent eae6c4b commit 39e1901
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/spec/update_and_delete_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions tests/integration/spec/test_spec.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
ConditionRange,
ConditionType,
CreateSpecificationRequestObject,
CreateSpecificationResponseObject,
CreateSpecificationsPartialSuccessResponse,
CreateSpecificationsRequest,
DeleteSpecificationsRequest,
Expand All @@ -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])
)
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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

0 comments on commit 39e1901

Please sign in to comment.