summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Mancy <rmancy@redhat.com>2011-01-04 21:43:26 +1000
committerBill Peck <bpeck@redhat.com>2011-01-04 08:36:57 -0500
commit03e9e86ac73dc662dd386ba733d7dae973ae48a0 (patch)
treebf41fa98e4318fc4d47bc485e21b17bc93ccfd8a
parented30f8736f584137bd1263ea4a12cf4324343c2d (diff)
some fixes for correctly doing equality with the cached objects
-rw-r--r--Server/bkr/server/helpers.py10
-rw-r--r--Server/bkr/server/model.py52
-rw-r--r--Server/bkr/server/test/selenium/test_report_problem.py1
3 files changed, 54 insertions, 9 deletions
diff --git a/Server/bkr/server/helpers.py b/Server/bkr/server/helpers.py
index c2b4efd..b9ee6e3 100644
--- a/Server/bkr/server/helpers.py
+++ b/Server/bkr/server/helpers.py
@@ -35,15 +35,13 @@ def make_fake_link(name,id,text):
def cache(f):
the_cache = {}
def do_cache(*args):
- args = tuple(args)
- #Make sure we have different cache vals for args
- args_to_hash = args + (f,)
- cache = the_cache
+ args = tuple(args)
+ #Make sure we have different cache vals for args
try:
- return cache[args_to_hash]
+ return the_cache[args]
except KeyError:
result = f(*args)
- the_cache[args_to_hash] = result
+ the_cache[args] = result
return result
return do_cache
diff --git a/Server/bkr/server/model.py b/Server/bkr/server/model.py
index e97954a..8548d5f 100644
--- a/Server/bkr/server/model.py
+++ b/Server/bkr/server/model.py
@@ -1047,19 +1047,24 @@ class User(object):
return self.user_name
def is_admin(self):
- return u'admin' in [group.group_name for group in self.groups]
+ return u'admin' in [group.group_name for group in self.groups]
def in_group(self,check_groups):
my_groups = [group.group_name for group in self.groups]
for my_g in check_groups:
if my_g in my_groups:
- return True
+ return True
return False
class Permission(object):
"""
A relationship that determines what each Group can do
"""
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
@classmethod
@cache
@@ -1187,6 +1192,13 @@ class Group(object):
"""
An ultra-simple group definition.
"""
+
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
+
@classmethod
@cache
def by_name(cls, name):
@@ -1782,7 +1794,6 @@ class System(SystemObject):
return True
elif user is None:
return False
-
if self.status==SystemStatus.by_name('Manual'): #If it's manual then we us our original perm system.
return self._has_regular_perms(user)
return False
@@ -2359,6 +2370,12 @@ class SystemType(SystemObject):
def __repr__(self):
return self.type
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
+
@classmethod
def get_all_types(cls):
"""
@@ -2431,6 +2448,12 @@ class SystemStatus(SystemObject):
def __repr__(self):
return self.status
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
+
@classmethod
def get_all_status(cls):
"""
@@ -3793,6 +3816,13 @@ class Product(object):
def __init__(self, name):
self.name = name
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
+
+
@classmethod
def by_id(cls, id):
return cls.query().filter(cls.id == id).one()
@@ -5528,6 +5558,12 @@ class Task(MappedObject):
Tasks that are available to schedule
"""
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
+
@classmethod
@cache
def by_name(cls, name):
@@ -5636,6 +5672,11 @@ class TaskType(MappedObject):
A task can be classified into serveral task types which can be used to
select tasks for batch runs
"""
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
@classmethod
@cache
@@ -5647,6 +5688,11 @@ class TaskPackage(MappedObject):
"""
A list of packages that a tasks should be run for.
"""
+ def __eq__(self,other):
+ return isinstance(other,self.__class__) and self.id == other.id
+
+ def __ne__(self,other):
+ return isinstance(other,self.__class__) and self.id != other.id
@classmethod
@cache
diff --git a/Server/bkr/server/test/selenium/test_report_problem.py b/Server/bkr/server/test/selenium/test_report_problem.py
index 9204930..56681e3 100644
--- a/Server/bkr/server/test/selenium/test_report_problem.py
+++ b/Server/bkr/server/test/selenium/test_report_problem.py
@@ -85,6 +85,7 @@ class TestReportProblem(SeleniumTestCase):
sel = self.selenium
try:
sel.open('report_problem?system_id=%s' % system.id)
+ sel.wait_for_page_to_load('3000')
self.fail('Should raise 403')
except Exception, e:
self.assert_('Response_Code = 403' in e.args[0])