[Erp5-report] r36605 fabien - in /experimental/bt5/erp5_credential: TestTemplateItem/ bt/

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Jun 25 17:30:47 CEST 2010


Author: fabien
Date: Fri Jun 25 17:30:42 2010
New Revision: 36605

URL: http://svn.erp5.org?rev=36605&view=rev
Log:
add test file

Added:
    experimental/bt5/erp5_credential/TestTemplateItem/
    experimental/bt5/erp5_credential/TestTemplateItem/testERP5Credential.py
Modified:
    experimental/bt5/erp5_credential/bt/revision
    experimental/bt5/erp5_credential/bt/template_test_id_list

Added: experimental/bt5/erp5_credential/TestTemplateItem/testERP5Credential.py
URL: http://svn.erp5.org/experimental/bt5/erp5_credential/TestTemplateItem/testERP5Credential.py?rev=36605&view=auto
==============================================================================
--- experimental/bt5/erp5_credential/TestTemplateItem/testERP5Credential.py (added)
+++ experimental/bt5/erp5_credential/TestTemplateItem/testERP5Credential.py [utf8] Fri Jun 25 17:30:42 2010
@@ -0,0 +1,365 @@
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+#          Fabien Morin <fabien at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+import unittest
+from Products.ERP5Type.tests.utils import reindex
+from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
+from Products.ERP5Type.tests.Sequence import SequenceList
+from zLOG import LOG
+import transaction
+
+class TestERP5Credential(ERP5TypeTestCase):
+
+  def getTitle(self):
+    return "ERP5 Credential"
+
+  def getBusinessTemplateList(self):
+    return (
+      'erp5_base',
+      'erp5_credential')
+
+  def afterSetUp(self):
+    """Prepare the test."""
+    self.createCategories()
+
+  @reindex
+  def createCategories(self):
+    """Create the categories for our test. """
+    # create categories
+    for cat_string in self.getNeededCategoryList() :
+      base_cat = cat_string.split("/")[0]
+      # if base_cat not exist, create it
+      if getattr(self.getPortal().portal_categories, base_cat, None) == None:
+        self.getPortal().portal_categories.newContent(\
+                                          portal_type='Base Category',
+                                          id=base_cat)
+      base_cat_value = self.getPortal().portal_categories[base_cat]
+      for cat in cat_string.split("/")[1:] :
+        if not cat in base_cat_value.objectIds() :
+          base_cat_value = base_cat_value.newContent(
+                    portal_type='Category',
+                    id=cat,
+                    title=cat.replace('_', ' ').title(),)
+        else:
+          base_cat_value = base_cat_value[cat]
+    # check categories have been created
+    for cat_string in self.getNeededCategoryList() :
+      self.assertNotEquals(None,
+                self.getCategoryTool().restrictedTraverse(cat_string),
+                cat_string)
+
+  def getNeededCategoryList(self):
+    """return a list of categories that should be created."""
+    return ('role/client/distributor',
+            'role/internal',
+            'role/media',
+            'role/partner',
+            'function/member',
+            'function/manager',
+            'function/agent',
+            'site/dakar',
+            'site/paris',
+            'site/tokyo',
+           )
+
+  def beforeTearDown(self):
+    self._removeAutomaticWorkflow()
+    # clear modules if necessary
+    module_list = (self.portal.getDefaultModule('Credential Request'),
+        self.portal.getDefaultModule('Credential Update'),
+        self.portal.getDefaultModule('Credential Recovery'),
+        self.portal.getDefaultModule('Person'))
+    for module in module_list:
+      module.manage_delObjects(list(module.objectIds()))
+    transaction.commit()
+    self.tic()
+
+  def getUserFolder(self):
+    """Returns the acl_users. """
+    return self.getPortal().acl_users
+
+  def _assertUserExists(self, login, password):
+    """Checks that a user with login and password exists and can log in to the
+    system.
+    """
+    from Products.PluggableAuthService.interfaces.plugins import\
+                                                      IAuthenticationPlugin
+    uf = self.getUserFolder()
+    self.assertNotEquals(uf.getUserById(login, None), None)
+    for plugin_name, plugin in uf._getOb('plugins').listPlugins(
+                                IAuthenticationPlugin ):
+      if plugin.authenticateCredentials(
+                  {'login':login, 'password':password}) is not None:
+        break
+    else:
+      self.fail("No plugin could authenticate '%s' with password '%s'" %
+              (login, password))
+
+  def _assertUserDoesNotExists(self, login, password):
+    """Checks that a user with login and password does not exists and cannot
+    log in to the system.
+    """
+    from Products.PluggableAuthService.interfaces.plugins import\
+                                                        IAuthenticationPlugin
+    uf = self.getUserFolder()
+    for plugin_name, plugin in uf._getOb('plugins').listPlugins(
+                              IAuthenticationPlugin ):
+      if plugin.authenticateCredentials(
+                {'login':login, 'password':password}) is not None:
+        self.fail(
+           "Plugin %s should not have authenticated '%s' with password '%s'" %
+           (plugin_name, login, password))
+
+  def _setAutomaticWorkflowOnPortalTypeList(self, portal_type_list):
+    '''
+      set the workflow credential_automatic_approve_interraction_workflow on
+      all portal_types parameters
+    '''
+    if not isinstance(portal_type_list, list):
+      portal_type_list = [portal_type_list]
+    for portal_type in portal_type_list:
+      pw = self.getWorkflowTool()
+      workflow_id = 'credential_automatic_approve_interraction_workflow'
+      cbt = pw._chains_by_type
+      props = {}
+      for id, wf_ids in cbt.iteritems():
+        if id == portal_type:
+          wf_ids = list(wf_ids) + [workflow_id]
+        props['chain_%s' % id] = ','.join(wf_ids)
+      pw.manage_changeWorkflows('', props = props)
+
+  def _removeAutomaticWorkflow(self):
+    '''
+      by default, the automatic workflow is not defined on any portal_type.
+      (should be define in project specific bt). The methode remove it.
+    '''
+    pw = self.getWorkflowTool()
+    workflow_id = 'credential_automatic_approve_interraction_workflow'
+    cbt = pw._chains_by_type
+    props = {}
+    for id, wf_ids in cbt.iteritems():
+      if workflow_id in wf_ids:
+        wf_ids = list(wf_ids)
+        wf_ids.remove(workflow_id)
+      props['chain_%s' % id] = ','.join(wf_ids)
+    pw.manage_changeWorkflows('', props = props)
+
+  def stepCreateSimpleSubscriptionRequest(self, sequence=None, sequence_list=None,
+      **kw):
+    '''
+    Create a simple subscription request
+    '''
+    request = self.portal.REQUEST
+    request['PARENTS'] = [self.app]
+    form_url = self.portal.absolute_url_path() + '/ERP5Site_viewNewCredentialRequestDialog'
+
+    # logout to be annonymous
+    self.logout()
+    # check annonymous can access subscription form
+    self.assertTrue("Desired Login Name" in request.traverse(form_url)())
+    # fill in and submit the subscription form
+    result = self.portal.ERP5Site_newCredentialRequest(\
+        first_name='Homer',
+        last_name='Simpson',
+        user_id='homie',
+        password='secret',
+        default_email_text='homer.simpson at fox.com'
+        )
+    self.assertTrue('portal_status_message=Credential%20Request%20Created.' in result)
+    # check it returned to login_form
+    self.assertTrue('login_form' in result)
+
+    transaction.commit()
+    self.tic()
+    credential_request_module = self.portal.getDefaultModule('Credential Request')
+    result = credential_request_module.contentValues(\
+        portal_type='Credential Request', first_name='Homer',
+        last_name='Simpson', user_id='homie')
+    self.assertEquals(len(result), 1)
+    sequence.edit(subscription_request=result[0])
+
+  def stepApproveSubscriptionRequest(self, sequence=None, sequence_list=None,
+      **kw):
+    subscription_request = sequence.get('subscription_request')
+    subscription_request.approve()
+
+  def stepCheckAccountIsCreated(self, sequence=None, sequence_list=None, **kw):
+    # check a person have been created
+    person_module = self.portal.getDefaultModule('Person')
+    person_result = person_module.contentValues(reference='homie')
+    self.assertEquals(len(person_result), 1)
+    person = person_result[0].getObject()
+    self.assertEquals(person.getTitle(), 'Homer Simpson')
+    self.assertEquals(person.getDefaultEmailText(), 'homer.simpson at fox.com')
+
+    # check homie can log in the system
+    self._assertUserExists('homie', 'secret')
+    self.login('homie')
+    from AccessControl import getSecurityManager
+    self.assertEquals(str(getSecurityManager().getUser()), 'homie')
+
+  def stepCreateCredentialUpdate(self, sequence=None, sequence_list=None, **kw):
+    # check the dialog is automatically pre-filled with the values of logged in
+    # user
+    self.login('homie')
+    # fill in and submit the credential update form
+    result = self.portal.ERP5Site_newCredentialUpdate(\
+        first_name='Homie',
+        last_name='Simpsons',
+        password='new_password',
+        default_email_text='homie.simpsons at fox.com'
+        )
+    self.assertTrue('portal_status_message=Credential%20Update%20Created.' in result)
+    credential_request_module = self.portal.getDefaultModule('Credential Update')
+    result = credential_request_module.contentValues(\
+        portal_type='Credential Update', first_name='Homie',
+        last_name='Simpsons')
+    self.assertEquals(len(result), 1)
+    credential_update = result[0]
+    sequence.edit(credential_update=credential_update)
+
+  def stepCheckCredentialUpdateForm(self, sequence=None, sequence_list=None, **kw):
+    # check the dialog is automatically pre-filled with the values of logged in
+    # user
+    self.login('homie')
+    result = self.portal.ERP5Site_viewNewCredentialUpdateDialog()
+    self.assertTrue('name="field_your_first_name" value="Homer"' in result)
+    self.assertTrue('name="field_your_last_name" value="Simpson"' in result)
+    self.assertTrue('name="field_your_default_email_text" '\
+        'value="homer.simpson at fox.com"' in result)
+
+  def stepApproveCredentialUpdate(self, sequence=None, sequence_list=None,
+      **kw):
+    credential_update = sequence.get('credential_update')
+    credential_update.approve()
+
+  def stepCheckCredentialUpdate(self, sequence=None, sequence_list=None,
+      **kw):
+    self.login()
+    # check the user with the updated password exists
+    self._assertUserExists('homie', 'new_password')
+    # check the user with the old password don't exists anymore
+    self._assertUserDoesNotExists('homie', 'secret')
+
+  def stepSetAutomaticWorkflowOnCredentialRequest(self, sequence=None,
+      sequence_list=None, **kw):
+    self._setAutomaticWorkflowOnPortalTypeList('Credential Request')
+
+  def stepSetAutomaticWorkflowOnCredentialUpdate(self, sequence=None,
+      sequence_list=None, **kw):
+    self._setAutomaticWorkflowOnPortalTypeList('Credential Update')
+
+
+
+  def test_01_simpleSubsciptionRequest(self):
+    '''
+    Check that is possible to subscribe to erp5
+    '''
+    sequence_list = SequenceList()
+    sequence_string = 'CreateSimpleSubscriptionRequest Tic '\
+
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self)
+
+  def test_02_approveSubscriptionRequest(self):
+    '''
+    Check that after approval, the account is created and the user is able to
+    log in the system.
+    '''
+    sequence_list = SequenceList()
+    sequence_string = 'CreateSimpleSubscriptionRequest '\
+                      'ApproveSubscriptionRequest Tic '\
+                      'CheckAccountIsCreated '\
+
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self)
+
+  def test_03_simpleCredentialUpdate(self):
+    '''
+    check it's possible to update credential informations using credential
+    update
+    '''
+    sequence_list = SequenceList()
+    sequence_string = 'CreateSimpleSubscriptionRequest '\
+                      'ApproveSubscriptionRequest Tic '\
+                      'CreateCredentialUpdate '\
+                      'CheckCredentialUpdateForm '\
+                      'ApproveCredentialUpdate Tic '\
+                      'CheckCredentialUpdate '\
+
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self)
+
+  def test_04_automaticCredentialRequestApproval(self):
+    '''
+    if the workflow credential_automatic_approve_interraction_workflow
+    is defined on Credential Request portal_type, the Credential Request object
+    should be approved automatically and account created without any human
+    intervention
+    '''
+    sequence_list = SequenceList()
+    sequence_string = 'SetAutomaticWorkflowOnCredentialRequest '\
+                      'CreateSimpleSubscriptionRequest Tic '\
+                      'CheckAccountIsCreated '\
+
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self)
+
+  def test_05_automaticCredentialUpdateApproval(self):
+    '''
+    if the workflow credential_automatic_approve_interraction_workflow
+    is defined on Credential Update portal_type, the Credential Update object
+    should be approved automatically and object modified without any human
+    intervention
+    '''
+    sequence_list = SequenceList()
+    sequence_string = 'SetAutomaticWorkflowOnCredentialUpdate '\
+                      'CreateSimpleSubscriptionRequest '\
+                      'ApproveSubscriptionRequest Tic '\
+                      'CreateCredentialUpdate Tic '\
+                      'CheckCredentialUpdate '\
+
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self)
+
+
+  def test_06_passwordRecovery(self):
+    '''
+    check that a user that forget his password is able to set a new one and
+    log in the system with this new password
+    '''
+
+  def test_07_checkCredentialQuestionIsNotCaseSensitive(self):
+    '''
+    check that if the user enter an answer with a diffent case, this will still
+    enought to reset his passord
+    '''
+
+def test_suite():
+  suite = unittest.TestSuite()
+  suite.addTest(unittest.makeSuite(TestERP5Credential))
+  return suite

Modified: experimental/bt5/erp5_credential/bt/revision
URL: http://svn.erp5.org/experimental/bt5/erp5_credential/bt/revision?rev=36605&r1=36604&r2=36605&view=diff
==============================================================================
--- experimental/bt5/erp5_credential/bt/revision [utf8] (original)
+++ experimental/bt5/erp5_credential/bt/revision [utf8] Fri Jun 25 17:30:42 2010
@@ -1 +1 @@
-91
\ No newline at end of file
+92
\ No newline at end of file

Modified: experimental/bt5/erp5_credential/bt/template_test_id_list
URL: http://svn.erp5.org/experimental/bt5/erp5_credential/bt/template_test_id_list?rev=36605&r1=36604&r2=36605&view=diff
==============================================================================
--- experimental/bt5/erp5_credential/bt/template_test_id_list [utf8] (original)
+++ experimental/bt5/erp5_credential/bt/template_test_id_list [utf8] Fri Jun 25 17:30:42 2010
@@ -0,0 +1 @@
+testERP5Credential
\ No newline at end of file




More information about the Erp5-report mailing list