testGis.py 7.08 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
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
#          Romain Courteaud <romain@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 os, sys
if __name__ == '__main__':
  execfile(os.path.join(sys.path[0], 'framework.py'))

# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager, \
                                             noSecurityManager
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
40
from Products.ERP5Type.tests.utils import createZODBPythonScript
41

42
class TestGeographicalAddress(ERP5TypeTestCase):
Romain Courteaud's avatar
Romain Courteaud committed
43 44 45 46 47 48
  """
  ERP5 Geographical Address related tests.

  The purpose of this test is to check that the getText function defined
  on a Geographical Address returns the standard text format.
  """
49 50 51 52 53 54 55 56 57 58

  run_all_test = 1
  entity_portal_type = 'Person'
  address_portal_type = 'Address'
  street_address_text = "rue Truc"
  street_address_number = "11"
  zip_code_text = "12345"
  city_text = "City1"

  def getTitle(self):
59
    return "Geographical Address"
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

  def getBusinessTemplateList(self):
    """
    """
    return ('erp5_base', )

  def login(self, quiet=0, run=run_all_test):
    uf = self.getPortal().acl_users
    uf._doAddUser('rc', '', ['Manager'], [])
    user = uf.getUserById('rc').__of__(uf)
    newSecurityManager(None, user)

  def enableLightInstall(self):
    """
    You can override this. 
    Return if we should do a light install (1) or not (0)
    """
    return 1

  def enableActivityTool(self):
    """
    You can override this.
    Return if we should create (1) or not (0) an activity tool.
    """
    return 1

  def afterSetUp(self, quiet=1, run=run_all_test):
    self.login()
    self.portal = self.getPortal()
    self.category_tool = self.getCategoryTool()
    self.createCategories()

  def createCategories(self):
    """
      Light install create only base categories, so we create
      some categories for testing them
    """
    region_category_list = ['country1', 'country2', ]
    if len(self.category_tool.region.contentValues()) == 0 :
      for category_id in region_category_list:
        o = self.category_tool.region.newContent(portal_type='Category',
                                               id=category_id,
                                               title=category_id.capitalize())
    self.region_category_list = ['region/%s' % x for x \
                                  in region_category_list]

  def stepTic(self,**kw):
    self.tic()

  def stepCreateEntity(self, sequence=None, sequence_list=None, **kw):
    """
    Create an entity
    """
    portal = self.getPortal()
    module = portal.getDefaultModule(self.entity_portal_type)
    entity = module.newContent(portal_type=self.entity_portal_type)
    sequence.edit(
        entity=entity,
    )

  def stepCreateAddress(self, sequence=None, sequence_list=None, **kw):
    """
    Create a address
    """
    entity = sequence.get('entity')
    address = entity.newContent(portal_type=self.address_portal_type)
    sequence.edit(
        address=address,
    )

  def stepSetTextAddressValue(self, sequence=None, sequence_list=None, **kw):
    """
    Set standard text value.
    """
    address = sequence.get('address')
    address.setStreetAddress("%s %s" % (self.street_address_number,
                                        self.street_address_text))
    address.setZipCode(self.zip_code_text)
    address.setCity(self.city_text)
    address.setRegionValue(self.portal.portal_categories.region.country1)

  def stepCheckAddressText(self, sequence=None,
                           sequence_list=None, **kw):
    """
    Check getAddressText
    """
    address = sequence.get('address')
    self.assertEquals(address.asText(),
        "%s %s\n%s %s" % (self.street_address_number,
                          self.street_address_text,
                          self.city_text,
                          self.zip_code_text))

  def test_01_standardAddress(self, quiet=0, run=run_all_test):
    """
      Test property existence
    """
    if not run: return
    
    sequence_list = SequenceList()
    sequence_string = '\
              CreateEntity \
              CreateAddress \
              SetTextAddressValue \
              CheckAddressText \
              '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

169 170
  def stepCreateAsTextScript(self, sequence=None, **kw) :
    """
171
    This script returns a different address format.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    """
    createZODBPythonScript(self.getPortal().portal_skins.custom,
                           'Address_asText', '', """
return '%s\\n%s %s' % \\
       (context.getStreetAddress(),
        context.getZipCode(), context.getCity())
""")
  
  def stepCheckAddressAsTextScript(self, sequence=None,
                                   sequence_list=None, **kw):
    """
    Check getAddressText
    """
    address = sequence.get('address')
    self.assertEquals(address.asText(),
        "%s %s\n%s %s" % (self.street_address_number,
                          self.street_address_text,
                          self.zip_code_text,
                          self.city_text))

  def test_02_asTextScript(self, quiet=0, run=run_all_test):
    """
      Test property existence
    """
    if not run: return
    
    sequence_list = SequenceList()
    sequence_string = '\
              CreateEntity \
              CreateAddress \
              SetTextAddressValue \
              CreateAsTextScript \
              CheckAddressAsTextScript \
              '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

209 210 211 212 213 214
if __name__ == '__main__':
  framework()
else:
  import unittest
  def test_suite():
    suite = unittest.TestSuite()
215
    suite.addTest(unittest.makeSuite(TestGeographicalAddress))
216
    return suite