|
| 1 | +from datetime import datetime |
| 2 | + |
| 3 | +from nisystemlink.clients.core._http_configuration import HttpConfiguration |
| 4 | +from nisystemlink.clients.test_plan import TestPlanClient |
| 5 | +from nisystemlink.clients.test_plan.models import ( |
| 6 | + CreateTestPlanRequest, |
| 7 | + Dashboard, |
| 8 | + Job, |
| 9 | + JobExecution, |
| 10 | + ManualExecution, |
| 11 | + QueryTestPlansRequest, |
| 12 | + ScheduleTestPlanRequest, |
| 13 | + ScheduleTestPlansRequest, |
| 14 | + UpdateTestPlanRequest, |
| 15 | + UpdateTestPlansRequest, |
| 16 | +) |
| 17 | + |
| 18 | +# Setup the server configuration to point to your instance of SystemLink Enterprise |
| 19 | +server_configuration = HttpConfiguration( |
| 20 | + server_uri="https://yourserver.yourcompany.com", |
| 21 | + api_key="YourAPIKeyGeneratedFromSystemLink", |
| 22 | +) |
| 23 | +client = TestPlanClient(configuration=server_configuration) |
| 24 | + |
| 25 | +create_test_plans_request = [ |
| 26 | + CreateTestPlanRequest( |
| 27 | + name="Python integration test plan", |
| 28 | + state="NEW", |
| 29 | + description="Test plan for verifying integration flow", |
| 30 | + |
| 31 | + estimated_duration_in_seconds=86400, |
| 32 | + properties={"env": "staging", "priority": "high"}, |
| 33 | + part_number="px40482", |
| 34 | + dut_id="Sample-Dut_Id", |
| 35 | + test_program="TP-Integration-001", |
| 36 | + system_filter="os:linux AND arch:x64", |
| 37 | + workspace="your_workspace_id", |
| 38 | + file_ids_from_template=["file1", "file2"], |
| 39 | + dashboard=Dashboard( |
| 40 | + id="DashBoardId", variables={"product": "PXIe-4080", "location": "Lab1"} |
| 41 | + ), |
| 42 | + execution_actions=[ |
| 43 | + ManualExecution(action="boot", type="MANUAL"), |
| 44 | + JobExecution( |
| 45 | + action="run", |
| 46 | + type="JOB", |
| 47 | + jobs=[ |
| 48 | + Job( |
| 49 | + functions=["run_test_suite"], |
| 50 | + arguments=[["test_suite.py"]], |
| 51 | + metadata={"env": "staging"}, |
| 52 | + ) |
| 53 | + ], |
| 54 | + systemId="system-001", |
| 55 | + ), |
| 56 | + ], |
| 57 | + ) |
| 58 | +] |
| 59 | + |
| 60 | +# create a test plan |
| 61 | +created_test_plans_response = client.create_test_plans( |
| 62 | + test_plans=create_test_plans_request |
| 63 | +) |
| 64 | + |
| 65 | +if created_test_plans_response.created_test_plans: |
| 66 | + created_test_plan_id = created_test_plans_response.created_test_plans[0].id |
| 67 | + |
| 68 | +# Query test plan using id. |
| 69 | +query_test_plans_request = QueryTestPlansRequest( |
| 70 | + skip=0, take=1, descending=False, returnCount=False |
| 71 | +) |
| 72 | +client.query_test_plans(query_request=query_test_plans_request) |
| 73 | + |
| 74 | +# Get test plan |
| 75 | +get_test_plan = client.get_test_plan(test_plan_id=created_test_plan_id) |
| 76 | + |
| 77 | +# Update test plan |
| 78 | +update_test_plans_request = UpdateTestPlansRequest( |
| 79 | + test_plans=[ |
| 80 | + UpdateTestPlanRequest( |
| 81 | + id=created_test_plan_id, |
| 82 | + name="Updated Test Plan", |
| 83 | + ) |
| 84 | + ] |
| 85 | +) |
| 86 | +updated_test_plan = client.update_test_plans(update_request=update_test_plans_request) |
| 87 | + |
| 88 | +# Schedule the test plan |
| 89 | +schedule_test_plans_request = ScheduleTestPlansRequest( |
| 90 | + test_plans=[ |
| 91 | + ScheduleTestPlanRequest( |
| 92 | + id=created_test_plan_id, |
| 93 | + planned_start_date_time=datetime.strptime( |
| 94 | + "2025-05-20T15:07:42.527Z", "%Y-%m-%dT%H:%M:%S.%fZ" |
| 95 | + ), |
| 96 | + estimated_end_date_time=datetime.strptime( |
| 97 | + "2025-05-22T15:07:42.527Z", "%Y-%m-%dT%H:%M:%S.%fZ" |
| 98 | + ), |
| 99 | + system_id="fake-system", |
| 100 | + ) |
| 101 | + ] |
| 102 | +) |
| 103 | +schedule_test_plan_response = client.schedule_test_plans( |
| 104 | + schedule_request=schedule_test_plans_request |
| 105 | +) |
| 106 | + |
| 107 | +# Delete test plan |
| 108 | +client.delete_test_plans(ids=[created_test_plan_id]) |
0 commit comments