forked from microsoft/azure-devops-python-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
77 lines (64 loc) · 2.63 KB
/
test.py
File metadata and controls
77 lines (64 loc) · 2.63 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
TEST samples
"""
import datetime
import logging
from samples import resource
from utils import emit
logger = logging.getLogger(__name__)
def get_project_names(context):
core_client = context.connection.clients.get_core_client()
return (project.name for project in core_client.get_projects())
@resource("test_plans")
def get_plans(context):
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for plan in test_client.get_plans(project):
emit("Test Plan {}: {} ({})".format(plan.id, plan.name, plan.area.name))
except Exception as e:
emit("Project '{}' raised error: {}".format(project, e))
@resource("test_suites")
def get_test_suites_for_plan(context):
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for plan in test_client.get_plans(project):
for suite in test_client.get_test_suites_for_plan(project, plan.id):
emit(
"Test Suite {}: {} ({}.{})".format(
suite.id, suite.name, plan.id, plan.name
)
)
except Exception as e:
emit("Project '{}' raised error: {}".format(project, e))
@resource("test_runs")
def get_test_runs(context):
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for run in test_client.get_test_runs(project, top=16):
emit(
"Test Run {}: {} => {} ({})".format(
run.id, run.name, run.state, project
)
)
except Exception as e:
emit("Project '{}' raised error: {}".format(project, e))
@resource("test_results")
def get_test_results(context):
test_client = context.connection.clients.get_test_client()
for project in get_project_names(context):
try:
for run in test_client.get_test_runs(project, top=10):
# Limiting Test Results is not something one shall do!
for res in test_client.get_test_results(project, run.id, top=3):
tc = res.test_case
tester = res.run_by.display_name
emit(
"Test Result {}: {} => {} by {} ({})".format(
run.id, tc.name, res.outcome, tester, project
)
)
except Exception as e:
emit("Project '{}' raised error: {}".format(project, e))