testBase.py 23.4 KB
Newer Older
Romain Courteaud's avatar
Romain Courteaud committed
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 52 53 54 55
##############################################################################
#
# Copyright (c) 2004, 2005 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.
#
##############################################################################

#
# Skeleton ZopeTestCase
#

from random import randint

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 Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager, \
                                             noSecurityManager
from DateTime import DateTime
from Acquisition import aq_base, aq_inner
from zLOG import LOG
from Products.ERP5Type.DateUtils import addToDate
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
import time
import os
from Products.ERP5Type import product_path
from Products.CMFCore.utils import getToolByName
56
from Products.ERP5Type.Tool.ClassTool import _aq_reset
Romain Courteaud's avatar
Romain Courteaud committed
57 58 59 60 61

class TestBase(ERP5TypeTestCase):

  run_all_test = 1
  object_portal_type = "Organisation"
62 63
  not_defined_property_id = "azerty_qwerty"
  not_defined_property_value = "qwerty_azerty"
Romain Courteaud's avatar
Romain Courteaud committed
64 65 66 67 68 69 70

  def getTitle(self):
    return "Base"

  def getBusinessTemplateList(self):
    """
    """
Sebastien Robin's avatar
Sebastien Robin committed
71
    return ('erp5_base')
Romain Courteaud's avatar
Romain Courteaud committed
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

  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()
    portal = self.getPortal()
    self.category_tool = self.getCategoryTool()
    portal_catalog = self.getCatalogTool()
    #portal_catalog.manage_catalogClear()
    self.createCategories()

  def createCategories(self):
    """ 
      Light install create only base categories, so we create 
      some categories for testing them
    """
Romain Courteaud's avatar
Romain Courteaud committed
106 107 108 109 110
    category_list = ['testGroup1', 'testGroup2']
    if len(self.category_tool.group.contentValues()) == 0 :
      for category_id in category_list:
        o = self.category_tool.group.newContent(portal_type='Category',
                                                id=category_id)
Romain Courteaud's avatar
Romain Courteaud committed
111 112 113 114

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

Romain Courteaud's avatar
Romain Courteaud committed
115 116
  def stepRemoveWorkflowsRelated(self, sequence=None, sequence_list=None, 
                                 **kw):
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    """
      Remove workflow related to the portal type
    """
    self.getWorkflowTool().setChainForPortalTypes(
        ['Organisation'], ())
    _aq_reset()

  def stepAssociateWorkflows(self, sequence=None, sequence_list=None, **kw):
    """
      Associate workflow to the portal type
    """
    self.getWorkflowTool().setChainForPortalTypes(
        ['Organisation'], ('validation_workflow', 'edit_workflow'))
    _aq_reset()

Romain Courteaud's avatar
Romain Courteaud committed
132 133
  def stepAssociateWorkflowsExcludingEdit(self, sequence=None, 
                                          sequence_list=None, **kw):
134 135 136 137 138 139 140
    """
      Associate workflow to the portal type
    """
    self.getWorkflowTool().setChainForPortalTypes(
        ['Organisation'], ('validation_workflow',))
    _aq_reset()

Romain Courteaud's avatar
Romain Courteaud committed
141 142
  def stepCreateObject(self, sequence=None, sequence_list=None, **kw):
    """
Romain Courteaud's avatar
Romain Courteaud committed
143
      Create a object_instance which will be tested.
Romain Courteaud's avatar
Romain Courteaud committed
144 145 146
    """
    portal = self.getPortal()
    module = portal.getDefaultModule(self.object_portal_type)
Romain Courteaud's avatar
Romain Courteaud committed
147
    object_instance = module.newContent(portal_type=self.object_portal_type)
Romain Courteaud's avatar
Romain Courteaud committed
148
    sequence.edit(
Romain Courteaud's avatar
Romain Courteaud committed
149
        object_instance=object_instance,
Romain Courteaud's avatar
Romain Courteaud committed
150 151
        current_title='',
        current_group_value=None
Romain Courteaud's avatar
Romain Courteaud committed
152 153 154 155 156 157
    )

  def stepCheckTitleValue(self, sequence=None, sequence_list=None, **kw):
    """
      Check if getTitle return a correect value
    """
Romain Courteaud's avatar
Romain Courteaud committed
158
    object_instance = sequence.get('object_instance')
Romain Courteaud's avatar
Romain Courteaud committed
159
    current_title = sequence.get('current_title')
