From 6d2ffcca8d77af715cec518f31f64e276d49dbf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 27 Oct 2015 18:06:50 +0100
Subject: [PATCH] SecurityTestCase: add helper methods for worklists

---
 product/ERP5Type/tests/SecurityTestCase.py | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/product/ERP5Type/tests/SecurityTestCase.py b/product/ERP5Type/tests/SecurityTestCase.py
index 413c1aa3bb..c68c4226a0 100644
--- a/product/ERP5Type/tests/SecurityTestCase.py
+++ b/product/ERP5Type/tests/SecurityTestCase.py
@@ -244,6 +244,41 @@ class SecurityTestCase(ERP5TypeTestCase):
 
   assertUserCanPassWorkflowTransition = failUnlessUserCanPassWorkflowTransition
 
+  def assertUserHasWorklist(self, username, worklist_id, document_count):
+    self.portal.portal_workflow.refreshWorklistCache()
+    self.portal.portal_caches.clearAllCache()
+    sm = getSecurityManager()
+    try:
+      self._loginAsUser(username)
+      global_action_list = [x for x in
+        self.portal.portal_workflow.listActions(object=self.portal)
+        if x['category'] == 'global']
+      worklist_action_list = [x for x in global_action_list
+        if x['worklist_id'] == worklist_id]
+      if not(worklist_action_list):
+        self.fail("User %s does not have worklist %s.\nWorklists: %s" % (
+          username, worklist_id, pformat(global_action_list)))
+      worklist_action, = worklist_action_list
+      self.assertEquals(document_count, worklist_action['count'],
+        "User %s has %s documents in her %s worklist, not %s" % (
+          username, worklist_action['count'], worklist_id, document_count))
+    finally:
+      setSecurityManager(sm)
+
+  def assertUserHasNoWorklist(self, username, worklist_id):
+    self.portal.portal_workflow.refreshWorklistCache()
+    self.portal.portal_caches.clearAllCache()
+    sm = getSecurityManager()
+    try:
+      self._loginAsUser(username)
+      worklist_action_list = [x for x in
+        self.portal.portal_workflow.listActions(object=self.portal)
+        if x['category'] == 'global' and x['worklist_id'] == worklist_id]
+      if worklist_action_list:
+        self.fail("User %s has worklist %s: %s" % (username, worklist_id, pformat(worklist_action_list)))
+    finally:
+      setSecurityManager(sm)
+
   # Simple check for an user Role
   def failIfUserHaveRoleOnDocument(self, username, role, document):
     """Fails if the user have the role on the document."""
-- 
2.30.9