-
Notifications
You must be signed in to change notification settings - Fork 31
feat: Add client for SystemLink results API #82
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
priyadarshini-ni
merged 25 commits into
ni:master
from
Madhan-Reddy-ni:users/Peram/niresults/add-results-client
Mar 5, 2025
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
36cb9f4
First Pass
Madhan-Reddy-ni dbb9055
Added the examples
Madhan-Reddy-ni c31dfc5
Removed the unnecessary changes
Madhan-Reddy-ni 5c6139f
Fix: PR Comments
Madhan-Reddy-ni a87f71d
Fix: Linting
Madhan-Reddy-ni f8f03b1
Merge branch 'master' into users/Peram/niresults/add-results-client
3124c3b
fix: resolve PR comments
5eb11bb
fix: rename file, add model
bb46743
add retry for 503, 504
a34a907
add workspace update parameter
9ac98fc
fix: lint
a70692a
remove arg for update-results
9004087
remove is_finalized
1a4abca
fix: lint
cc4dc76
fix: add updateResultRequest
cf89b0b
move the results client into testmonitor client
19a57bd
update doc
0338102
add mapping for model in test
e17912f
fix: resolve comments
06ba5e4
fix: add model for create request and partial response
e40ac37
move result example to testmonitor folder
bbf44ba
fix: nit changes, added standard status types
2b07a13
fix: type error
3b31618
fix: move status to a separate file
13894e6
add class to init
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
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,90 @@ | ||
| from nisystemlink.clients.testmonitor import TestMonitorClient | ||
| from nisystemlink.clients.testmonitor.models import ( | ||
| CreateResultRequest, | ||
| QueryResultsRequest, | ||
| QueryResultValuesRequest, | ||
| ResultField, | ||
| ResultStatus, | ||
| StandardResultStatus, | ||
| StatusType, | ||
| ) | ||
|
|
||
| program_name = "Example Name" | ||
| host_name = "Example Host" | ||
| status_type = StatusType.PASSED | ||
|
|
||
|
|
||
| def create_some_results(): | ||
| """Create two example results on your server.""" | ||
| new_results = [ | ||
| CreateResultRequest( | ||
| part_number="Example 123 AA", | ||
| program_name=program_name, | ||
| host_name=host_name, | ||
| status=StandardResultStatus.PASSED, | ||
| keywords=["original keyword"], | ||
| properties={"original property key": "yes"}, | ||
| ), | ||
| CreateResultRequest( | ||
| part_number="Example 123 AA1", | ||
| program_name=program_name, | ||
| host_name=host_name, | ||
| status=ResultStatus(status_type=StatusType.CUSTOM, status_name="Custom"), | ||
| keywords=["original keyword"], | ||
| properties={"original property key": "original"}, | ||
| ), | ||
| ] | ||
| create_response = client.create_results(new_results) | ||
| return create_response | ||
|
|
||
|
|
||
| # Server configuration is not required when used with Systemlink Client or run throught Jupyter on SLE | ||
| server_configuration = None | ||
|
|
||
| # # Example of setting up the server configuration to point to your instance of SystemLink Enterprise | ||
| # server_configuration = HttpConfiguration( | ||
| # server_uri="https://yourserver.yourcompany.com", | ||
| # api_key="YourAPIKeyGeneratedFromSystemLink", | ||
| # ) | ||
|
|
||
| client = TestMonitorClient(configuration=server_configuration) | ||
|
|
||
| create_response = create_some_results() | ||
|
|
||
| # 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) | ||
|
|
||
| # 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'status.statusType="{status_type}"', return_count=True | ||
| ) | ||
| 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]) |
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 |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| from ._api_info import Operation, V2Operations, ApiInfo | ||
| from ._result import Result, ResultStatus, StatusType, StandardResultStatus | ||
| from ._create_results_partial_success import CreateResultsPartialSuccess | ||
| from ._update_results_partial_success import UpdateResultsPartialSuccess | ||
| from ._delete_results_partial_success import DeleteResultsPartialSuccess | ||
| from ._paged_results import PagedResults | ||
| from ._create_result_request import CreateResultRequest | ||
| from ._update_result_request import UpdateResultRequest | ||
| from ._query_results_request import ( | ||
| QueryResultsRequest, | ||
| ResultField, | ||
| QueryResultValuesRequest, | ||
| ) | ||
|
|
||
| # flake8: noqa |
51 changes: 51 additions & 0 deletions
51
nisystemlink/clients/testmonitor/models/_create_result_request.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,51 @@ | ||
| from datetime import datetime | ||
| from typing import Dict, List, Optional | ||
|
|
||
| from nisystemlink.clients.core._uplink._json_model import JsonModel | ||
| from nisystemlink.clients.testmonitor.models._result import ResultStatus | ||
|
|
||
|
|
||
| class CreateResultRequest(JsonModel): | ||
| """Contains information about a result.""" | ||
|
|
||
| status: ResultStatus | ||
| """The status of the result.""" | ||
|
|
||
| started_at: Optional[datetime] | ||
| """The time that the result started.""" | ||
|
|
||
| program_name: str | ||
| """The name of the program that generated this result.""" | ||
|
|
||
| system_id: Optional[str] | ||
| """The id of the system that generated this result.""" | ||
|
|
||
| host_name: Optional[str] | ||
| """The name of the host that generated this result.""" | ||
|
|
||
| part_number: Optional[str] | ||
| """The part number is the unique identifier of a product within a single org.""" | ||
|
|
||
| serial_number: Optional[str] | ||
| """The serial number of the system that generated this result.""" | ||
|
|
||
| total_time_in_seconds: Optional[float] | ||
| """The total time that the result took to run in seconds.""" | ||
|
|
||
| keywords: Optional[List[str]] | ||
| """A list of keywords that categorize this result.""" | ||
|
|
||
| properties: Optional[Dict[str, str]] | ||
| """A list of custom properties for this result.""" | ||
|
|
||
| operator: Optional[str] | ||
| """The operator that ran the result.""" | ||
|
|
||
| file_ids: Optional[List[str]] | ||
| """A list of file ids that are attached to this result.""" | ||
|
|
||
| data_table_ids: Optional[List[str]] | ||
| """A list of data table ids that are attached to this result.""" | ||
|
|
||
| workspace: Optional[str] | ||
| """The id of the workspace that this product belongs to.""" |
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.