summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Šplíchal <psplicha@redhat.com>2011-06-29 11:13:00 +0200
committerPetr Šplíchal <psplicha@redhat.com>2011-06-29 11:13:00 +0200
commitaf04e57c2b8efcaf79b5ac778f7f649d28122d2c (patch)
tree86fe6a2857cd321219d43145c3b87a45e7a28332
parentc62424259d249c9bec08480013467c45a8ebfc08 (diff)
downloadpython-nitrate-af04e57c2b8efcaf79b5ac778f7f649d28122d2c.tar.gz
python-nitrate-af04e57c2b8efcaf79b5ac778f7f649d28122d2c.tar.xz
python-nitrate-af04e57c2b8efcaf79b5ac778f7f649d28122d2c.zip
Nitrate: Provide default equality handling for all objects
-rw-r--r--Nitrate.py61
1 files changed, 23 insertions, 38 deletions
diff --git a/Nitrate.py b/Nitrate.py
index cd4257b..0a6d9a1 100644
--- a/Nitrate.py
+++ b/Nitrate.py
@@ -167,6 +167,13 @@ class Nitrate(object):
# Nitrate Properties
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ id = property(_getter("id"), doc="Object identifier.")
+
+ @property
+ def identifier(self):
+ """ Consistent identifier string. """
+ return "{0}#{1}".format(self._prefix, self._id)
+
@property
def _config(self):
""" User configuration (expected in ~/.nitrate). """
@@ -203,12 +210,6 @@ class Nitrate(object):
Nitrate._requests += 1
return Nitrate._connection
- @property
- def identifier(self):
- """ Consistent identifier string. """
- return "{0}#{1}".format(self._prefix, self._id)
-
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Nitrate Special
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -229,6 +230,22 @@ class Nitrate(object):
return "Nitrate server: {0}\nTotal requests handled: {1}".format(
self._config["url"], self._requests)
+ def __eq__(self, other):
+ """ Handle object equality based on its id. """
+ return self.id == other.id
+
+ def __ne__(self, other):
+ """ Handle object inequality based on its id. """
+ return self.id != other.id
+
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ # Nitrate Methods
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ def _get(self):
+ """ Fetch object data from the server. """
+ raise NitrateError("To be implemented by respective class")
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Bug Class
@@ -364,14 +381,6 @@ class PlanType(Nitrate):
""" Return TestPlan type for printing. """
return self.name
- def __eq__(self, other):
- """ Handle correctly TestPlan type equality. """
- return self._id == other._id
-
- def __ne__(self, other):
- """ Handle correctly TestPlan type inequality. """
- return self._id != other._id
-
@property
def id(self):
""" Numeric TestPlan type id. """
@@ -414,14 +423,6 @@ class Priority(Nitrate):
""" Return priority name for printing. """
return self.name
- def __eq__(self, other):
- """ Handle correctly priority equality. """
- return self._id == other._id
-
- def __ne__(self, other):
- """ Handle correctly priority inequality. """
- return self._id != other._id
-
@property
def id(self):
""" Numeric priority id. """
@@ -569,14 +570,6 @@ class CaseStatus(Nitrate):
""" Return casestatus name for printing. """
return self.name
- def __eq__(self, other):
- """ Handle correctly casestatus equality. """
- return self._id == other._id
-
- def __ne__(self, other):
- """ Handle correctly casestatus inequality. """
- return self._id != other._id
-
@property
def id(self):
""" Numeric casestatus id. """
@@ -622,14 +615,6 @@ class Status(Nitrate):
""" Return status name for printing. """
return self.name
- def __eq__(self, other):
- """ Handle correctly status equality. """
- return self._id == other._id
-
- def __ne__(self, other):
- """ Handle correctly status inequality. """
- return self._id != other._id
-
@property
def id(self):
""" Numeric status id. """