Skip to content

Commit 883ea06

Browse files
author
Ammar Husain Mian Fazulul
committed
updated implementation
1 parent 2b2f2b9 commit 883ea06

File tree

5 files changed

+86
-38
lines changed

5 files changed

+86
-38
lines changed

nisystemlink/clients/test_plan/test_plan_templates/_test_plan_templates_client.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
from typing import List, Optional
44

55
from nisystemlink.clients import core
6-
7-
from uplink import Field, retry
8-
96
from nisystemlink.clients.core._uplink._base_client import BaseClient
10-
117
from nisystemlink.clients.core._uplink._methods import post
8+
from uplink import Field, retry
129

1310
from . import models
1411

@@ -53,6 +50,18 @@ def create_test_plan_templates(
5350
...
5451

5552
@post("query-testplan-templates")
53+
def __query_test_plan_templates(
54+
self, query_test_plan_templates: models._QueryTestPlanTemplatesRequest
55+
) -> models.QueryTestPlanTemplatesResponse:
56+
"""Queries one or more test plan templates and return errors for failed queries.
57+
58+
Returns: A list of test plan templates, based on the query and errors for the wrong query.
59+
60+
Raises: ApiException: if unable to communicate with the `/niworkorder` service of provided invalid
61+
arguments.
62+
"""
63+
...
64+
5665
def query_test_plan_templates(
5766
self, query_test_plan_templates: models.QueryTestPlanTemplatesRequest
5867
) -> models.QueryTestPlanTemplatesResponse:
@@ -63,7 +72,27 @@ def query_test_plan_templates(
6372
Raises: ApiException: if unable to communicate with the `/niworkorder` service of provided invalid
6473
arguments.
6574
"""
66-
...
75+
projection_str = (
76+
[projection.name for projection in query_test_plan_templates.projection]
77+
if query_test_plan_templates.projection
78+
else None
79+
)
80+
query_params = {
81+
"filter": query_test_plan_templates.filter,
82+
"take": query_test_plan_templates.take,
83+
"substitutions": query_test_plan_templates.substitutions,
84+
"continuationToken": query_test_plan_templates.continuation_token,
85+
"orderBy": query_test_plan_templates.order_by,
86+
"descending": query_test_plan_templates.descending,
87+
"projection": projection_str,
88+
}
89+
90+
query_params = {k: v for k, v in query_params.items() if v is not None}
91+
92+
query_request = models._QueryTestPlanTemplatesRequest(**query_params)
93+
94+
print(query_request)
95+
return self.__query_test_plan_templates(query_test_plan_templates=query_request)
6796

6897
@post("delete-testplan-templates", args=[Field("ids")])
6998
def delete_test_plan_templates(

nisystemlink/clients/test_plan/test_plan_templates/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
)
44
from nisystemlink.clients.test_plan.test_plan_templates.models._query_test_plan_templates_request import (
55
QueryTestPlanTemplatesRequest,
6+
_QueryTestPlanTemplatesRequest,
67
TestPlanTemplateField,
78
)
89
from nisystemlink.clients.test_plan.test_plan_templates.models._query_test_plan_templates_response import (

nisystemlink/clients/test_plan/test_plan_templates/models/_query_test_plan_templates_request.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ class TestPlanTemplateOrderBy(str, Enum):
1616

1717

1818
class TestPlanTemplateField(str, Enum):
19-
ID = "id"
20-
NAME = "name"
21-
TEMPLATE_GROUP = "templateGroup"
22-
PRODUCT_FAMILIES = "productFamilies"
23-
PART_NUMBERS = "partNumbers"
24-
SUMMARY = "summary"
25-
DESCRIPTION = "description"
26-
TEST_PROGRAM = "testProgram"
27-
ESTIMATED_DURATION_IN_SECONDS = "estimatedDurationInSeconds"
28-
SYSTEM_FILTER = "systemFilter"
29-
EXECUTION_ACTIONS = "executionActions"
30-
FILE_IDS = "fileIds"
31-
WORKSPACE = "workspace"
32-
PROPERTIES = "properties"
33-
DASHBOARD = "dashboard"
19+
ID = enum.auto()
20+
NAME = enum.auto()
21+
TEMPLATE_GROUP = enum.auto()
22+
PRODUCT_FAMILIES = enum.auto()
23+
PART_NUMBERS = enum.auto()
24+
SUMMARY = enum.auto()
25+
DESCRIPTION = enum.auto()
26+
TEST_PROGRAM = enum.auto()
27+
ESTIMATED_DURATION_IN_SECONDS = enum.auto()
28+
SYSTEM_FILTER = enum.auto()
29+
EXECUTION_ACTIONS = enum.auto()
30+
FILE_IDS = enum.auto()
31+
WORKSPACE = enum.auto()
32+
PROPERTIES = enum.auto()
33+
DASHBOARD = enum.auto()
34+
CREATED_BY = enum.auto()
35+
UPDATED_BY = enum.auto()
36+
CREATED_AT = enum.auto()
37+
UPDATED_AT = enum.auto()
3438

3539

3640
class QueryTestPlanTemplatesRequest(JsonModel):
@@ -75,6 +79,14 @@ class QueryTestPlanTemplatesRequest(JsonModel):
7579
order_by: Optional[TestPlanTemplateOrderBy] = None
7680
"""Field by which test plan templates can be ordered/sorted."""
7781

82+
substitutions: Optional[List[str]] = None
83+
"""Makes substitutions in the query filter expression
84+
using non-negative integers. These integers
85+
use the @ symbol as a prefix. The filter
86+
expression replaces each substitution
87+
with the element at the corresponding
88+
index in this list. The index is zero-based."""
89+
7890
descending: Optional[bool] = None
7991
"""Whether to return the test plan templates in the descending order. By default, test plan
8092
templates are sorted in the ascending order."""
@@ -141,6 +153,14 @@ class _QueryTestPlanTemplatesRequest(JsonModel):
141153
order_by: Optional[TestPlanTemplateOrderBy] = None
142154
"""Field by which test plan templates can be ordered/sorted."""
143155

156+
substitutions: Optional[List[str]] = None
157+
"""Makes substitutions in the query filter expression
158+
using non-negative integers. These integers
159+
use the @ symbol as a prefix. The filter
160+
expression replaces each substitution
161+
with the element at the corresponding
162+
index in this list. The index is zero-based."""
163+
144164
descending: Optional[bool] = None
145165
"""Whether to return the test plan templates in the descending order. By default, test plan
146166
templates are sorted in the ascending order."""
@@ -149,7 +169,7 @@ class _QueryTestPlanTemplatesRequest(JsonModel):
149169
"""Allows users to continue the query at the next test plan templates that matches the given
150170
criteria."""
151171

152-
projection: List[str] = []
172+
projection: Optional[List[str]] = None
153173
"""
154174
Gets or sets the projection to be used when retrieving the assets. If not specified,
155175
all properties will be returned.

nisystemlink/clients/test_plan/test_plan_templates/models/_test_plan_templates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class Dashboard(JsonModel):
2222
class TestPlanTemplateBase(JsonModel):
2323
"""Contains information about a test plan template."""
2424

25-
name: str
25+
name: str | None
2626
"""Name of the test plan template."""
2727

28-
template_group: str = None
28+
template_group: str | None = None
2929
"""The template group defined by the user."""
3030

3131
product_families: Optional[List[str]] = None
@@ -47,7 +47,7 @@ class TestPlanTemplateBase(JsonModel):
4747
"""The estimated time in seconds for executing the test plan created from this template."""
4848

4949
system_filter: Optional[str] = None
50-
"""The LINQ filter string is used to filter the potential list of
50+
"""The LINQ filter string is used to filter the potential list of
5151
systems capable of executing test plans created from this template.
5252
"""
5353

tests/integration/test_plan/test_plan_templates/test_test_plan_template.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from typing import List
22

33
import pytest
4-
54
from nisystemlink.clients.core._http_configuration import HttpConfiguration
6-
75
from nisystemlink.clients.test_plan.models._execution_definition import ManualExecution
86
from nisystemlink.clients.test_plan.test_plan_templates import TestPlanTemplateClient
97
from nisystemlink.clients.test_plan.test_plan_templates.models import (
@@ -44,12 +42,13 @@ def _create_test_plan_templates(
4442
created_test_plan_templates = (
4543
created_test_plan_templates + response.created_test_plan_templates
4644
)
47-
client.delete_test_plan_templates(
48-
ids=[
49-
test_plan_template.id
50-
for test_plan_template in created_test_plan_templates
51-
]
52-
)
45+
client.delete_test_plan_templates(
46+
ids=[
47+
test_plan_template.id
48+
for test_plan_template in created_test_plan_templates
49+
if test_plan_template.id is not None
50+
]
51+
)
5352

5453

5554
@pytest.mark.integration
@@ -110,15 +109,13 @@ def test__query_test_plan_template__returns_queried_test_plan_template(
110109

111110
assert template_id is not None
112111

112+
query = QueryTestPlanTemplatesRequest(filter=f'id="{template_id}"', take=1)
113+
113114
query_test_plan_template_response: QueryTestPlanTemplatesResponse = (
114-
client.query_test_plan_templates(
115-
query_test_plan_templates=QueryTestPlanTemplatesRequest(
116-
filter=f'id="{template_id}"', take=1
117-
)
118-
)
115+
client.query_test_plan_templates(query_test_plan_templates=query)
119116
)
120117

121-
assert len(query_test_plan_template_response.test_plan_templates) == 1
118+
assert len(query_test_plan_template_response.test_plan_templates) == 1, query
122119
assert (
123120
query_test_plan_template_response.test_plan_templates[0].id == template_id
124121
)
@@ -166,6 +163,7 @@ def test_query_test_plan_templates_with_projections__returns_test_plan_templates
166163
query = QueryTestPlanTemplatesRequest(
167164
projection=[TestPlanTemplateField.ID, TestPlanTemplateField.NAME],
168165
)
166+
print(query)
169167
response = client.query_test_plan_templates(query_test_plan_templates=query)
170168

171169
assert response is not None

0 commit comments

Comments
 (0)