Romain Courteaud's avatar
Romain Courteaud committed
160
    self.assertEquals(object_instance.getTitle(), current_title)
Romain Courteaud's avatar
Romain Courteaud committed
161

Romain Courteaud's avatar
Romain Courteaud committed
162 163
  def stepSetDifferentTitleValueWithEdit(self, sequence=None, 
                                         sequence_list=None, **kw):
Romain Courteaud's avatar
Romain Courteaud committed
164 165 166
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
167
    object_instance = sequence.get('object_instance')
Romain Courteaud's avatar
Romain Courteaud committed
168 169
    current_title = sequence.get('current_title')
    new_title_value = '%s_a' % current_title
Romain Courteaud's avatar
Romain Courteaud committed
170
    object_instance.edit(title=new_title_value)
Romain Courteaud's avatar
Romain Courteaud committed
171 172 173 174 175 176 177 178 179 180 181 182
    sequence.edit(
        current_title=new_title_value
    )

  def stepCheckIfActivitiesAreCreated(self, sequence=None, sequence_list=None,
                                      **kw):
    """
      Check if there is a activity in activity queue.
    """
    portal = self.getPortal()
    get_transaction().commit()
    message_list = portal.portal_activities.getMessageList()
183 184 185 186 187 188 189 190
    method_id_list = [x.method_id for x in message_list]
    # XXX FIXME: how many activities should be created normally ?
    # Sometimes it's one, sometimes 2...
    self.failUnless(len(message_list) > 0)
    self.failUnless(len(message_list) < 3)
    for method_id in method_id_list:
      self.failUnless(method_id in ["immediateReindexObject", 
                                    "recursiveImmediateReindexObject"])
Romain Courteaud's avatar
Romain Courteaud committed
191

Romain Courteaud's avatar
Romain Courteaud committed
192 193
  def stepSetSameTitleValueWithEdit(self, sequence=None, sequence_list=None, 
                                    **kw):
Romain Courteaud's avatar
Romain Courteaud committed
194 195 196
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
197 198
    object_instance = sequence.get('object_instance')
    object_instance.edit(title=object_instance.getTitle())
Romain Courteaud's avatar
Romain Courteaud committed
199 200 201 202 203 204 205 206 207 208

  def stepCheckIfMessageQueueIsEmpty(self, sequence=None, 
                                     sequence_list=None, **kw):
    """
      Check if there is no activity in activity queue.
    """
    portal = self.getPortal()
    message_list = portal.portal_activities.getMessageList()
    self.assertEquals(len(message_list), 0)

209 210 211 212 213 214 215 216 217 218
  def stepMakeImmediateReindexObjectCrashing(self, sequence=None, sequence_list=None, **kw):
    """
      Overwrite immediateReindexObject() with a crashing method
    """
    def crashingMethod(self):
      self.ImmediateReindexObjectIsCalled()
    from Products.ERP5Type.Document.Organisation import Organisation
    Organisation.immediateReindexObject = crashingMethod
    Organisation.recursiveImmediateReindexObject = crashingMethod

Romain Courteaud's avatar
Romain Courteaud committed
219 220
  def test_01_areActivitiesWellLaunchedByPropertyEdit(self, quiet=0, 
                                                      run=run_all_test):
Romain Courteaud's avatar
Romain Courteaud committed
221
    """
222 223
      Test if setter does not call a activity if the attribute 
      value is not changed.
Romain Courteaud's avatar
Romain Courteaud committed
224 225 226
    """
    if not run: return
    sequence_list = SequenceList()
227 228 229 230
    # Test without workflows associated to the portal type
    sequence_string = '\
              RemoveWorkflowsRelated \
              CreateObject \
Romain Courteaud's avatar
Romain Courteaud committed
231
              Tic \
232
              CheckTitleValue \
233
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
234
              SetDifferentTitleValueWithEdit \
235 236 237 238
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
Romain Courteaud's avatar
Romain Courteaud committed
239
              SetSameTitleValueWithEdit \
240
              CheckTitleValue \
241
              CheckIfMessageQueueIsEmpty \
Romain Courteaud's avatar
Romain Courteaud committed
242
              SetDifferentTitleValueWithEdit \
243 244 245 246 247 248 249 250 251 252
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test with workflows associated to the portal type
    sequence_string = '\
              AssociateWorkflows \
              CreateObject \
Romain Courteaud's avatar
Romain Courteaud committed
253
              Tic \
Romain Courteaud's avatar
Romain Courteaud committed
254
              CheckTitleValue \
