summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Šplíchal <psplicha@redhat.com>2011-07-27 15:51:34 +0200
committerPetr Šplíchal <psplicha@redhat.com>2011-07-27 15:51:34 +0200
commit2b32a6ebc99dbbbd1a840b29b1843ac8536d652c (patch)
treebbd3ceb6a1a77ab8168a3f1ba53803564237e0f9
parent51e0d2486c75291607ee679a242d5835b1e5a776 (diff)
downloadpython-nitrate-2b32a6ebc99dbbbd1a840b29b1843ac8536d652c.tar.gz
python-nitrate-2b32a6ebc99dbbbd1a840b29b1843ac8536d652c.tar.xz
python-nitrate-2b32a6ebc99dbbbd1a840b29b1843ac8536d652c.zip
Nitrate: RunStatus class implementation
-rw-r--r--Nitrate.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/Nitrate.py b/Nitrate.py
index e3afba4..ab7b30e 100644
--- a/Nitrate.py
+++ b/Nitrate.py
@@ -11,6 +11,7 @@ Nitrate object which checks ~/.nitrate config file for the url:
"""
import os
+import re
import sys
import ConfigParser
import logging as log
@@ -665,9 +666,46 @@ class Product(Nitrate):
class RunStatus(Nitrate):
""" Test run status. """
- id = property(_getter("id"), doc="Test run status id")
- def __init__(self, id):
- self._id = id
+
+ _statuses = ['RUNNING', 'FINISHED']
+
+ def __init__(self, status):
+ """
+ Takes numeric status id, status name or stop date.
+
+ A 'None' value is considered to be a 'no stop date' running:
+
+ 0 ... RUNNING ... 'None'
+ 1 ... FINISHED ... '2011-07-27 15:14'
+ """
+ if isinstance(status, int):
+ if status not in [0, 1]:
+ raise NitrateError(
+ "Not a valid run status id: '{0}'".format(status))
+ self._id = status
+ else:
+ # Running or no stop date
+ if status == "RUNNING" or status == "None" or status is None:
+ self._id = 0
+ # Finished or some stop date
+ elif status == "FINISHED" or re.match("^[-0-9: ]+$", status):
+ self._id = 1
+ else:
+ raise NitrateError("Invalid run status '{0}'".format(status))
+
+ def __str__(self):
+ """ Return run status name for printing. """
+ return self.name
+
+ @property
+ def id(self):
+ """ Numeric runstatus id. """
+ return self._id
+
+ @property
+ def name(self):
+ """ Human readable runstatus name. """
+ return self._statuses[self._id]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1779,7 +1817,7 @@ class TestRun(Mutable):
hash["notes"] = self.notes
hash["product"] = self.product.id
hash["product_version"] = self.product.version.id
- # TODO hash["status"] = self.status.id
+ hash["status"] = self.status.id
hash["summary"] = self.summary
log.info("Updating test run " + self.identifier)
@@ -2134,6 +2172,7 @@ if __name__ == "__main__":
TestCase(46490).script = "/CoreOS/component/example"
CaseRun(525318).status = Status("PASSED")
TestRun(6757).tags.add("TestTag")
+ TestRun(6757).status = RunStatus("FINISHED")
# Display info about the server
print "\n", Nitrate()