summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Šplíchal <psplicha@redhat.com>2012-02-21 15:23:37 +0100
committerPetr Šplíchal <psplicha@redhat.com>2012-02-21 15:23:37 +0100
commit1c9fc0c227f1deae0efca187c38dab79c56c6fe0 (patch)
tree26e48104eae7ad76348cd21ede420d99e5016277
parent16a63080b6be9950fb76bd61c466c6142bcec3ef (diff)
downloadpython-nitrate-1c9fc0c227f1deae0efca187c38dab79c56c6fe0.tar.gz
python-nitrate-1c9fc0c227f1deae0efca187c38dab79c56c6fe0.tar.xz
python-nitrate-1c9fc0c227f1deae0efca187c38dab79c56c6fe0.zip
Include example scripts
-rwxr-xr-xexamples/example.py98
-rwxr-xr-xexamples/matrix.py23
2 files changed, 121 insertions, 0 deletions
diff --git a/examples/example.py b/examples/example.py
new file mode 100755
index 0000000..fc027ea
--- /dev/null
+++ b/examples/example.py
@@ -0,0 +1,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
diff --git a/examples/matrix.py b/examples/matrix.py
new file mode 100755
index 0000000..e8cba98
--- /dev/null
+++ b/examples/matrix.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+import re, sys, optparse
+from nitrate import *
+
+if __name__ == "__main__":
+ parser = optparse.OptionParser(usage="matrix.py --plan PLAN [options]")
+ parser.add_option("--plan", dest="plan", type="int", help="test plan id")
+ options = parser.parse_args()[0]
+
+ testplan = TestPlan(options.plan)
+ print "Checking results of {0}:\nTest runs: {1}".format(testplan,
+ ", ".join([run.identifier for run in testplan.testruns]))
+
+ for testcase in sorted(testplan.testcases, key=lambda x: x.script):
+ for testrun in testplan.testruns:
+ for caserun in testrun.caseruns:
+ if caserun.testcase.id == testcase.id:
+ print caserun.status.shortname,
+ break
+ else:
+ print "....",
+ print "- {0} - {1}".format(str(testcase.tester).ljust(8), testcase)