255
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
256
              SetDifferentTitleValueWithEdit \
Romain Courteaud's avatar
Romain Courteaud committed
257 258 259 260
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
Romain Courteaud's avatar
Romain Courteaud committed
261
              SetSameTitleValueWithEdit \
262 263 264
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
Romain Courteaud's avatar
Romain Courteaud committed
265
              CheckIfMessageQueueIsEmpty \
Romain Courteaud's avatar
Romain Courteaud committed
266
              SetDifferentTitleValueWithEdit \
Romain Courteaud's avatar
Romain Courteaud committed
267 268 269 270 271 272
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    # Test with workflows associated to the portal type, excluding edit_workflow
    sequence_string = '\
              AssociateWorkflowsExcludingEdit \
              CreateObject \
              Tic \
              CheckTitleValue \
              MakeImmediateReindexObjectCrashing \
              SetDifferentTitleValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameTitleValueWithEdit \
              CheckIfMessageQueueIsEmpty \
              CheckTitleValue \
              SetDifferentTitleValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
Romain Courteaud's avatar
Romain Courteaud committed
295 296
    sequence_list.play(self)

Romain Courteaud's avatar
Romain Courteaud committed
297 298 299 300
  def stepCheckGroupValue(self, sequence=None, sequence_list=None, **kw):
    """
      Check if getTitle return a correect value
    """
Romain Courteaud's avatar
Romain Courteaud committed
301
    object_instance = sequence.get('object_instance')
Romain Courteaud's avatar
Romain Courteaud committed
302
    current_group_value = sequence.get('current_group_value')
Romain Courteaud's avatar
Romain Courteaud committed
303
    self.assertEquals(object_instance.getGroupValue(), current_group_value)
Romain Courteaud's avatar
Romain Courteaud committed
304 305 306 307 308 309

  def stepSetDifferentGroupValueWithEdit(self, sequence=None, 
                                         sequence_list=None, **kw):
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
310
    object_instance = sequence.get('object_instance')
Romain Courteaud's avatar
Romain Courteaud committed
311
    current_group_value = sequence.get('current_group_value')
Romain Courteaud's avatar
Romain Courteaud committed
312 313 314 315
    group1 = object_instance.portal_categories.\
                       restrictedTraverse('group/testGroup1')
    group2 = object_instance.portal_categories.\
                       restrictedTraverse('group/testGroup2')
Romain Courteaud's avatar
Romain Courteaud committed
316 317 318 319 320 321
    if (current_group_value is None) or \
       (current_group_value == group2) :
      new_group_value = group1
    else:
      new_group_value = group2
#     new_group_value = '%s_a' % current_title
Romain Courteaud's avatar
Romain Courteaud committed
322
    object_instance.edit(group_value=new_group_value)
Romain Courteaud's avatar
Romain Courteaud committed
323 324 325 326 327 328 329 330 331
    sequence.edit(
        current_group_value=new_group_value
    )

  def stepSetSameGroupValueWithEdit(self, sequence=None, sequence_list=None, 
                                    **kw):
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
332 333
    object_instance = sequence.get('object_instance')
    object_instance.edit(group_value=object_instance.getGroupValue())
