|
| 1 | +from nisystemlink.clients.testmonitor import TestMonitorClient |
| 2 | +from nisystemlink.clients.testmonitor.models import ( |
| 3 | + CreateResultRequest, |
| 4 | + QueryResultsRequest, |
| 5 | + QueryResultValuesRequest, |
| 6 | + ResultField, |
| 7 | + Status, |
| 8 | + StatusType, |
| 9 | +) |
| 10 | + |
| 11 | +program_name = "Example Name" |
| 12 | +host_name = "Example Host" |
| 13 | +status_type = StatusType.PASSED |
| 14 | + |
| 15 | + |
| 16 | +def create_some_results(): |
| 17 | + """Create two example results on your server.""" |
| 18 | + new_results = [ |
| 19 | + CreateResultRequest( |
| 20 | + part_number="Example 123 AA", |
| 21 | + program_name=program_name, |
| 22 | + host_name=host_name, |
| 23 | + status=Status.PASSED(), |
| 24 | + keywords=["original keyword"], |
| 25 | + properties={"original property key": "yes"}, |
| 26 | + ), |
| 27 | + CreateResultRequest( |
| 28 | + part_number="Example 123 AA1", |
| 29 | + program_name=program_name, |
| 30 | + host_name=host_name, |
| 31 | + status=Status(status_type=StatusType.CUSTOM, status_name="Custom"), |
| 32 | + keywords=["original keyword"], |
| 33 | + properties={"original property key": "original"}, |
| 34 | + ), |
| 35 | + ] |
| 36 | + create_response = client.create_results(new_results) |
| 37 | + return create_response |
| 38 | + |
| 39 | + |
| 40 | +# Server configuration is not required when used with Systemlink Client or run throught Jupyter on SLE |
| 41 | +server_configuration = None |
| 42 | + |
| 43 | +# # Example of setting up the server configuration to point to your instance of SystemLink Enterprise |
| 44 | +# server_configuration = HttpConfiguration( |
| 45 | +# server_uri="https://yourserver.yourcompany.com", |
| 46 | +# api_key="YourAPIKeyGeneratedFromSystemLink", |
| 47 | +# ) |
| 48 | + |
| 49 | +client = TestMonitorClient(configuration=server_configuration) |
| 50 | + |
| 51 | +create_response = create_some_results() |
| 52 | + |
| 53 | +# Get all the results using the continuation token in batches of 100 at a time. |
| 54 | +response = client.get_results(take=100, return_count=True) |
| 55 | +all_results = response.results |
| 56 | +while response.continuation_token: |
| 57 | + response = client.get_results( |
| 58 | + take=100, continuation_token=response.continuation_token, return_count=True |
| 59 | + ) |
| 60 | + all_results.extend(response.results) |
| 61 | + |
| 62 | +# use get for first result created |
| 63 | +created_result = client.get_result(create_response.results[0].id) |
| 64 | + |
| 65 | +# Query results without continuation |
| 66 | +query_request = QueryResultsRequest( |
| 67 | + filter=f'status.statusType="{status_type.value}"', return_count=True |
| 68 | +) |
| 69 | +response = client.query_results(query_request) |
| 70 | + |
| 71 | +# Update the first result that you just created and replace the keywords |
| 72 | +updated_result = create_response.results[0] |
| 73 | +updated_result.keywords = ["new keyword"] |
| 74 | +updated_result.properties = {"new property key": "new value"} |
| 75 | +update_response = client.update_results([create_response.results[0]], replace=True) |
| 76 | + |
| 77 | +# Query for just the ids of results that match the family |
| 78 | +values_query = QueryResultValuesRequest( |
| 79 | + filter=f'programName="{program_name}"', field=ResultField.ID |
| 80 | +) |
| 81 | +values_response = client.query_result_values(query=values_query) |
| 82 | + |
| 83 | +# delete each created result individually by id |
| 84 | +for result in create_response.results: |
| 85 | + client.delete_result(result.id) |
| 86 | + |
| 87 | +# Create some more and delete them with a single call to delete. |
| 88 | +create_response = create_some_results() |
| 89 | +client.delete_results([result.id for result in create_response.results]) |
0 commit comments