testBug.py 7.8 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, DummyMailHost
36 37 38 39 40 41 42 43 44 45 46 47 48 49
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList
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'



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

  # pseudo constants
  RUN_ALL_TEST = 1
  QUIET = 1


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

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


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


  def afterSetUp(self, quiet=QUIET, run=RUN_ALL_TEST):
    """
      Initialize the ERP5 site.
    """
    self.login()
85 86
    self.datetime      = DateTime()  # Save today at initialisation to "freeze" the time
    self.portal        = self.getPortal()
Kevin Deldycke's avatar
Kevin Deldycke committed
87
    self.workflow_tool = self.portal.portal_workflow
88 89 90 91 92
    # 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'))

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


  ##################################
  ##  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
  ##################################

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


122
  def stepCreateBug(self, sequence=None, sequence_list=None, **kw):
123
    """
124
      Create a dummy bug
125
    """
126 127 128 129 130 131 132
    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
133
                               , stop_date         = self.datetime  # Today
134 135 136 137 138
                               )
    sequence.edit(bug = bug)


  def stepOpenBug(self, sequence=None, sequence_list=None, **kw):
139
    """
140
      Open the bug.
141
    """
142 143 144 145 146 147
    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):
148
    """
149
      Close the bug.
150
    """
151 152
    bug = sequence.get('bug')
    self.workflow_tool.doActionFor(bug, 'close_action')
Kevin Deldycke's avatar
Kevin Deldycke committed
153
    self.assertEquals(bug.getValidationState(), 'closed')
154 155


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


  def stepFollowBug(self, sequence=None, sequence_list=None, **kw):
166
    """
167
      The bug reporter don't know how to nicely report a bug. Tell him.
168
    """
169 170 171 172 173
    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):
174
    """
175
      Set the bug as unit tested.
176
    """
177 178 179
    bug = sequence.get('bug')
    bug.setTested(True)
    self.assertEquals(bug.getTested(), True)
180 181


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


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

198 199 200 201 202 203 204


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

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

223 224

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

242

243 244 245 246 247 248 249

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