Romain Courteaud's avatar
Romain Courteaud committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349


  def test_02_areActivitiesWellLaunchedByCategoryEdit(self, quiet=0, 
                                                      run=run_all_test):
    """
      Test if setter does not call a activity if the attribute 
      value is not changed.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test without workflows associated to the portal type
    sequence_string = '\
              RemoveWorkflowsRelated \
              CreateObject \
              Tic \
              CheckGroupValue \
350
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
              SetDifferentGroupValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameGroupValueWithEdit \
              CheckIfMessageQueueIsEmpty \
              SetDifferentGroupValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test with workflows associated to the portal type
    sequence_string = '\
              AssociateWorkflows \
              CreateObject \
              Tic \
              CheckGroupValue \
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
              MakeImmediateReindexObjectCrashing \
              SetDifferentGroupValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameGroupValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetDifferentGroupValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test with workflows associated to the portal type, excluding edit_workflow
    sequence_string = '\
              AssociateWorkflowsExcludingEdit \
              CreateObject \
              Tic \
              CheckGroupValue \
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
              SetDifferentGroupValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameGroupValueWithEdit \
              CheckIfMessageQueueIsEmpty \
              SetDifferentGroupValueWithEdit \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def stepSetDifferentTitleValueWithSetter(self, sequence=None, 
                                           sequence_list=None, **kw):
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
417
    object_instance = sequence.get('object_instance')
Romain Courteaud's avatar
Romain Courteaud committed
418 419
    current_title = sequence.get('current_title')
    new_title_value = '%s_a' % current_title
Romain Courteaud's avatar
Romain Courteaud committed
420
    object_instance.setTitle(new_title_value)
Romain Courteaud's avatar
Romain Courteaud committed
421 422 423 424 425 426 427 428 429
    sequence.edit(
        current_title=new_title_value
    )

  def stepSetSameTitleValueWithSetter(self, sequence=None, 
                                      sequence_list=None, **kw):
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
430 431
    object_instance = sequence.get('object_instance')
    object_instance.setTitle(object_instance.getTitle())
Romain Courteaud's avatar
Romain Courteaud committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446

  def test_03_areActivitiesWellLaunchedByPropertySetter(self, quiet=0, 
                                                        run=run_all_test):
    """
      Test if setter does not call a activity if the attribute 
      value is not changed.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test without workflows associated to the portal type
    sequence_string = '\
              RemoveWorkflowsRelated \
              CreateObject \
              Tic \
              CheckTitleValue \
447
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
448 449 450 451 452 453
              SetDifferentTitleValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameTitleValueWithSetter \
454 455 456
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
Romain Courteaud's avatar
Romain Courteaud committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470
              CheckIfMessageQueueIsEmpty \
              SetDifferentTitleValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test with workflows associated to the portal type
    sequence_string = '\
              AssociateWorkflows \
              CreateObject \
              Tic \
              CheckTitleValue \
471
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
472 473 474 475 476 477
              SetDifferentTitleValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameTitleValueWithSetter \
478 479 480
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
Romain Courteaud's avatar
Romain Courteaud committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
              CheckIfMessageQueueIsEmpty \
              SetDifferentTitleValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckTitleValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def stepSetDifferentGroupValueWithSetter(self, sequence=None, 
                                           sequence_list=None, **kw):
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
496
    object_instance = sequence.get('object_instance')
Romain Courteaud's avatar
Romain Courteaud committed
497
    current_group_value = sequence.get('current_group_value')
Romain Courteaud's avatar
Romain Courteaud committed
498 499 500 501
    group1 = object_instance.portal_categories.\
                                   restrictedTraverse('group/testGroup1')
    group2 = object_instance.portal_categories.\
                                   restrictedTraverse('group/testGroup2')
Romain Courteaud's avatar
Romain Courteaud committed
502 503 504 505 506 507
    if (current_group_value is None) or \
       (current_group_value == group2) :
      new_group_value = group1
    else:
      new_group_value = group2
#     new_group_value = '%s_a' % current_title
Romain Courteaud's avatar
Romain Courteaud committed
508
    object_instance.setGroupValue(new_group_value)
Romain Courteaud's avatar
Romain Courteaud committed
509 510 511 512 513 514 515 516 517
    sequence.edit(
        current_group_value=new_group_value
    )

  def stepSetSameGroupValueWithSetter(self, sequence=None, 
                                      sequence_list=None, **kw):
    """
      Set a different title value
    """
Romain Courteaud's avatar
Romain Courteaud committed
518 519
    object_instance = sequence.get('object_instance')
    object_instance.setGroupValue(object_instance.getGroupValue())
Romain Courteaud's avatar
Romain Courteaud committed
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534

  def test_04_areActivitiesWellLaunchedByCategorySetter(self, quiet=0, 
                                                        run=run_all_test):
    """
      Test if setter does not call a activity if the attribute 
      value is not changed.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test without workflows associated to the portal type
    sequence_string = '\
              RemoveWorkflowsRelated \
              CreateObject \
              Tic \
              CheckGroupValue \
535
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
536 537 538 539 540 541
              SetDifferentGroupValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameGroupValueWithSetter \
542 543 544
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
Romain Courteaud's avatar
Romain Courteaud committed
545 546 547 548 549 550 551 552 553 554 555 556 557 558
              CheckIfMessageQueueIsEmpty \
              SetDifferentGroupValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test with workflows associated to the portal type
    sequence_string = '\
              AssociateWorkflows \
              CreateObject \
              Tic \
              CheckGroupValue \
559
              MakeImmediateReindexObjectCrashing \
Romain Courteaud's avatar
Romain Courteaud committed
560 561 562 563 564 565
              SetDifferentGroupValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              SetSameGroupValueWithSetter \
566 567 568
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
Romain Courteaud's avatar
Romain Courteaud committed
569 570 571 572 573 574 575 576 577 578
              CheckIfMessageQueueIsEmpty \
              SetDifferentGroupValueWithSetter \
              CheckIfActivitiesAreCreated \
              CheckGroupValue \
              Tic \
              CheckIfMessageQueueIsEmpty \
              '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

579 580 581
  def stepSetObjectNotDefinedProperty(self, sequence=None, 
                                      sequence_list=None, **kw):
    """
