testBug.py 7.84 KB
Newer Older
1 2
##############################################################################
#
3
# Copyright (c) 2007 Nexedi SA and Contributors. All Rights Reserved.
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
#                    Kevin Deldycke <kevin_AT_nexedi_DOT_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
from zLOG import LOG
from Testing import ZopeTestCase
from DateTime import DateTime
from Products.CMFCore.utils import getToolByName
35
from Products.ERP5Type.Utils import convertToUpperCase
36 37
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList
38
from Products.ERP5Type.tests.utils import DummyMailHost
39 40 41 42 43 44 45 46 47 48 49 50
from AccessControl.SecurityManagement import newSecurityManager


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'



51
class TestBug(ERP5TypeTestCase):
52
  """
53
    ERP5 unit tests for Bug module (part of erp5_forge business template).
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  """

  # pseudo constants
  RUN_ALL_TEST = 1
  QUIET = 1


  ##################################
  ##  ZopeTestCase Skeleton
  ##################################

  def getTitle(self):
    """
      Return the title of the current test set.
    """
69
    return "Bug"
70 71 72 73 74 75


  def getBusinessTemplateList(self):
    """
      Return the list of required business templates.
    """
76 77 78
    return ( 'erp5_base'
           , 'erp5_forge'
           )
79 80 81 82 83 84 85


  def afterSetUp(self, quiet=QUIET, run=RUN_ALL_TEST):
    """
      Initialize the ERP5 site.
    """
    self.login()
86 87
    self.datetime      = DateTime()  # Save today at initialisation to "freeze" the time
    self.portal        = self.getPortal()
Kevin Deldycke's avatar
Kevin Deldycke committed
88
    self.workflow_tool = self.portal.portal_workflow
89 90 91 92 93
    # Use a dummy mailhost to not send mail notification to the guy how run unit test
    if 'MailHost' in self.portal.objectIds():
      self.portal.manage_delObjects(['MailHost'])
      self.portal._setObject('MailHost', DummyMailHost('MailHost'))

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115


  ##################################
  ##  Usefull methods
  ##################################

  def login(self, quiet=QUIET, run=RUN_ALL_TEST):
    """
      Create a new manager user and login.
    """
    user_name = 'kevin'
    user_folder = self.getPortal().acl_users
    user_folder._doAddUser(user_name, '', ['Manager', 'Owner', 'Assignor'], [])
    user = user_folder.getUserById(user_name).__of__(user_folder)
    newSecurityManager(None, user)



  ##################################
  ##  Basic steps
  ##################################

116
  def stepTic(self, **kw):
117
    """
118
      Flush activity queue.
119
    """
120
    self.tic()
121 122


123
  def stepCreateBug(self, sequence=None, sequence_list=None, **kw):
124
    """
125
      Create a dummy bug
126
    """
127 128 129 130 131 132 133
    portal_type = 'Bug'
    bug_module = self.portal.getDefaultModule(portal_type)
    bug = bug_module.newContent( portal_type       = portal_type
                               , immediate_reindex = 1
                               , title             = 'This is an important bug'
                               , description       = 'This %µ&~#^@! bug always happend on ERP5 start. The solution consist to kill the developper.'
                               , start_date        = self.datetime  # Today
134
                               , stop_date         = self.datetime  # Today
135 136 137 138 139
                               )
    sequence.edit(bug = bug)


  def stepOpenBug(self, sequence=None, sequence_list=None, **kw):
140
    """
141
      Open the bug.
142
    """
143 144 145 146 147 148
    bug = sequence.get('bug')
    self.workflow_tool.doActionFor(bug, 'open_action')
    self.assertEquals(bug.getValidationState(), 'open')


  def stepCloseBug(self, sequence=None, sequence_list=None, **kw):
149
    """
150
      Close the bug.
151
    """
152 153
    bug = sequence.get('bug')
    self.workflow_tool.doActionFor(bug, 'close_action')
Kevin Deldycke's avatar
Kevin Deldycke committed
154
    self.assertEquals(bug.getValidationState(), 'closed')
155 156


157
  def stepCancelBug(self, sequence=None, sequence_list=None, **kw):
158
    """
159
      Cancel the bug.
160
    """
161 162
    bug = sequence.get('bug')
    self.workflow_tool.doActionFor(bug, 'cancel_action')
Kevin Deldycke's avatar
Kevin Deldycke committed
163
    self.assertEquals(bug.getValidationState(), 'cancelled')
164 165 166


  def stepFollowBug(self, sequence=None, sequence_list=None, **kw):
167
    """
168
      The bug reporter don't know how to nicely report a bug. Tell him.
169
    """
170 171 172 173 174
    bug = sequence.get('bug')
    self.workflow_tool.doActionFor(bug, 'follow_action', comment="Your Bug report is bad. You don't know how to report a bug. Please read http://www.chiark.greenend.org.uk/~sgtatham/bugs.html and resubmit your bug.")


  def stepSetTestedBug(self, sequence=None, sequence_list=None, **kw):
175
    """
176
      Set the bug as unit tested.
177
    """
178 179 180
    bug = sequence.get('bug')
    bug.setTested(True)
    self.assertEquals(bug.getTested(), True)
181 182


183
  def stepSetOldClosedDate(self, sequence=None, sequence_list=None, **kw):
184
    """
185
      Change Closed Date to a funky old value.
186
    """
187 188 189
    bug = sequence.get('bug')
    bug.setStopDate(self.datetime - 10)
    self.assertEquals(bug.getStopDate(), self.datetime - 10) # Check that datetime is fixed
190 191


192
  def stepCheckClosedDate(self, sequence=None, sequence_list=None, **kw):
193
    """
194
      Check that the closed date is set as today.
195
    """
196 197
    bug = sequence.get('bug')
    self.assertEquals(bug.getStopDate(), self.datetime)
198

199 200 201 202 203 204 205


  ##################################
  ##  Tests
  ##################################

  def test_01_StopDateUpdatedOnClose(self, quiet=QUIET, run=RUN_ALL_TEST):
206
    """
207
      Test that a closed bug has its stop date property updated.
208 209 210
    """
    if not run: return
    sequence_list = SequenceList()
211 212 213 214
    step_list = [ 'stepCreateBug'
                , 'stepOpenBug'
                , 'stepTic'
                , 'stepSetOldClosedDate'
Kevin Deldycke's avatar
Kevin Deldycke committed
215
                , 'stepSetTestedBug'
216 217 218
                , 'stepCloseBug'
                , 'stepTic'
                , 'stepCheckClosedDate'
219 220 221 222 223
                ]
    sequence_string = ' '.join(step_list)
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

224 225

  def test_02_StopDateUpdatedOnCancel(self, quiet=QUIET, run=RUN_ALL_TEST):
226
    """
227
      Same test as above but on cancel action (test bug #600).
228 229 230
    """
    if not run: return
    sequence_list = SequenceList()
231 232 233 234 235 236 237
    step_list = [ 'stepCreateBug'
                , 'stepOpenBug'
                , 'stepTic'
                , 'stepSetOldClosedDate'
                , 'stepCancelBug'
                , 'stepTic'
                , 'stepCheckClosedDate'
238 239 240 241 242
                ]
    sequence_string = ' '.join(step_list)
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

243

244 245 246 247 248 249 250

if __name__ == '__main__':
  framework()
else:
  import unittest
  def test_suite():
    suite = unittest.TestSuite()
251
    suite.addTest(unittest.makeSuite(TestBug))
252
    return suite