Skip to content

Commit 06671e0

Browse files
author
Ammar Husain Mian Fazulul
committed
Merge branch 'users/ammar/feat/testplan' of https://github.com/aravindhan-ni/nisystemlink-clients-python into users/ammar/feat/test_plan_template_api
2 parents a62104c + 557c4d8 commit 06671e0

26 files changed

+1132
-0
lines changed

docs/api_reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ API Reference
1616
api_reference/file
1717
api_reference/notebook
1818
api_reference/feeds
19+
api_reference/test_plan
1920
api_reference/test_plan_templates
2021

2122
Indices and tables

docs/api_reference/test_plan.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. _api_tag_page:
2+
3+
nisystemlink.clients.test_plan.test_plan
4+
======================
5+
6+
.. autoclass:: nisystemlink.clients.test_plan.test_plan.TestPlanClient
7+
:exclude-members: __init__
8+
9+
.. automethod:: __init__
10+
.. automethod:: create_test_plans
11+
.. automethod:: delete_test_plans
12+
.. automethod:: query_test_plans
13+
.. automethod:: schedule_test_plans
14+
.. automethod:: update_test_plans
15+
.. automethod:: get_test_plan
16+
17+
.. automodule:: nisystemlink.clients.test_plan.test_plan.models
18+
:members:
19+
:imported-members:

docs/getting_started.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,32 @@ Create, query, retry, and cancel notebook executions.
321321
:language: python
322322
:linenos:
323323