Romain Courteaud's avatar
Romain Courteaud committed
582
    Set a not defined property on the object_instance.
583
    """
Romain Courteaud's avatar
Romain Courteaud committed
584 585
    object_instance = sequence.get('object_instance')
    object_instance.setProperty(self.not_defined_property_id,
586 587 588 589 590
                       self.not_defined_property_value)

  def stepCheckNotDefinedPropertySaved(self, sequence=None, 
                                       sequence_list=None, **kw):
    """
Romain Courteaud's avatar
Romain Courteaud committed
591
    Check if a not defined property is stored on the object_instance.
592
    """
Romain Courteaud's avatar
Romain Courteaud committed
593
    object_instance = sequence.get('object_instance')
594
    self.assertEquals(self.not_defined_property_value,
Romain Courteaud's avatar
Romain Courteaud committed
595
                      getattr(object_instance, self.not_defined_property_id))
596 597 598 599 600 601

  def stepCheckGetNotDefinedProperty(self, sequence=None, 
                                     sequence_list=None, **kw):
    """
    Check getProperty with a not defined property.
    """
Romain Courteaud's avatar
Romain Courteaud committed
602
    object_instance = sequence.get('object_instance')
603
    self.assertEquals(self.not_defined_property_value,
Romain Courteaud's avatar
Romain Courteaud committed
604
                    object_instance.getProperty(self.not_defined_property_id))
605 606 607 608

  def stepCheckObjectPortalType(self, sequence=None, 
                                sequence_list=None, **kw):
    """
Romain Courteaud's avatar
Romain Courteaud committed
609
    Check the portal type of the object_instance.
610
    """
Romain Courteaud's avatar
Romain Courteaud committed
611 612
    object_instance = sequence.get('object_instance')
    object_instance.getPortalType()
613
    self.assertEquals(self.object_portal_type,
Romain Courteaud's avatar
Romain Courteaud committed
614
                      object_instance.getPortalType())
615 616 617

  def stepCreateTempObject(self, sequence=None, sequence_list=None, **kw):
    """
Romain Courteaud's avatar
Romain Courteaud committed
618
      Create a temp object_instance which will be tested.
619 620 621 622 623
    """
    portal = self.getPortal()
    from Products.ERP5Type.Document import newTempOrganisation
    tmp_object = newTempOrganisation(portal, "a_wonderful_id")
    sequence.edit(
Romain Courteaud's avatar
Romain Courteaud committed
624
        object_instance=tmp_object,
625 626 627 628 629 630 631 632 633 634
        current_title='',
        current_group_value=None
    )

  def test_05_getPropertyWithoutPropertySheet(self, quiet=0, run=run_all_test):
    """
    Test if set/getProperty work without any property sheet.
    """
    if not run: return
    sequence_list = SequenceList()
Romain Courteaud's avatar
Romain Courteaud committed
635
    # Test on object_instance.
636 637 638 639 640 641 642
    sequence_string = '\
              CreateObject \
              SetObjectNotDefinedProperty \
              CheckNotDefinedPropertySaved \
              CheckGetNotDefinedProperty \
              '
    sequence_list.addSequenceString(sequence_string)
Romain Courteaud's avatar
Romain Courteaud committed
643
    # Test on temp object_instance.
644 645 646 647 648 649 650 651 652 653
    sequence_string = '\
              CreateTempObject \
              CheckObjectPortalType \
              SetObjectNotDefinedProperty \
              CheckNotDefinedPropertySaved \
              CheckGetNotDefinedProperty \
              '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

Romain Courteaud's avatar
Romain Courteaud committed
654 655 656 657 658 659 660 661
if __name__ == '__main__':
    framework()
else:
    import unittest
    def test_suite():
        suite = unittest.TestSuite()
        suite.addTest(unittest.makeSuite(TestBase))
        return suite