From 2283bf10cd59a3566894a666e4cd6aed9c95998f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Thu, 14 Oct 2010 13:20:46 +0000
Subject: [PATCH]  - separate tests totally by recreating all before and after
 test run

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39147 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../tests/testERP5RemoteUserManager.py        | 49 ++++++++++---------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/product/ERP5Wizard/tests/testERP5RemoteUserManager.py b/product/ERP5Wizard/tests/testERP5RemoteUserManager.py
index 651550578d..70c7431c2f 100644
--- a/product/ERP5Wizard/tests/testERP5RemoteUserManager.py
+++ b/product/ERP5Wizard/tests/testERP5RemoteUserManager.py
@@ -101,6 +101,8 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
 
   def afterSetUp(self):
     self.portal = self.getPortalObject()
+    self.createDummyWitchTool()
+    self.setUpRemoteUserManager()
     self.person_module = self.portal.person_module
     acl_users = self.portal.acl_users
     self.erp5_remote_manager = getattr(acl_users, self.erp5_remote_manager_id)
@@ -111,6 +113,10 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
     self.tic()
 
   def beforeTearDown(self):
+    """Clear everthing"""
+    self.portal.acl_users.manage_delObjects(self.erp5_remote_manager_id)
+    self.portal.deleteContent('portal_witch')
+    self.removeAuthenticationServerPreferences()
     self.portal.portal_caches.clearAllCache()
     transaction.commit()
     self.tic()
@@ -118,25 +124,26 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
     transaction.commit()
     self.tic()
 
-  def setUpAuthenticationServerPreferences(self):
+  def removeAuthenticationServerPreferences(self):
     portal_preferences = self.portal.portal_preferences
-    # disable all existing system preferences
-    system_preference = None
     if self.system_preference_id in portal_preferences.objectIds():
-      system_preference = getattr(portal_preferences,
-          self.system_preference_id)
-      self.assertEqual(self.system_preference_portal_type,
-          system_preference.getPortalType())
-    else:
-      system_preference = portal_preferences.newContent(
-          portal_type=self.system_preference_portal_type)
-    system_preference.edit(
-        preferred_witch_tool_server_url=self.portal.absolute_url() + '/',
-        preferred_witch_tool_server_root=self.getPortalId(),
+      portal_preferences.deleteContent(self.system_preference_id)
+
+  def setUpAuthenticationServerPreferences(self, server_url=None,
+      server_root=None):
+    if server_url is None:
+      server_url = self.portal.absolute_url() + '/'
+    if server_root is None:
+      self.getPortalId()
+    portal_preferences = self.portal.portal_preferences
+    # disable all existing system preferences
+    system_preference = portal_preferences.newContent(
+        portal_type=self.system_preference_portal_type,
+        id=self.system_preference_id,
+        preferred_witch_tool_server_url=server_url,
+        preferred_witch_tool_server_root=server_root,
     )
-    if self.portal.portal_workflow.isTransitionPossible(system_preference,
-        'enable'):
-      system_preference.enable()
+    system_preference.enable()
     self.assertEqual('global', system_preference.getPreferenceState())
     # clear cache after setting preferences
     self.portal.portal_caches.clearAllCache()
@@ -146,13 +153,6 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
       self.portal.newContent(id='portal_witch',
         portal_type=self.base_type_portal_type)
 
-  def setUpOnce(self):
-    self.portal = self.getPortalObject()
-    self.setUpRemoteUserManager()
-    self.createDummyWitchTool()
-    transaction.commit()
-    self.tic()
-
   def createPerson(self, reference, password):
     """Creates person with reference and password in title to simulate remote
     logging"""
@@ -160,6 +160,9 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
         portal_type=self.person_portal_type,
         reference=reference, title=password)
 
+  ############################################################################
+  # TESTS
+  ############################################################################
   def test_correct_login(self):
     login = 'someone'
     password = 'somepass'
-- 
2.30.9