-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36cb9f4
commit dbb9055
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,23 @@ | ||
.. _api_tag_page: | ||
|
||
nisystemlink.clients.result | ||
====================== | ||
|
||
.. autoclass:: nisystemlink.clients.result.ResultClient | ||
:exclude-members: __init__ | ||
|
||
.. automethod:: __init__ | ||
.. automethod:: create_results | ||
.. automethod:: get_results | ||
.. automethod:: query_results | ||
.. automethod:: query_result_values | ||
.. automethod:: update_results | ||
.. automethod:: delete_result | ||
.. automethod:: delete_results | ||
|
||
.. automodule:: nisystemlink.clients.result.models | ||
:members: | ||
:imported-members: | ||
|
||
.. automodule:: nisystemlink.clients.result.utilities | ||
:members: |
This file contains 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 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,87 @@ | ||
from nisystemlink.clients.core import HttpConfiguration | ||
from nisystemlink.clients.result import ResultClient | ||
from nisystemlink.clients.result.models import ( | ||
QueryResultsRequest, | ||
QueryResultValuesRequest, | ||
Result, | ||
ResultField, | ||
StatusObject, | ||
StatusType, | ||
) | ||
|
||
program_name = "Example Name" | ||
host_name = "Example Host" | ||
|
||
|
||
def create_some_results(): | ||
"""Create two example results on your server.""" | ||
new_results = [ | ||
Result( | ||
part_number="Example 123 AA", | ||
program_name=program_name, | ||
host_name=host_name, | ||
status=StatusObject(status_type=StatusType.PASSED, status_name="Passed"), | ||
keywords=["original keyword"], | ||
properties={"original property key": "yes"}, | ||
), | ||
Result( | ||
part_number="Example 123 AA1", | ||
program_name=program_name, | ||
host_name=host_name, | ||
status=StatusObject(status_type=StatusType.FAILED, status_name="Failed"), | ||
keywords=["original keyword"], | ||
properties={"original property key": "original"}, | ||
), | ||
] | ||
create_response = client.create_results(new_results) | ||
return create_response | ||
|
||
|
||
# Setup the server configuration to point to your instance of SystemLink Enterprise | ||
server_configuration = HttpConfiguration( | ||
server_uri="https://dev-api.lifecyclesolutions.ni.com", | ||
api_key="30IUOX8btHdgziA8hgya502zVH8wp2tWGEDH-yMaF6", | ||
) | ||
client = ResultClient(configuration=server_configuration) | ||
|
||
# Get all the results using the continuation token in batches of 100 at a time. | ||
response = client.get_results(take=100, return_count=True) | ||
all_results = response.results | ||
while response.continuation_token: | ||
response = client.get_results( | ||
take=100, continuation_token=response.continuation_token, return_count=True | ||
) | ||
all_results.extend(response.results) | ||
|
||
create_response = create_some_results() | ||
|
||
# use get for first result created | ||
created_result = client.get_result(create_response.results[0].id) | ||
|
||
# Query results without continuation | ||
query_request = QueryResultsRequest( | ||
filter=f'programName="{program_name}" && hostName="{host_name}"', | ||
return_count=True, | ||
order_by=ResultField.HOST_NAME, | ||
) | ||
response = client.query_results(query_request) | ||
|
||
# Update the first result that you just created and replace the keywords | ||
updated_result = create_response.results[0] | ||
updated_result.keywords = ["new keyword"] | ||
updated_result.properties = {"new property key": "new value"} | ||
update_response = client.update_results([create_response.results[0]], replace=True) | ||
|
||
# Query for just the ids of results that match the family | ||
values_query = QueryResultValuesRequest( | ||
filter=f'programName="{program_name}"', field=ResultField.ID | ||
) | ||
values_response = client.query_result_values(query=values_query) | ||
|
||
# delete each created result individually by id | ||
for result in create_response.results: | ||
client.delete_result(result.id) | ||
|
||
# Create some more and delete them with a single call to delete. | ||
create_response = create_some_results() | ||
client.delete_results([result.id for result in create_response.results]) |