Skip to content

Commit 953686c

Browse files
ammarhusain-EMRAmmar Husain Mian FazululAravindhan Palanisamyaravindhan-nirbell517
authored
feat: Add Client for Workorders service Test plans and Test plan template APIs (#137)
Co-authored-by: Ammar Husain Mian Fazulul <[email protected]> Co-authored-by: Aravindhan Palanisamy <[email protected]> Co-authored-by: aravindhan-ni <[email protected]> Co-authored-by: Richard Bell <[email protected]>
1 parent a47aa3a commit 953686c

35 files changed

+1774
-2
lines changed

docs/api_reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ API Reference
1818
api_reference/feeds
1919
api_reference/assetmanagement
2020
api_reference/systems
21+
api_reference/test_plan
2122

2223
Indices and tables
2324
------------------

docs/api_reference/test_plan.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. _api_tag_page:
2+
3+
nisystemlink.clients.test_plan
4+
======================
5+
6+
.. autoclass:: nisystemlink.clients.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+
.. automethod:: create_test_plan_templates
17+
.. automethod:: query_test_plan_templates
18+
.. automethod:: delete_test_plan_templates
19+
20+
.. automodule:: nisystemlink.clients.test_plan.models
21+
:members:
22+
:imported-members:

docs/getting_started.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,36 @@ Create, query, and remove some systems.
372372
.. literalinclude:: ../examples/systems/systems.py
373373
:language: python
374374
:linenos:
375+
376+
TestPlan API
377+
-------
378+
379+
Overview
380+
~~~~~~~~
381+
382+
The :class:`.TestPlanClient` class is the primary entry point of the TestPlan API.
383+
384+
When constructing a :class:`.TestPlanClient`, you can pass an
385+
:class:`.HttpConfiguration` (like one retrieved from the
386+
:class:`.HttpConfigurationManager`), or let :class:`.TestPlanClient` use the
387+
default connection. The default connection depends on your environment.
388+
389+
With a :class:`.TestPlanClient` object, you can:
390+
391+
* Create, query, get, update, schedule and delete TestPlans
392+
* Create, query and delete test plan templates
393+
394+
Examples
395+
~~~~~~~~
396+
397+
Create, query, get, update, schedule and delete TestPlans
398+
399+
.. literalinclude:: ../examples/test_plan/test_plans.py
400+
:language: python
401+
:linenos:
402+
403+
Create, query and delete test plan templates.
404+
405+
.. literalinclude:: ../examples/test_plan/test_plan_templates.py
406+
:language: python
407+
:linenos:
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from nisystemlink.clients.core._http_configuration import HttpConfiguration
2+
from nisystemlink.clients.test_plan import TestPlanClient
3+
from nisystemlink.clients.test_plan.models import (
4+
CreateTestPlanTemplateRequest,
5+
Dashboard,
6+
Job,
7+
JobExecution,
8+
ManualExecution,
9+
QueryTestPlanTemplatesRequest,
10+
)
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+
# Test plan template request metadata
21+
create_test_plan_template_request = [
22+
CreateTestPlanTemplateRequest(
23+
name="Python integration test plan template",
24+
template_group="sample template group",
25+
product_families=["FamilyA", "FamilyB"],
26+
part_numbers=["PN-1001", "PN-1002"],
27+
summary="Template for running integration test plans",
28+
description="This template defines execution steps for integration workflows.",
29+
test_program="TP-INT-002",
30+
estimated_duration_in_seconds=86400,
31+
system_filter="os:linux AND arch:x64",
32+
execution_actions=[
33+
ManualExecution(action="boot", type="MANUAL"),
34+
JobExecution(
35+
action="run",
36+
type="JOB",
37+
jobs=[
38+
Job(
39+
functions=["run_test_suite"],
40+
arguments=[["test_suite.py"]],
41+
metadata={"env": "staging"},
42+
)
43+
],
44+
systemId="system-001",
45+
),
46+
],
47+
file_ids=["file1", "file2"],
48+
workspace="your_workspace_id",
49+
properties={"env": "staging", "priority": "high"},
50+
dashboard=Dashboard(
51+
id="DashBoardId", variables={"product": "PXIe-4080", "location": "Lab1"}
52+
),
53+
)
54+
]
55+
56+
# Create a test plan template
57+
create_test_plan_template_response = client.create_test_plan_templates(
58+
test_plan_templates=create_test_plan_template_request
59+
)
60+
61+
create_test_plan_template_id = None
62+
63+
if (
64+
create_test_plan_template_response.created_test_plan_templates
65+
and create_test_plan_template_response.created_test_plan_templates[0].id
66+
):
67+
create_test_plan_template_id = str(
68+
create_test_plan_template_response.created_test_plan_templates[0].id
69+
)
70+
71+
# Query test plan templates using id
72+
query_test_plan_template_request = QueryTestPlanTemplatesRequest(
73+
filter=f'id="{create_test_plan_template_id}"', take=1
74+
)
75+
76+
client.query_test_plan_templates(
77+
query_test_plan_templates=query_test_plan_template_request
78+
)
79+
80+
# Delete the created test plan template.
81+
if create_test_plan_template_id is not None:
82+
client.delete_test_plan_templates(ids=[create_test_plan_template_id])

examples/test_plan/test_plans.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from datetime import datetime
2+
3+
from nisystemlink.clients.core._http_configuration import HttpConfiguration
4+
from nisystemlink.clients.test_plan import TestPlanClient
5+
from nisystemlink.clients.test_plan.models import (
6+
CreateTestPlanRequest,
7+
Dashboard,
8+
Job,
9+
JobExecution,
10+
ManualExecution,
11+
QueryTestPlansRequest,
12+
ScheduleTestPlanRequest,
13+
ScheduleTestPlansRequest,
14+
UpdateTestPlanRequest,
15+
UpdateTestPlansRequest,
16+
)
17+
18+
# Setup the server configuration to point to your instance of SystemLink Enterprise
19+
server_configuration = HttpConfiguration(
20+
server_uri="https://yourserver.yourcompany.com",
21+
api_key="YourAPIKeyGeneratedFromSystemLink",
22+
)
23+
client = TestPlanClient(configuration=server_configuration)
24+
25+
create_test_plans_request = [
26+
CreateTestPlanRequest(
27+
name="Python integration test plan",
28+
state="NEW",
29+
description="Test plan for verifying integration flow",
30+
assigned_to="[email protected]",
31+
estimated_duration_in_seconds=86400,
32+
properties={"env": "staging", "priority": "high"},
33+
part_number="px40482",
34+
dut_id="Sample-Dut_Id",
35+
test_program="TP-Integration-001",
36+
system_filter="os:linux AND arch:x64",
37+
workspace="your_workspace_id",
38+
file_ids_from_template=["file1", "file2"],
39+
dashboard=Dashboard(
40+
id="DashBoardId", variables={"product": "PXIe-4080", "location": "Lab1"}
41+
),
42+
execution_actions=[
43+
ManualExecution(action="boot", type="MANUAL"),
44+
JobExecution(
45+
action="run",
46+
type="JOB",
47+
jobs=[
48+
Job(
49+
functions=["run_test_suite"],
50+
arguments=[["test_suite.py"]],
51+
metadata={"env": "staging"},
52+
)
53+
],
54+
systemId="system-001",
55+
),
56+
],
57+
)
58+
]
59+
60+
# create a test plan
61+
created_test_plans_response = client.create_test_plans(
62+
test_plans=create_test_plans_request
63+
)
64+
65+
if created_test_plans_response.created_test_plans:
66+
created_test_plan_id = created_test_plans_response.created_test_plans[0].id
67+
68+
# Query test plan using id.
69+
query_test_plans_request = QueryTestPlansRequest(
70+
skip=0, take=1, descending=False, returnCount=False
71+
)
72+
client.query_test_plans(query_request=query_test_plans_request)
73+
74+
# Get test plan
75+
get_test_plan = client.get_test_plan(test_plan_id=created_test_plan_id)
76+
77+
# Update test plan
78+
update_test_plans_request = UpdateTestPlansRequest(
79+
test_plans=[
80+
UpdateTestPlanRequest(
81+
id=created_test_plan_id,
82+
name="Updated Test Plan",
83+
)
84+
]
85+
)
86+
updated_test_plan = client.update_test_plans(update_request=update_test_plans_request)
87+
88+
# Schedule the test plan
89+
schedule_test_plans_request = ScheduleTestPlansRequest(
90+
test_plans=[
91+
ScheduleTestPlanRequest(
92+
id=created_test_plan_id,
93+
planned_start_date_time=datetime.strptime(
94+
"2025-05-20T15:07:42.527Z", "%Y-%m-%dT%H:%M:%S.%fZ"
95+
),
96+
estimated_end_date_time=datetime.strptime(
97+
"2025-05-22T15:07:42.527Z", "%Y-%m-%dT%H:%M:%S.%fZ"
98+
),
99+
system_id="fake-system",
100+
)
101+
]
102+
)
103+
schedule_test_plan_response = client.schedule_test_plans(
104+
schedule_request=schedule_test_plans_request
105+
)
106+
107+
# Delete test plan
108+
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

0 commit comments

Comments
 (0)