testPlanningBox.py 5.93 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
##############################################################################
#
# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
#          Rafael Monnerat <rafael@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.
#
##############################################################################

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.Utils import get_request
from StringIO import StringIO
34
from DateTime import DateTime
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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

class DummyFieldStorage:
  """A dummy FieldStorage to be wrapped in a FileUpload object.
  """ 
  def __init__(self):
    self.file = StringIO()
    self.filename = '<dummy field storage>'
    self.headers = {}

class TestPlanningBox(ERP5TypeTestCase):
  """
    Test the API of PlanningBox. The user-visible aspect is 
    not tested here.
  """
  quiet = 1
  run_all_test = 1
 
  def getBusinessTemplateList(self):
    # Use the same framework as the functional testing for convenience.
    # This adds some specific portal types and skins.
     return ('erp5_ui_test',)

  def getTitle(self):
     return "PlanningBox"

  def afterSetUp(self):
     self.login()

  def login(self):
    uf = self.getPortal().acl_users
    uf._doAddUser('seb', '', ['Manager'], [])
    user = uf.getUserById('seb').__of__(uf)
    newSecurityManager(None, user)

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

  def stepCreateObjects(self, sequence = None, sequence_list = None, **kw):
    # Make sure that the status is clean.
    portal = self.getPortal()
    portal.ListBoxZuite_reset()
    message = portal.foo_module.FooModule_createObjects()
    self.failUnless('Created Successfully' in message)

  def stepCreateObjectLines(self, sequence = None, sequence_list = None, **kw):
    # Make sure that the status is clean.
    portal = self.getPortal()
    message = portal.foo_module['0'].Foo_createObjects(num=1)
    self.failUnless('Created Successfully' in message)
84
    portal.foo_module['0'].Foo_editObjectLineDates()
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

  def stepRenderStructure(self, sequence = None, sequence_list = None, **kw):
    portal = self.getPortal()
    context = portal.foo_module['0']
    planningbox = context.Foo_viewPlanningBox.planning_box
    request = get_request()
    request['here'] = context
    #planningboxline_list = planningbox.get_value('default', REQUEST = request)
    basic, planning = planningbox.widget.render_structure(field=planningbox, 
                                                          REQUEST=request, 
                                                          context=context)
    sequence.edit(planning_box = planningbox,
                    basic=basic,
                    planning=planning)

  def stepCheckPlanning(self, sequence = None, sequence_list = None, **kw):
101
    planning = sequence.get('planning')
102
    self.assertEquals(planning.vertical_view, 0)
103 104
    self.assertEquals(len(planning.content), 1)
    bloc = planning.content[0]
105
    self.assertEquals(bloc.name , 'group_1_activity_1_block_1')
106 107 108
    self.assertEquals(bloc.title , 'Title 0')
    for info in bloc.info.values():
      self.assertEquals(info.info,'Title 0')
109 110
      self.assertEquals(info.link , 
                        '%s/foo_module/0/0/view' % self.getPortal().absolute_url())
111 112 113 114
    # Check Parent Activities
    parent = bloc.parent_activity
    for info in parent.info.values():
      self.assertEquals(info,'Title 0')
115 116
    self.assertEquals(parent.link , 
                      '/%s/foo_module/0/0' % self.getPortal().getId())
117 118 119 120
    # XXX This test for Quantity is not complete, It should be improved. 
    self.assertEquals(parent.height , None)
    self.assertEquals(parent.title,'Title 0')

121 122
  def stepCheckBasic(self, sequence = None, sequence_list = None, **kw):
    basic = sequence.get('basic')
123 124 125
    self.assertEquals(len(basic.report_group_list), 1)
    lane_tree_list = basic.buildLaneTreeList()
    sec_axis_info = basic.getLaneAxisInfo(lane_tree_list)
126 127 128 129 130
    date = DateTime()
    today = DateTime('%s/%s/%s' % (date.year(),date.month(),date.day()))
    self.assertEquals(sec_axis_info['bound_start'], today)
    self.assertEquals(sec_axis_info['bound_stop'], today+1)

131
    for tree_list, activity_list,stat in basic.report_group_list:
132 133
      self.assertEquals(len(activity_list), 1)

134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
  def test_01(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()
    sequence_string = '\
                       CreateObjects \
                       Tic \
                       CreateObjectLines \
                       Tic \
                       RenderStructure \
                       CheckPlanning \
                       CheckBasic \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

Rafael Monnerat's avatar
Rafael Monnerat committed
150 151 152 153 154
import unittest
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestPlanningBox))
  return suite
155