Skip to content

Commit b1ebf7c

Browse files
vishnu-niVishnu Govindaraj
andauthored
feat: Spec client | Add Get Spec API (#147)
Signed-off-by: Vishnu Govindaraj <[email protected]> Co-authored-by: Vishnu Govindaraj <[email protected]>
1 parent b655593 commit b1ebf7c

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

docs/api_reference/spec.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ nisystemlink.clients.spec
1212
.. automethod:: delete_specs
1313
.. automethod:: query_specs
1414
.. automethod:: update_specs
15+
.. automethod:: get_spec
1516

1617
.. automodule:: nisystemlink.clients.spec.models
1718
:members:

docs/getting_started.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ With a :class:`.SpecClient` object, you can:
170170

171171
* Query for specifications on any fields using DynamicLinq syntax.
172172

173+
* Get a specification using an Id.
174+
173175
Examples
174176
~~~~~~~~
175177

176-
Create and Query Specifications
178+
Create, Get and Query Specifications
177179

178-
.. literalinclude:: ../examples/spec/query_specs.py
180+
.. literalinclude:: ../examples/spec/get_and_query_specs.py
179181
:language: python
180182
:linenos:
181183

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@
6868
]
6969

7070
# Create the specs on the server
71-
client.create_specs(CreateSpecificationsRequest(specs=spec_requests))
71+
created_response = client.create_specs(CreateSpecificationsRequest(specs=spec_requests))
72+
73+
# use get for first spec created
74+
if created_response.created_specs and len(created_response.created_specs) > 0:
75+
created_spec = client.get_spec(created_response.created_specs[0].id)
7276

7377
# You can query specs based on any field using DynamicLinq syntax.
7478
# These are just some representative examples.

nisystemlink/clients/spec/_spec_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ def query_specs(
9696
"""
9797
...
9898

99+
@get("specs/{id}")
100+
def get_spec(self, id: str) -> models.Specification:
101+
"""Retrieves a single spec by id.
102+
103+
Args:
104+
id (str): Unique ID of a specification.
105+
106+
Returns:
107+
The single spec matching `id`
108+
109+
Raises:
110+
ApiException: if unable to communicate with the `nispec` service or if there are invalid
111+
arguments.
112+
"""
113+
...
114+
99115
@post("update-specs")
100116
def update_specs(
101117
self, specs: models.UpdateSpecificationsRequest

tests/integration/spec/test_spec.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List
33

44
import pytest
5+
from nisystemlink.clients.core._api_exception import ApiException
56
from nisystemlink.clients.core._http_configuration import HttpConfiguration
67
from nisystemlink.clients.spec import SpecClient
78
from nisystemlink.clients.spec.models import (
@@ -237,6 +238,39 @@ def test__update_single_same_version__version_updates(
237238
updated_spec = update_response.updated_specs[0]
238239
assert updated_spec.version == 1
239240

241+
def test__get_spec_by_id__spec_matches_expected(
242+
self, client: SpecClient, create_specs, product
243+
):
244+
productId = product
245+
spec = CreateSpecificationsRequestObject(
246+
product_id=productId,
247+
spec_id="spec1",
248+
type=SpecificationType.FUNCTIONAL,
249+
keywords=["work", "reviewed"],
250+
category="Parametric Specs",
251+
block="newBlock",
252+
)
253+
254+
response = create_specs(CreateSpecificationsRequest(specs=[spec]))
255+
256+
assert response is not None
257+
assert len(response.created_specs) == 1
258+
created_spec = response.created_specs[0]
259+
260+
get_spec_response = client.get_spec(created_spec.id)
261+
262+
assert get_spec_response is not None
263+
assert get_spec_response.id == created_spec.id
264+
assert get_spec_response.product_id == productId
265+
266+
def test__get_non_existant_spec_by_id__get_spec_fails(self, client: SpecClient):
267+
non_existant_spec_id = "10"
268+
269+
with pytest.raises(ApiException) as exception_info:
270+
client.get_spec(non_existant_spec_id)
271+
272+
assert exception_info.value.http_status_code == 404
273+
240274
def test__query_product__all_returned(
241275
self, client: SpecClient, create_specs, create_specs_for_query, product
242276
):

0 commit comments

Comments
 (0)