testERP5WebWithCRM.py 7.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
#          Nicolas Delaby <nicolas@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
31
import transaction
Jérome Perrin's avatar
Jérome Perrin committed
32

33
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50


class TestERP5WebWithCRM(ERP5TypeTestCase):
  """Test for erp5_web and erp5_crm features
  """

  def getTitle(self):
    return "ERP5 Web with CRM"

  def getBusinessTemplateList(self):
    """
    Return the list of required business templates.
    """
    return ('erp5_base',
            'erp5_ingestion',
            'erp5_ingestion_mysql_innodb_catalog',
            'erp5_crm',
Nicolas Delaby's avatar
Nicolas Delaby committed
51
            'erp5_jquery',
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
            'erp5_web',
            )

  def afterSetUp(self):
    self.login()
    user = self.createUser('robby')
    self.createUserAssignment(user, {})

  def clearModule(self, module):
    module.manage_delObjects(list(module.objectIds()))
    self.tic()

  def beforeTearDown(self):
    self.clearModule(self.portal.web_site_module)
    self.clearModule(self.portal.event_module)
    self.clearModule(self.portal.person_module)

  def setupWebSection(self, **kw):
    """
      Setup Web Site
    """
    portal = self.getPortal()
    website = self.getPortal().web_site_module.newContent(portal_type='Web Site',
                                                          **kw)
    websection = website.newContent(portal_type='Web Section', **kw)
    website.publish()
    self.tic()
    return websection

  def test_01_Contact_Us_with_Anonymous_user(self):
    """Test creation of Web Message with Anonymous User
    """
    web_section = self.setupWebSection()
    self.logout()
    form_kw = {'source_organisation_title': 'John Doe Industries',
               'source_person_first_name': 'John',
               'source_person_last_name': 'Doe',
               'source_person_default_email_text': 'John.Doe@example.com',
               'source_person_default_telephone_text': '34343434',
91
               'text_content': 'I want ERP5 for my company',
92 93 94 95 96 97
              }
    web_section.WebSection_addWebMessage(**form_kw)
    self.tic()

    self.login()
    # Now a web message has been created
98
    telephone_key = 'source_person_default_telephone_text'
99 100
    event = self.portal.event_module.objectValues()[0]
    for property_id, value in form_kw.iteritems():
101 102 103
      if property_id == telephone_key:
        value =  '+(0)-%s' % value

104 105
      self.assertEqual(event.getProperty(property_id), value)
    self.assertEqual(event.getSourceCarrier(), web_section.getRelativeUrl())
106 107 108 109 110
    self.assertTrue(event.hasStartDate())

    # Trig alarm execution
    self.portal.portal_alarms.fetch_incoming_web_message_list.activeSense()
    self.tic()
111
    self.assertEqual(event.getSimulationState(), 'delivered')
112 113
    ticket = event.getFollowUpValue()
    self.assertTrue(ticket is not None)
114
    self.assertEqual(ticket.getSimulationState(), 'submitted')
115 116
    person = event.getSourceValue()
    self.assertTrue(person is not None)
117
    self.assertEqual(person.getFirstName(),
118
                      form_kw['source_person_first_name'])
119
    self.assertEqual(person.getLastName(),
120
                      form_kw['source_person_last_name'])
121
    self.assertEqual(person.getDefaultEmailText(),
122 123 124
                      form_kw['source_person_default_email_text'])
    self.assertTrue(form_kw['source_person_default_telephone_text'] in\
                    person.getDefaultTelephoneText())
125
    self.assertEqual(person.getValidationState(), 'validated')
126 127
    organisation = person.getSubordinationValue()
    self.assertTrue(organisation is not None)
128 129
    self.assertEqual(organisation.getValidationState(), 'validated')
    self.assertEqual(organisation.getTitle(),
130
                      form_kw['source_organisation_title'])
131 132

  def test_02_Contact_Us_with_Aunthenticated_user(self):
Leonardo Rochael Almeida's avatar
Leonardo Rochael Almeida committed
133
    """Test creation of Web Message with Authenticated User
134 135 136
    """
    web_section = self.setupWebSection()
    self.logout()
137
    self.loginByUserName('robby')
138 139 140 141 142
    form_kw = {'source_organisation_title': 'John Doe Industries',
               'source_person_first_name': 'John',
               'source_person_last_name': 'Doe',
               'source_person_default_email_text': 'John.Doe@example.com',
               'source_person_default_telephone_text': '34343434',
143
               'text_content': 'I want ERP5 for my company',
144 145
              }
    web_section.WebSection_addWebMessage(**form_kw)
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    transaction.commit()
    # here we check a random bug caused by the ordering of activities
    should_stop = [None]
    event_module_path_prefix = self.portal.event_module.getPath() + '/'
    deprioritize_message_list = []
    # we'll stop whenever we find the message that reindex the newly created
    # event object
    def stop_condition(message_list):
      for message in message_list:
        object_path = '/'.join(message.object_path)
        if (message.method_id == 'immediateReindexObject' and
            object_path.startswith(event_module_path_prefix)):
          deprioritize_message_list.append(message)
          return True
      return False
    self.tic(stop_condition=stop_condition)
    web_message_reindex_message, = deprioritize_message_list
    web_message_path = web_message_reindex_message.object_path
    self.assertTrue(
      self.portal.unrestrictedTraverse(web_message_path).getPortalType(),
      'Web Message',
    )
    # we'll deprioritize this message, so it executes last of all
    self.portal.cmf_activity_sql_connection.manage_test("""
      update message set priority=100
      where uid=%s
    """ % web_message_reindex_message.uid)
    transaction.commit()
174 175 176 177
    self.tic()
    self.logout()

    self.login()
178
    telephone_key = "source_person_default_telephone_text"
179 180 181
    # Now a web message has been created
    event = self.portal.event_module.objectValues()[0]
    for property_id, value in form_kw.iteritems():
182 183
      if property_id == telephone_key:
        value =  '+(0)-%s' % value
184
      self.assertEqual(event.getProperty(property_id), value)
185

186
    self.assertEqual(event.getSourceCarrier(), web_section.getRelativeUrl())
187 188 189 190 191 192 193
    self.assertTrue(event.hasStartDate())
    self.assertTrue(event.hasSource()) # User was connected
                                       # he became source of event

    # Trig alarm execution
    self.portal.portal_alarms.fetch_incoming_web_message_list.activeSense()
    self.tic()
194
    self.assertEqual(event.getSimulationState(), 'delivered')
195 196 197 198 199

def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestERP5WebWithCRM))
  return suite