summaryrefslogtreecommitdiffstats
path: root/examples/create.py
blob: fc027eab0546623ec3052ddc9613743c598f8dc8 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python

from nitrate import *

# Set log level, cache level and color mode
setLogLevel(log.DEBUG)
setCacheLevel(CACHE_OBJECTS)
setColorMode(COLOR_AUTO)

# Initialize an existing test plan
info("Initializing an existing test plan")
generalPlan = TestPlan(3781)
print generalPlan

# Logging, catching errors
setLogLevel(log.INFO)
info("Initializing a bad test plan")
try:
    log.info("Inspecting the test plan")
    badPlan = TestPlan(1)
    print badPlan
except NitrateError, e:
    log.error("Bad test plan id ({0})".format(e))

# Iterate over all test plan's test cases
info("Inspecting test plan's test cases")
for testcase in generalPlan:
    print testcase

# Create a new test plan
info("Creating a new test plan")
releasePlan = TestPlan(
        parent=generalPlan,
        name="python / rhel-6.2",
        type="Release",
        product="Red Hat Enterprise Linux 6",
        version="6.2")

# Link all automated test cases from the general plan
info("Linking automated test cases from the general plan")
for testcase in generalPlan:
    if testcase.automated:
        releasePlan.testcases.add(testcase)
releasePlan.update()

# Create a new test case
info("Creating a new test case")
testcase = TestCase(
        summary="New performance test",
        product="Red Hat Enterprise Linux 6",
        category="Performance",
        script="/CoreOS/python/Performance/new-test")

# Set status, priority, default tester, add tags, attach bugs, link plans
info("Setting status, priority, tester, tags, bugs and plans")
testcase.status = CaseStatus("CONFIRMED")
testcase.priority = Priority("P1")
testcase.tester = User("psplicha")
testcase.tags.add("rhel-6.2")
testcase.bugs.add(Bug(123))
testcase.testplans.add([generalPlan, releasePlan])
testcase.update()

# Beware of caching (reload objects if necessary)
info("Test plan synopsis (before update)")
print generalPlan.synopsis
print releasePlan.synopsis
generalPlan = TestPlan(generalPlan.id)
releasePlan = TestPlan(releasePlan.id)
info("Test plan synopsis (after update)")
print generalPlan.synopsis
print releasePlan.synopsis

# List all general plan's children including their status
info("Listing child test plans of the general test plan")
for testplan in TestPlan.search(parent=generalPlan.id):
    print testplan, testplan.status

# Create a new test run
info("Creating a new test run")
testrun = TestRun(
        testplan=releasePlan,
        build="RHEL6.2-20110815.n.1",
        summary="python-2.6.6-20.el6.x86_64 / ER#11359")

# Get script and arguments for all IDLE performance caseruns, move to RUNNING
info("Scheduling performance tests")
for caserun in testrun:
    if (caserun.status == Status("IDLE")
            and str(caserun.testcase.category) == "Performance"):
        print caserun.testcase.script, caserun.testcase.arguments
        caserun.status = Status("RUNNING")
        caserun.update()

# Check case run status of the whole test run
info("Checking case run status")
for caserun in testrun:
    print caserun