324+
TestPlan API
325+
-------
326+
327+
Overview
328+
~~~~~~~~
329+
330+
The :class:`.TestPlanClient` class is the primary entry point of the TestPlan API.
331+
332+
When constructing a :class:`.TestPlanClient`, you can pass an
333+
:class:`.HttpConfiguration` (like one retrieved from the
334+
:class:`.HttpConfigurationManager`), or let :class:`.TestPlanClient` use the
335+
default connection. The default connection depends on your environment.
336+
337+
With a :class:`.TestPlanClient` object, you can:
338+
339+
* Create, query, get, update, schedule and delete TestPlans
340+
341+
Examples
342+
~~~~~~~~
343+
344+
Create, query, get, update, schedule and delete TestPlans
345+
346+
.. literalinclude:: ../examples/test_plan/test_plan/test_plans.py
347+
:language: python
348+
:linenos:
349+
324350
TestPlanTemplate API
325351
-------
326352

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from nisystemlink.clients.core._http_configuration import HttpConfiguration
2+
from nisystemlink.clients.test_plan.test_plan import TestPlanClient
3+
from nisystemlink.clients.test_plan.test_plan.models import (
4+
CreateTestPlanRequest,
5+
CreateTestPlansRequest,
6+
QueryTestPlansRequest,
7+
ScheduleTestPlanRequest,
8+
ScheduleTestPlansRequest,
9+
UpdateTestPlanRequest,
10+
UpdateTestPlansRequest,
11+
)
12+
13+
# Setup the server configuration to point to your instance of SystemLink Enterprise
14+
server_configuration = HttpConfiguration(
15+
server_uri="https://yourserver.yourcompany.com",
16+
api_key="YourAPIKeyGeneratedFromSystemLink",
17+
)
18+
client = TestPlanClient(configuration=server_configuration)
19+
20+
create_test_plans_request = CreateTestPlansRequest(
21+
testPlans=[
22+
CreateTestPlanRequest(
23+
name="Python integration test plan", state="NEW", partNumber="px40482"
24+
)
25+
]
26+
)
27+
28+
# create a test plan
29+
created_test_plans = client.create_test_plans(create_request=create_test_plans_request)
30+
31+
created_test_plan_id = created_test_plans.created_test_plans[0].id
32+
33+
# Query test plan using id.
34+
query_test_plans_request = QueryTestPlansRequest(
35+
skip=0,
36+
take=1,
37+
descending=False,
38+
returnCount=False,
39+
)
40+
client.query_test_plans(query_request=query_test_plans_request)
41+
42+
# Get test plan
43+
get_test_plan = client.get_test_plan(test_plan_id=created_test_plan_id)
44+
45+
# Update test plan
46+
update_test_plans_request = UpdateTestPlansRequest(
47+
testPlans=[
48+
UpdateTestPlanRequest(
49+
id=created_test_plan_id,
50+
name="Updated Test Plan",
51+
)
52+
]
53+
)
54+
updated_test_plan = client.update_test_plans(update_request=update_test_plans_request)
55+
56+
# Schedule the test plan
57+
schedule_test_plans_request = ScheduleTestPlansRequest(
58+
test_plans=[
59+
ScheduleTestPlanRequest(
60+
id=created_test_plan_id,
61+
planned_start_date_time="2025-05-20T15:07:42.527Z",
62+
estimated_end_date_time="2025-05-20T15:07:42.527Z",
63+
system_id="fake-system",
64+
)
65+
]
66+
)
67+
schedule_test_plan_response = client.schedule_test_plans(
68+
schedule_request=schedule_test_plans_request
69+
)
70+
71+
# Delete test plan
72+
client.delete_test_plans(ids=[created_test_plan_id])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ._test_plan_client import TestPlanClient
2+
3+
# flake8: noqa
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
from typing import Optional
2+
3+
from nisystemlink.clients import core
4+
from nisystemlink.clients.core._http_configuration import HttpConfiguration
5+
from nisystemlink.clients.core._uplink._base_client import BaseClient
6+
from nisystemlink.clients.core._uplink._methods import get, post
7+
from uplink import retry
8+
9+
from .models import (
10+
_QueryTestPlansRequest,
11+
CreateTestPlansRequest,
12+
CreateTestPlansResponse,
13+
DeleteTestPlansRequest,
14+
QueryTestPlansRequest,
15+
QueryTestPlansResponse,
16+
ScheduleTestPlansRequest,
17+
ScheduleTestPlansResponse,
18+
TestPlan,
19+
UpdateTestPlansRequest,
20+
UpdateTestPlansResponse,
21+
)
22+
23+
24+
@retry(
25+
when=retry.when.status(408, 429, 502, 503, 504),
26+
stop=retry.stop.after_attempt(5),
27+
on_exception=retry.CONNECTION_ERROR,
28+
)
29+
class TestPlanClient(BaseClient):
30+
def __init__(self, configuration: Optional[HttpConfiguration] = None):
31+
"""Initialize an instance.
32+
33+
Args:
34+
configuration: Defines the web server to connect to and information about
35+
how to connect. If not provided, the
36+
:class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>`
37+
is used to obtain the configuration.
38+
39+
Raises:
40+
ApiException: if unable to communicate with the WorkOrder Service.
41+
"""
42+
if configuration is None:
43+
configuration = core.HttpConfigurationManager.get_configuration()
44+
45+
super().__init__(configuration, base_path="/niworkorder/v1/")
46+
47+
@get("testplans/{test_plan_id}")
48+
def get_test_plan(self, test_plan_id) -> TestPlan:
49+
"""Retrieve a test plan by its ID.
50+
51+
Args:
52+
test_plan_id: The ID of the test plan to retrieve.
53+
54+
Returns:
55+
The TestPlan object corresponding to the given ID.
56+
"""
57+
...
58+
59+
@post("testplans")
60+
def create_test_plans(
61+
self, create_request: CreateTestPlansRequest
62+
) -> CreateTestPlansResponse:
63+
"""Create a new test plan.
64+
65+
Args:
66+
test_plan: The test plans to create.
67+
68+
Returns:
69+
The created test plan object.
70+
"""
71+
...
72+
73+
@post("delete-testplans")
74+
def delete_test_plans(self, ids: DeleteTestPlansRequest) -> None:
75+
"""Delete test plans by IDs.
76+
77+
Args:
78+
test_plan_ids: A list of test plan IDs to delete.
79+
80+
Returns:
81+
None
82+
"""
83+
...
84+
85+
@post("query-testplans")
86+
def __query_test_plans(
87+
self, query_request: _QueryTestPlansRequest
88+
) -> QueryTestPlansResponse:
89+
"""Query test plans.
90+
91+
Args:
92+
query: The query to execute.
93+
94+
Returns:
95+
A QueryTestPlansResponse object containing test plans that match the query.
96+
"""
97+
...
98+
99+
def query_test_plans(
100+
self, query_request: QueryTestPlansRequest
101+
) -> QueryTestPlansResponse:
102+
"""Query test plans.
103+
104+
Args:
105+
query: The query to execute.
106+
107+
Returns:
108+
A QueryTestPlansResponse object containing test plans that match the query.
109+
"""
110+
projection_str = (
111+
[projection.name for projection in query_request.projection]
112+
if query_request.projection
113+
else None
114+
)
115+
query_params = {
116+
"filter": query_request.filter,
117+
"take": query_request.take,
118+
"continuation_token": query_request.continuation_token,
119+
"order_by": query_request.order_by,
120+
"descending": query_request.descending,
121+
"return_count": query_request.return_count,
122+
"projection": projection_str,
123+
}
124+
125+
query_params = {k: v for k, v in query_params.items() if v is not None}
126+
127+
query_test_plans_request = _QueryTestPlansRequest(**query_params)
128+
129+
return self.__query_test_plans(query_request=query_test_plans_request)
130+
131+
@post("schedule-testplans")
132+
def schedule_test_plans(
133+
self, schedule_request: ScheduleTestPlansRequest
134+
) -> ScheduleTestPlansResponse:
135+
"""Schedule a test plan.
136+
137+
Args:
138+
schedule: The schedule to apply to the test plan.
139+
140+
Returns:
141+
A ScheduleTestPlansResponse object containing the scheduled test plan.
142+
"""
143+
...
144+
145+
@post("update-testplans")
146+
def update_test_plans(
147+
self, update_request: UpdateTestPlansRequest
148+
) -> UpdateTestPlansResponse:
149+
"""Update a test plan.
150+
151+
Args:
152+
test_plan: The test plan to update.
153+
154+
Returns:
155+
The updated test plan object.
156+
"""
157+
...
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from ._create_test_plans_request import CreateTestPlansRequest
2+
from ._create_test_plan_request import CreateTestPlanRequest
3+
from ._create_test_plans_response import CreateTestPlansResponse
4+
from ._schedule_test_plan_request import ScheduleTestPlanRequest
5+
from ._schedule_test_plans_response import ScheduleTestPlansResponse
6+
from ._delete_test_plans_request import DeleteTestPlansRequest
7+
from ._execution_event import ExecutionEvent
8+
from ._query_test_plans_request import (
9+
QueryTestPlansRequest,
10+
TestPlanField,
11+
_QueryTestPlansRequest,
12+
)
13+
from ._query_test_plans_response import QueryTestPlansResponse
14+
from ._schedule_test_plans_request import ScheduleTestPlansRequest
15+
from ._state import State
16+
from ._test_plan import TestPlan
17+
from ._update_test_plan_request import UpdateTestPlanRequest
18+
from ._update_test_plans_request import UpdateTestPlansRequest
19+
from ._update_test_plans_response import UpdateTestPlansResponse
20+
from ._workflow_definition import WorkflowDefinition
21+
from ._order_by import OrderBy
22+
23+
# flake8: noqa
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from typing import Dict, List, Optional
2+
3+
from nisystemlink.clients.core._uplink._json_model import JsonModel
4+
5+
from ...models._execution_definition import ExecutionDefinition
6+
7+
8+
class Dashboard(JsonModel):
9+
"""Represents a dashboard reference."""
10+
11+
id: Optional[str] = None
12+
"""ID of the dashboard"""
13+
14+
variables: Optional[Dict[str, str]] = None
15+
"""Variables for the dashboard"""
16+
17+
18+
class CreateTestPlanRequest(JsonModel):
19+
"""Represents the request body content for creating a test plan."""
20+
21+
name: Optional[str] = None
22+
"""The name of the test plan."""
23+
24+
template_id: Optional[str] = None
25+
"""The ID of the template to use for the test plan."""
26+
27+
state: Optional[str] = None
28+
"""The state of the test plan."""
29+
30+
description: Optional[str] = None
31+
"""A description of the test plan."""
32+
33+
assigned_to: Optional[str] = None
34+
"""The user or group assigned to the test plan."""
35+
36+
work_order_id: Optional[str] = None
37+
"""The work order ID associated with the test plan."""
38+
39+
estimated_duration_in_seconds: Optional[int] = None
40+
"""The estimated duration of the test plan in seconds."""
41+
42+
properties: Optional[Dict[str, str]] = None
43+
"""Additional properties for the test plan."""
44+
45+
part_number: Optional[str] = None
46+
"""The part number associated with the test plan."""
47+
48+
dut_id: Optional[str] = None
49+
"""The Device Under Test (DUT) ID."""
50+
51+
test_program: Optional[str] = None
52+
"""The test program associated with the test plan."""
53+
54+
systemtest_programfilter: Optional[str] = None
55+
"""The system filter to apply."""
56+
57+
workspace: Optional[str] = None
58+
"""The workspace associated with the test plan."""
59+
60+
file_ids_from_template: Optional[List[str]] = None
61+
"""List of file IDs from the template."""
62+
63+
dashboard: Optional[Dashboard] = None
64+
"""The dashboard associated with the test plan."""
65+
66+
execution_actions: Optional[List[ExecutionDefinition]] = None
67+
"""List of execution actions for the test plan."""

0 commit comments

Comments
 (0)