Skip to content
1 change: 1 addition & 0 deletions nisystemlink/clients/spec/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ._query_specs import (
QuerySpecificationsRequest,
PagedSpecifications,
SpecificationOrderBy,
SpecificationProjection,
)
from ._specification import (
Expand Down
2 changes: 2 additions & 0 deletions nisystemlink/clients/spec/models/_query_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ class SpecificationProjection(str, Enum):
WORKSPACE = "WORKSPACE"
CREATED_AT = "CREATED_AT"
CREATED_BY = "CREATED_BY"
UPDATED_AT = "UPDATED_AT"


class SpecificationOrderBy(Enum):
"""The valid ways to order the response to a spec query."""

ID = "ID"
SPEC_ID = "SPEC_ID"
UPDATED_AT = "UPDATED_AT"


class QuerySpecificationsRequest(JsonModel):
Expand Down
119 changes: 117 additions & 2 deletions tests/integration/spec/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
NumericConditionValue,
QuerySpecificationsRequest,
SpecificationLimit,
SpecificationOrderBy,
SpecificationProjection,
SpecificationType,
StringConditionValue,
Expand Down Expand Up @@ -318,7 +319,11 @@ def test__query_spec_projection_columns__columns_returned(
):
request = QuerySpecificationsRequest(
product_ids=[product],
projection=[SpecificationProjection.SPEC_ID, SpecificationProjection.NAME],
projection=[
SpecificationProjection.SPEC_ID,
SpecificationProjection.NAME,
SpecificationProjection.UPDATED_AT,
],
)
Comment thread
Ahalya-ni marked this conversation as resolved.

response = client.query_specs(request)
Expand All @@ -329,9 +334,10 @@ def test__query_spec_projection_columns__columns_returned(

assert response.specs
assert len(response.specs) == 3
assert len(spec_columns) == 2
assert len(spec_columns) == 3
assert "spec_id" in spec_columns
assert "name" in spec_columns
assert "updated_at" in spec_columns

def test__query_specs__returns_condition_value_type_correctly(
self, client: SpecClient, create_specs, create_specs_for_query, product
Expand Down Expand Up @@ -405,3 +411,112 @@ def test__without_condition_type_projection__query_specs__condition_type_field_i
assert "condition_name" in spec_columns
assert "condition_unit" in spec_columns
assert "condition_type" not in spec_columns

def test__query_specs_order_by_updated_at__returns_in_ascending_order(
Comment thread
Ahalya-ni marked this conversation as resolved.
Outdated
self, client: SpecClient, create_specs, product
):
# Create two specs, then update the first so it has a later updated_at than the second.
spec_1_id = uuid.uuid1().hex
spec_2_id = uuid.uuid1().hex
response = create_specs(
CreateSpecificationsRequest(
specs=[
CreateSpecificationsRequestObject(
product_id=product,
spec_id=spec_1_id,
type=SpecificationType.FUNCTIONAL,
),
CreateSpecificationsRequestObject(
product_id=product,
spec_id=spec_2_id,
type=SpecificationType.FUNCTIONAL,
),
]
)
)
spec_1 = next(
spec for spec in response.created_specs if spec.spec_id == spec_1_id
)
update_response = client.update_specs(
UpdateSpecificationsRequest(
specs=[
UpdateSpecificationsRequestObject(
id=spec_1.id,
product_id=spec_1.product_id,
spec_id=spec_1.spec_id,
type=SpecificationType.PARAMETRIC,
version=spec_1.version,
workspace=spec_1.workspace,
)
]
)
)
assert update_response
assert update_response.updated_specs
assert len(update_response.updated_specs) == 1

request = QuerySpecificationsRequest(
product_ids=[product],
order_by=SpecificationOrderBy.UPDATED_AT,
order_by_descending=False,
)
response = client.query_specs(request)

assert response.specs
# spec_2 was not updated, so it has an earlier updated_at — must come first
assert response.specs[0].spec_id == spec_2_id
assert response.specs[1].spec_id == spec_1_id

def test__query_specs_order_by_updated_at_descending__returns_in_descending_order(
self, client: SpecClient, create_specs, product
):
spec_1_id = uuid.uuid1().hex
spec_2_id = uuid.uuid1().hex
response = create_specs(
CreateSpecificationsRequest(
specs=[
CreateSpecificationsRequestObject(
product_id=product,
spec_id=spec_1_id,
type=SpecificationType.FUNCTIONAL,
),
CreateSpecificationsRequestObject(
product_id=product,
spec_id=spec_2_id,
type=SpecificationType.FUNCTIONAL,
),
]
)
)
spec_1 = next(
spec for spec in response.created_specs if spec.spec_id == spec_1_id
)
update_response = client.update_specs(
UpdateSpecificationsRequest(
specs=[
UpdateSpecificationsRequestObject(
id=spec_1.id,
product_id=spec_1.product_id,
spec_id=spec_1.spec_id,
type=SpecificationType.PARAMETRIC,
version=spec_1.version,
workspace=spec_1.workspace,
)
]
)
)
assert update_response
assert update_response.updated_specs
assert len(update_response.updated_specs) == 1

request = QuerySpecificationsRequest(
product_ids=[product],
order_by=SpecificationOrderBy.UPDATED_AT,
order_by_descending=True,
)
response = client.query_specs(request)

assert response.specs
# spec_1 was updated last, so it has a later updated_at — must come first
assert response.specs[0].spec_id == spec_1_id
assert response.specs[1].spec_id == spec_2_id
Loading