-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestrail_prepare.py
61 lines (54 loc) · 2.07 KB
/
testrail_prepare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import sys
import base64
import json
import requests
import argparse
from datetime import datetime
from testrail import *
class TestRailAPIWrapper:
def __init__(self, base_url, user, password):
self._client = APIClient(base_url)
self._client.user = user
self._client.password = password
def add_plan(self, project_id, entries):
# https://docs.testrail.techmatrix.jp/testrail/docs/702/api/reference/plans/
# POST index.php?/api/v2/add_plan/:project_id
entries["name"] = datetime.now().strftime("%Y-%m-%d-%H-%M") + " MagicPod Test"
response = self._client.send_post(
'add_plan/'+str(project_id),entries)
return response
TESTRAIL_URL = os.environ.get("TESTRAIL_URL")
TESTRAIL_USER = os.environ.get("TESTRAIL_USER")
TESTRAIL_PASSWORD = os.environ.get("TESTRAIL_PASSWORD")
TESTRAIL_TESTPLAN_JSON_FILENAME = './testplan.json'
TESTRAIL_PROJECT_ID = 3 # [ToDo]Change to the target project id in TestRail
TESTRAIL_TESTPLAN_ENTRY = {
"name": "testplan_name",
"entries": [
{
"suite_id": 3, # [ToDo]Change to the target suite_id in TestRail
"include_all": True, # All test cases in a suite will be included in the test plan
"config_ids": [5,6,7], # [ToDo]Change to the target config ids
"runs": [
{
"config_ids": [5] # [ToDo]Change to the target config id
},
{
"config_ids": [6] # [ToDo]Change to the target config id
},
{
"config_ids": [7] # [ToDo]Change to the target config id
}
]
},
]
}
def prepare_testplan():
print("Preparing test plan")
client = TestRailAPIWrapper(TESTRAIL_URL, TESTRAIL_USER, TESTRAIL_PASSWORD)
response = client.add_plan(TESTRAIL_PROJECT_ID, TESTRAIL_TESTPLAN_ENTRY)
print(json.dumps(response, indent=4))
with open(TESTRAIL_TESTPLAN_JSON_FILENAME, "w", encoding='utf-8') as file:
file.write(json.dumps(response))
prepare_testplan()