testERP5WebWithCRM.py 7.39 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# -*- 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
import transaction

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase,\
     _getConversionServerDict


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
52
            'erp5_jquery',
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
            'erp5_web',
            )

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

  def setSystemPreference(self):
    portal_type = 'System Preference'
    preference_list = self.portal.portal_preferences.contentValues(
                                                       portal_type=portal_type)
    if not preference_list:
      preference = self.portal.portal_preferences.newContent(
                                                       portal_type=portal_type)
    else:
      preference = preference_list[0]
    conversion_dict = _getConversionServerDict()
    preference.setPreferredOoodocServerAddress(conversion_dict['hostname'])
    preference.setPreferredOoodocServerPortNumber(conversion_dict['port'])
    if self.portal.portal_workflow.isTransitionPossible(preference, 'enable'):
      preference.enable()

  def clearModule(self, module):
    module.manage_delObjects(list(module.objectIds()))
    transaction.commit()
    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()
    transaction.commit()
    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',
110
               'text_content': 'I want ERP5 for my company',
111 112 113 114 115 116 117
              }
    web_section.WebSection_addWebMessage(**form_kw)
    transaction.commit()
    self.tic()

    self.login()
    # Now a web message has been created
118
    telephone_key = 'source_person_default_telephone_text'
119 120
    event = self.portal.event_module.objectValues()[0]
    for property_id, value in form_kw.iteritems():
121 122 123
      if property_id == telephone_key:
        value =  '+(0)-%s' % value

124 125 126 127 128 129 130 131
      self.assertEquals(event.getProperty(property_id), value)
    self.assertEquals(event.getSourceCarrier(), web_section.getRelativeUrl())
    self.assertTrue(event.hasStartDate())

    # Trig alarm execution
    self.portal.portal_alarms.fetch_incoming_web_message_list.activeSense()
    transaction.commit()
    self.tic()
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    self.assertEquals(event.getSimulationState(), 'acknowledged')
    ticket = event.getFollowUpValue()
    self.assertTrue(ticket is not None)
    self.assertEquals(ticket.getSimulationState(), 'submitted')
    person = event.getSourceValue()
    self.assertTrue(person is not None)
    self.assertEquals(person.getFirstName(),
                      form_kw['source_person_first_name'])
    self.assertEquals(person.getLastName(),
                      form_kw['source_person_last_name'])
    self.assertEquals(person.getDefaultEmailText(),
                      form_kw['source_person_default_email_text'])
    self.assertTrue(form_kw['source_person_default_telephone_text'] in\
                    person.getDefaultTelephoneText())
    self.assertEquals(person.getValidationState(), 'validated')
    organisation = person.getSubordinationValue()
    self.assertTrue(organisation is not None)
    self.assertEquals(organisation.getValidationState(), 'validated')
    self.assertEquals(organisation.getTitle(),
                      form_kw['source_organisation_title'])
152 153 154 155 156 157 158 159 160 161 162 163

  def test_02_Contact_Us_with_Aunthenticated_user(self):
    """Test creation of Web Message with Authenticted User
    """
    web_section = self.setupWebSection()
    self.logout()
    self.login('robby')
    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',
164
               'text_content': 'I want ERP5 for my company',
165 166 167 168 169 170 171
              }
    web_section.WebSection_addWebMessage(**form_kw)
    transaction.commit()
    self.tic()
    self.logout()

    self.login()
172
    telephone_key = "source_person_default_telephone_text"
173 174 175
    # Now a web message has been created
    event = self.portal.event_module.objectValues()[0]
    for property_id, value in form_kw.iteritems():
176 177
      if property_id == telephone_key:
        value =  '+(0)-%s' % value
178
      self.assertEquals(event.getProperty(property_id), value)
179

180 181 182 183 184 185 186 187 188
    self.assertEquals(event.getSourceCarrier(), web_section.getRelativeUrl())
    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()
    transaction.commit()
    self.tic()
189
    self.assertEquals(event.getSimulationState(), 'acknowledged')
190 191 192 193 194

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