-
Notifications
You must be signed in to change notification settings - Fork 32
feat: Add Client for Workorders service Test plans and Test plan template APIs #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MuthuRajan-S
merged 77 commits into
ni:master
from
aravindhan-ni:users/ammar/feat/test_plan_template_api
May 28, 2025
Merged
Changes from 17 commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
525c770
added boiler plate for test plan client
ebfc90f
users/ammar/feat/testplan
f09ab69
add testplans api client and models
0ebc4a5
update request model name
95053ad
test setup
5d96899
add create test
8eca2b3
lint
e9dfe5d
fix test
39630d8
test try 1
703d060
test try 1
881a44d
draft implementation
db0d53a
moved test plan to integration folder
d52edd6
Merge branch 'users/ammar/feat/testplan' of https://github.com/aravin…
5e2699e
lint
a08df7d
add tests
535ffd1
Merge branch 'users/ammar/feat/testplan' of https://github.com/aravin…
6100544
added rest of test cases
293d185
added documentation
10c8d8b
updated documentation
0298403
updated nit changes
0b8fa56
added comments in init files
99d7d9e
resolved comments
d93bbac
added documentation for test plan template
a10a6b6
update test
1b4b88c
update lint
3a63524
add query projection
1977508
fix lint
94054e9
Merge branch 'users/ammar/feat/testplan' of https://github.com/aravin…
bae388d
add query projection
dd9cd31
Merge branch 'users/ammar/feat/testplan' of https://github.com/aravin…
de1909d
lint
f74c454
add docs
ac8e9a0
lint
dc12eba
Merge branch 'users/ammar/feat/testplan' of https://github.com/aravin…
2b2f2b9
lint
5405c0f
add example
fdbaa5e
refactor
883ea06
updated implementation
cf34f10
refactor
54445cd
refactor
585f0b9
enum update
3ee9e7a
query request refactor
7c77939
test constant update
32f6f8a
resolving PR comments
aca8441
add api errors
557c4d8
Merge pull request #3 from aravindhan-ni/users/arvin/feat/testplan/te…
aravindhan-ni a62104c
update as per comment
06671e0
Merge branch 'users/ammar/feat/testplan' of https://github.com/aravin…
89aa933
added test plan module
5697644
refactor test plan api
15572cc
resolved comments
2231a4a
refactor file names
82de1be
update comment
42f8271
update test constant
a640feb
update test constant
d22d4c1
update test
09768cf
update constant
ce85d2a
refactor
8969220
update docs
1bff3b4
fix warnings
6915830
try example fail fix
5d080f4
lint
f2aa651
update execution actions
0fd415b
update run test py setup
cd55dd3
Update tests test name
aravindhan-ni 142dfd4
lint and update exports
1f8d98b
Merge branch 'users/ammar/feat/test_plan_template_api' of https://git…
f34f0fb
refactor
2a8aed1
Merge branch 'master' of https://github.com/aravindhan-ni/nisystemlin…
8fc290c
Merge branch 'master' of https://github.com/aravindhan-ni/nisystemlin…
6431f9a
Create main.yml
aravindhan-ni 7bcf337
Merge branch 'master' of https://github.com/aravindhan-ni/nisystemlin…
ef4704f
remove workflow
0f2db44
refactor
009b54b
Merge branch 'ni:master' into master
aravindhan-ni d884e7d
Merge branch 'master' of https://github.com/aravindhan-ni/nisystemlin…
732af5f
add comment to usage of workspace
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .. _api_tag_page: | ||
|
|
||
| nisystemlink.clients.test_plan.test_plan_templates | ||
| ====================== | ||
|
|
||
| .. autoclass:: nisystemlink.clients.test_plan.test_plan_templates.TestPlanTemplateClient | ||
| :exclude-members: __init__ | ||
|
|
||
| .. automethod:: __init__ | ||
| .. automethod:: create_test_plan_templates | ||
| .. automethod:: query_test_plan_templates | ||
| .. automethod:: delete_test_plan_templates | ||
|
|
||
| .. automodule:: nisystemlink.clients.test_plan.test_plan_templates.models | ||
| :members: | ||
| :imported-members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
examples/test_plan/test_plan_templates/test_plan_templates.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from nisystemlink.clients.core._http_configuration import HttpConfiguration | ||
| from nisystemlink.clients.test_plan.models._execution_definition import ManualExecution | ||
| from nisystemlink.clients.test_plan.test_plan_templates._test_plan_templates_client import ( | ||
| TestPlanTemplateClient, | ||
| ) | ||
| from nisystemlink.clients.test_plan.test_plan_templates.models._query_test_plan_templates_request import ( | ||
| QueryTestPlanTemplatesRequest, | ||
| ) | ||
| from nisystemlink.clients.test_plan.test_plan_templates.models._test_plan_templates import ( | ||
| TestPlanTemplateBase, | ||
| ) | ||
|
|
||
| # Setup the server configuration to point to your instance of SystemLink Enterprise | ||
| server_configuration = HttpConfiguration( | ||
| server_uri="https://yourserver.yourcompany.com", | ||
| api_key="YourAPIKeyGeneratedFromSystemLink", | ||
| ) | ||
| client = TestPlanTemplateClient(configuration=server_configuration) | ||
|
|
||
| # Test plan template request metadata | ||
| create_test_plan_template_request = [ | ||
| TestPlanTemplateBase( | ||
| name="Python integration test plan template", | ||
| templateGroup="sample template group", | ||
| workspace="33eba2fe-fe42-48a1-a47f-a6669479a8aa", | ||
| executionActions=[ManualExecution(action="TEST", type="MANUAl")], | ||
| ) | ||
| ] | ||
|
|
||
| # Create a test plan template | ||
| create_test_plan_template_response = client.create_test_plan_templates( | ||
| test_plan_templates=create_test_plan_template_request | ||
| ) | ||
|
|
||
| create_test_plan_template_id = None | ||
|
|
||
| if ( | ||
| create_test_plan_template_response.created_test_plan_templates | ||
| and create_test_plan_template_response.created_test_plan_templates[0].id | ||
| ): | ||
| create_test_plan_template_id = str( | ||
| create_test_plan_template_response.created_test_plan_templates[0].id | ||
| ) | ||
|
|
||
| # Query test plan templates using id | ||
| query_test_plan_template_request = QueryTestPlanTemplatesRequest( | ||
| filter=f'id="{create_test_plan_template_id}"', take=1 | ||
| ) | ||
|
|
||
| client.query_test_plan_templates( | ||
| query_test_plan_templates=query_test_plan_template_request | ||
| ) | ||
|
|
||
| # Delete the created test plan template. | ||
| if create_test_plan_template_id is not None: | ||
| client.delete_test_plan_templates(ids=[create_test_plan_template_id]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # flake8: noqa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from ._execution_definition import ExecutionDefinition | ||
|
|
||
| # flake8: noqa |
95 changes: 95 additions & 0 deletions
95
nisystemlink/clients/test_plan/models/_execution_definition.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| from typing import List, Union | ||
|
|
||
| from nisystemlink.clients.core._uplink._json_model import JsonModel | ||
|
|
||
|
|
||
| class Job(JsonModel): | ||
| """Represents a job to be executed, including its functions, arguments, and metadata.""" | ||
|
|
||
| functions: List[str] | ||
| """List of function names to execute.""" | ||
|
|
||
| arguments: List[List[object]] | ||
| """List of argument lists for each function.""" | ||
|
|
||
| metadata: dict[str, object] | ||
| """Additional metadata for the job.""" | ||
|
|
||
|
|
||
| class NotebookExecution(JsonModel): | ||
| """Defines the execution of a notebook.""" | ||
|
|
||
| action: str | ||
| """User defined action to perform in workflow (user defined).""" | ||
|
|
||
| type: str = "NOTEBOOK" | ||
| """Type of execution, default is 'NOTEBOOK'.""" | ||
|
|
||
| notebookId: str | ||
| """ID of the notebook to execute.""" | ||
|
|
||
|
|
||
| class ManualExecution(JsonModel): | ||
| """Represents a manual execution definition.""" | ||
|
|
||
| action: str | ||
| """User defined action to perform in workflow (user defined).""" | ||
|
|
||
| type: str = "MANUAL" | ||
| """Type of execution, default is 'MANUAL'.""" | ||
|
|
||
|
|
||
| class JobExecution(JsonModel): | ||
| """Defines the execution of one or more jobs.""" | ||
|
|
||
| action: str | ||
| """User defined action to perform in workflow (user defined).""" | ||
|
|
||
| type: str = "JOB" | ||
| """Type of execution, default is 'JOB'.""" | ||
|
|
||
| jobs: List[Job] | ||
| """List of jobs to execute.""" | ||
|
|
||
| systemId: str | None = None | ||
| """Optional system ID where jobs will run.""" | ||
|
|
||
|
|
||
| class ScheduleExecution(JsonModel): | ||
| """Represents a scheduled execution definition.""" | ||
|
|
||
| action: str | ||
| """User defined action to perform in workflow (user defined).""" | ||
|
|
||
| type: str = "SCHEDULE" | ||
| """Type of execution, default is 'SCHEDULE'.""" | ||
|
|
||
|
|
||
| class UnscheduleExecution(JsonModel): | ||
| """Represents an unscheduled execution definition.""" | ||
|
|
||
| action: str | ||
| """User defined action to perform in workflow (user defined).""" | ||
|
|
||
| type: str = "UNSCHEDULE" | ||
| """Type of execution, default is 'UNSCHEDULE'.""" | ||
|
|
||
|
|
||
| class NoneExecution(JsonModel): | ||
| """Represents a definition where no execution is specified.""" | ||
|
|
||
| action: str | ||
| """User defined action to perform in workflow (user defined).""" | ||
|
|
||
| type: str = "None" | ||
| """Type of execution, default is 'None'.""" | ||
|
|
||
|
|
||
| ExecutionDefinition = Union[ | ||
|
ammarhusain-EMR marked this conversation as resolved.
Outdated
|
||
| NotebookExecution, | ||
| ManualExecution, | ||
| JobExecution, | ||
| NoneExecution, | ||
| ScheduleExecution, | ||
| UnscheduleExecution, | ||
| ] | ||
5 changes: 5 additions & 0 deletions
5
nisystemlink/clients/test_plan/test_plan_templates/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from nisystemlink.clients.test_plan.test_plan_templates._test_plan_templates_client import ( | ||
| TestPlanTemplateClient, | ||
| ) | ||
|
|
||
| # flake8: noqa |
110 changes: 110 additions & 0 deletions
110
nisystemlink/clients/test_plan/test_plan_templates/_test_plan_templates_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """Implementation of Test plan template Client""" | ||
|
|
||
| from typing import List, Optional | ||
|
|
||
| from nisystemlink.clients import core | ||
| from nisystemlink.clients.core._uplink._base_client import BaseClient | ||
| from nisystemlink.clients.core._uplink._methods import post | ||
| from uplink import Field, retry | ||
|
|
||
| from . import models | ||
|
|
||
|
|
||
| @retry( | ||
| when=retry.when.status(408, 429, 502, 503, 504), | ||
| stop=retry.stop.after_attempt(5), | ||
| on_exception=retry.CONNECTION_ERROR, | ||
| ) | ||
| class TestPlanTemplateClient(BaseClient): | ||
|
ammarhusain-EMR marked this conversation as resolved.
Outdated
|
||
| def __init__(self, configuration: Optional[core.HttpConfiguration] = None): | ||
| """Initialize an instance. | ||
|
|
||
| Args: | ||
| configuration: Defines the web server to connect to and information about | ||
| how to connect. If not provided, the | ||
| :class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>` | ||
| is used to obtain the configuration. | ||
|
|
||
| Raises: | ||
| ApiException: if unable to communicate with the `/niworkorder` Service. | ||
| """ | ||
| if configuration is None: | ||
| configuration = core.HttpConfigurationManager.get_configuration() | ||
| super().__init__(configuration, base_path="/niworkorder/v1/") | ||
|
|
||
| @post("testplan-templates", args=[Field("testPlanTemplates")]) | ||
| def create_test_plan_templates( | ||
| self, test_plan_templates: List[models.TestPlanTemplateBase] | ||
| ) -> models.CreateTestPlanTemplatePartialSuccessResponse: | ||
| """Creates one or more test plan template and return errors for failed creations. | ||
|
|
||
| Args: | ||
| test_plan_templates: A list of test plan templates to attempt to create. | ||
|
|
||
| Returns: A list of created test plan templates, test plan templates that failed to create, and errors for | ||
| failures. | ||
|
|
||
| Raises: ApiException: if unable to communicate with the `/niworkorder` service of provided invalid | ||
| arguments. | ||
| """ | ||
| ... | ||
|
|
||
| @post("query-testplan-templates") | ||
| def __query_test_plan_templates( | ||
| self, query_test_plan_templates: models._QueryTestPlanTemplatesRequest | ||
| ) -> models.QueryTestPlanTemplatesResponse: | ||
| """Queries one or more test plan templates and return errors for failed queries. | ||
|
|
||
| Returns: A list of test plan templates, based on the query and errors for the wrong query. | ||
|
|
||
| Raises: ApiException: if unable to communicate with the `/niworkorder` service of provided invalid | ||
| arguments. | ||
| """ | ||
| ... | ||
|
|
||
| def query_test_plan_templates( | ||
| self, query_test_plan_templates: models.QueryTestPlanTemplatesRequest | ||
| ) -> models.QueryTestPlanTemplatesResponse: | ||
| """Queries one or more test plan templates and return errors for failed queries. | ||
|
|
||
| Returns: A list of test plan templates, based on the query and errors for the wrong query. | ||
|
|
||
| Raises: ApiException: if unable to communicate with the `/niworkorder` service of provided invalid | ||
| arguments. | ||
| """ | ||
| projection_str = ( | ||
| [projection.name for projection in query_test_plan_templates.projection] | ||
| if query_test_plan_templates.projection | ||
| else None | ||
| ) | ||
| query_params = { | ||
| "filter": query_test_plan_templates.filter, | ||
| "take": query_test_plan_templates.take, | ||
| "substitutions": query_test_plan_templates.substitutions, | ||
| "continuationToken": query_test_plan_templates.continuation_token, | ||
| "orderBy": query_test_plan_templates.order_by, | ||
| "descending": query_test_plan_templates.descending, | ||
| "projection": projection_str, | ||
| } | ||
|
|
||
| query_params = {k: v for k, v in query_params.items() if v is not None} | ||
|
|
||
| query_request = models._QueryTestPlanTemplatesRequest(**query_params) | ||
|
|
||
| print(query_request) | ||
|
ammarhusain-EMR marked this conversation as resolved.
Outdated
|
||
| return self.__query_test_plan_templates(query_test_plan_templates=query_request) | ||
|
|
||
| @post("delete-testplan-templates", args=[Field("ids")]) | ||
| def delete_test_plan_templates( | ||
| self, ids: List[str] | ||
| ) -> Optional[models.DeleteTestPlanTemplatesPartialSuccessResponse]: | ||
| """Deletes one or more test plan templates and return errors for failed deletion. | ||
|
|
||
| Returns: | ||
| A partial success if any test plan templates failed to delete, or None if all | ||
| test plan templates were deleted successfully. | ||
|
|
||
| Raises: ApiException: if unable to communicate with the `/niworkorder` service of provided invalid | ||
| arguments. | ||
| """ | ||
| ... | ||
20 changes: 20 additions & 0 deletions
20
nisystemlink/clients/test_plan/test_plan_templates/models/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from nisystemlink.clients.test_plan.test_plan_templates.models._create_test_plan_templates_partial_success_response import ( | ||
| CreateTestPlanTemplatePartialSuccessResponse, | ||
| ) | ||
| from nisystemlink.clients.test_plan.test_plan_templates.models._query_test_plan_templates_request import ( | ||
| QueryTestPlanTemplatesRequest, | ||
| _QueryTestPlanTemplatesRequest, | ||
| TestPlanTemplateField, | ||
| ) | ||
| from nisystemlink.clients.test_plan.test_plan_templates.models._query_test_plan_templates_response import ( | ||
| QueryTestPlanTemplatesResponse, | ||
| ) | ||
| from nisystemlink.clients.test_plan.test_plan_templates.models._delete_test_plan_templates_partial_success_response import ( | ||
| DeleteTestPlanTemplatesPartialSuccessResponse, | ||
| ) | ||
| from nisystemlink.clients.test_plan.test_plan_templates.models._test_plan_templates import ( | ||
| TestPlanTemplateBase, | ||
| TestPlanTemplateResponse, | ||
| ) | ||
|
|
||
| # flake8: noqa |
24 changes: 24 additions & 0 deletions
24
...t_plan/test_plan_templates/models/_create_test_plan_templates_partial_success_response.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from typing import List, Optional | ||
|
|
||
| from nisystemlink.clients.core._api_error import ApiError | ||
| from nisystemlink.clients.core._uplink._json_model import JsonModel | ||
|
|
||
| from ._test_plan_templates import TestPlanTemplateBase, TestPlanTemplateResponse | ||
|
|
||
|
|
||
| class CreateTestPlanTemplatePartialSuccessResponse(JsonModel): | ||
|
|
||
| created_test_plan_templates: Optional[List[TestPlanTemplateResponse]] = None | ||
| """The list of test plan templates that were successfully created.""" | ||
|
|
||
| failed_test_plan_templates: Optional[List[TestPlanTemplateBase]] = None | ||
|
ammarhusain-EMR marked this conversation as resolved.
Outdated
|
||
| """The list of test plan templates that were not created. | ||
|
|
||
| If this is `None`, then all test plan templates were successfully created. | ||
| """ | ||
|
|
||
| error: Optional[ApiError] = None | ||
| """Error messages for test plan templates that were not created. | ||
|
|
||
| If this is `None`, then all test plan templates were successfully created. | ||
| """ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.