testFieldLibraryGuideline.py 14.3 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 40 41 42 43 44 45 46 47
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Nexedi SA 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 unittest

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList

class TestFieldLibraryGuideline(ERP5TypeTestCase):
  business_template_title = 'erp5_geek'
  skin_folder_name = 'erp5_geek'
  field_library_id = 'Base_viewGeekFieldLibrary'
  wrong_field_library_id = 'Geek_viewFieldLibrary'
  form_id = 'Base_viewGeek'

  def getTitle(self):
    return "Field Library Guideline Test"

  def getBusinessTemplateList(self):
    """  """
    return (
      'erp5_base',
48
      'erp5_crm',
49
      'erp5_administration',
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
      )

  def beforeTearDown(self):
    """
    Remove objects created in tests.
    """
    # Remove skin folder
    if 'erp5_geek' in self.getSkinsTool().objectIds():
      self.getSkinsTool().manage_delObjects(['erp5_geek'])
      ps = self.getSkinsTool()
      for skin_name, selection in ps.getSkinPaths():
        new_selection = []
        selection = selection.split(',')
        for skin_id in selection:
          if skin_id != 'erp5_geek':
            new_selection.append(skin_id)
        ps.manage_skinLayers(skinpath=tuple(new_selection),
                             skinname=skin_name, add_skin=1)
68
    self.commit()
69 70 71 72 73 74 75 76

  def stepCreateSkinFolder(self, sequence=None, sequence_list=None, **kw):
    """
    Create a skin folder
    """
    ps = self.getSkinsTool()
    ps.manage_addProduct['OFSP'].manage_addFolder(self.skin_folder_name)
    skin_folder = ps._getOb(self.skin_folder_name, None)
77
    self.assertTrue(skin_folder is not None)
78 79 80 81 82
    sequence.edit(skin_folder_id=skin_folder.getId())
    # add skin in layers
    for skin_name, selection in ps.getSkinPaths():
      selection = selection.split(',')
      selection.append(self.skin_folder_name)
83
      ps.manage_skinLayers(skinpath=tuple(selection), skinname=skin_name,
84 85
                           add_skin=1)

86
  def stepCreateNewBusinessTemplate(self, sequence=None,
87 88 89 90 91 92 93 94 95 96 97
                                    sequence_list=None, **kw):
    """
    Create a new Business Template
    """
    template_tool = self.getTemplateTool()
    template = template_tool.newContent(
        portal_type='Business Template',
        title=self.business_template_title,
        template_skin_id_list=[self.skin_folder_name])
    sequence.edit(custom_business_template=template)

98
  def stepCheckMissingFieldLibrary(self, sequence=None,
99 100 101 102 103 104 105
                                   sequence_list=None, **kw):
    """
    Check that the dialog propose to create the field library
    """
    business_template = sequence.get('custom_business_template')
    modifiable_field_list = \
        business_template.BusinessTemplate_getModifiableFieldList()
106
    self.assertEqual(1, len(modifiable_field_list))
107
    modifiable_field = modifiable_field_list[0]
108
    self.assertEqual('1_create_form', modifiable_field.choice[0])
109
    self.assertEqual('%s/%s' % (self.skin_folder_name, self.field_library_id),
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
                      modifiable_field.object_id)

  def test_01_missingFieldLibrary(self):
    """
    Create an business template with an empty skin folder.
    Check that the 'Manage Field Library' action propose to create the field
    library.
    """
    sequence_list = SequenceList()
    sequence_string = '\
                       CreateSkinFolder \
                       CreateNewBusinessTemplate \
                       CheckMissingFieldLibrary \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def createForm(self, form_id):
    skin_tool = self.getSkinsTool()
    skin_folder = skin_tool._getOb(self.skin_folder_name)
    addERP5Form = skin_folder.manage_addProduct['ERP5Form'].addERP5Form
    addERP5Form(form_id, 'View')
    return skin_folder._getOb(form_id)

134
  def stepCreateFieldLibrary(self, sequence=None,
135 136 137 138 139 140 141
                             sequence_list=None, **kw):
    """
    Create a Field Library
    """
    form = self.createForm(self.field_library_id)
    sequence.edit(field_library=form)

142
  def stepCreateForm(self, sequence=None,
143 144 145 146 147 148 149
                     sequence_list=None, **kw):
    """
    Create a Form
    """
    form = self.createForm(self.form_id)
    sequence.edit(form=form)

150
  def stepCreateNotProxifiedField(self, sequence=None,
151 152 153 154 155 156 157 158
                                  sequence_list=None, **kw):
    """
    Create a not proxified field
    """
    form = sequence.get('form')
    addField = form.manage_addProduct['Formulator'].manage_addField
    addField('my_title', 'Title', 'StringField')

159
  def stepCheckToProxifyField(self, sequence=None,
160 161 162 163 164 165 166
                         sequence_list=None, **kw):
    """
    Check that the dialog propose to proxify the field
    """
    business_template = sequence.get('custom_business_template')
    modifiable_field_list = \
        business_template.BusinessTemplate_getModifiableFieldList()
167
    self.assertEqual(1, len(modifiable_field_list))
168
    modifiable_field = modifiable_field_list[0]
169
    self.assertEqual('0_keep_non_proxy_field',
170
                      modifiable_field.choice_item_list[0][1])
171
    self.assertEqual('%s/%s/my_title' % (self.skin_folder_name,
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
                                          self.form_id),
                      modifiable_field.object_id)

  def test_02_notProxifiedField(self):
    """
    Create an business template with a skin folder containing a Field Library.
    Add a form to the skin folder.
    Add a not proxified field inside this form.
    Check that the 'Manage Field Library' action propose to proxify the field.
    """
    sequence_list = SequenceList()
    sequence_string = '\
                       CreateSkinFolder \
                       CreateFieldLibrary \
                       CreateForm \
                       CreateNotProxifiedField \
                       CreateNewBusinessTemplate \
                       CheckToProxifyField \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

194
  def stepCreateDeadProxyField(self, sequence=None,
195 196 197 198 199 200 201 202
                               sequence_list=None, **kw):
    """
    Create a dead proxy field
    """
    form = sequence.get('form')
    addField = form.manage_addProduct['Formulator'].manage_addField
    addField('my_title', 'Title', 'ProxyField')

203
  def stepCheckDeadFieldDetection(self, sequence=None,
204 205 206 207 208 209 210
                                  sequence_list=None, **kw):
    """
    Check that the dialog detects the dead proxy field
    """
    business_template = sequence.get('custom_business_template')
    modifiable_field_list = \
        business_template.BusinessTemplate_getModifiableFieldList()
211
    self.assertEqual(1, len(modifiable_field_list))
212
    modifiable_field = modifiable_field_list[0]
213
    self.assertEqual('0_keep_dead_proxy_field',
214
                      modifiable_field.choice_item_list[0][1])
215
    self.assertEqual('%s/%s/my_title' % (self.skin_folder_name,
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
                                          self.form_id),
                      modifiable_field.object_id)

  def test_03_deadProxyField(self):
    """
    Create an business template with a skin folder containing a Field Library.
    Add a form to the skin folder.
    Add a dead proxy field inside this form.
    Check that the 'Manage Field Library' detects this dead proxy field.
    """
    sequence_list = SequenceList()
    sequence_string = '\
                       CreateSkinFolder \
                       CreateFieldLibrary \
                       CreateForm \
                       CreateDeadProxyField \
                       CreateNewBusinessTemplate \
                       CheckDeadFieldDetection \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

238
  def stepCreateTemplateField(self, sequence=None,
239 240 241 242 243 244 245 246
                               sequence_list=None, **kw):
    """
    Create a template field
    """
    form = sequence.get('field_library')
    addField = form.manage_addProduct['Formulator'].manage_addField
    addField('my_title', 'Title', 'ProxyField')

247
  def stepCheckUnusedTemplateFieldDetection(self, sequence=None,
248 249 250 251 252 253 254
                                            sequence_list=None, **kw):
    """
    Check that the dialog detects this unused proxy field.
    """
    business_template = sequence.get('custom_business_template')
    modifiable_field_list = \
        business_template.BusinessTemplate_getModifiableFieldList()
255
    self.assertEqual(1, len(modifiable_field_list))
256
    modifiable_field = modifiable_field_list[0]
257
    self.assertEqual('0_unused_proxy_field',
258
                      modifiable_field.choice_item_list[0][1])
259
    self.assertEqual('%s/%s/my_title' % (self.skin_folder_name,
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
                                          self.field_library_id),
                      modifiable_field.object_id)

  def test_04_unusedProxyField(self):
    """
    Create an business template with a skin folder containing a Field Library.
    Add a template field inside the field library.
    Check that the 'Manage Field Library' detects this unused proxy field.
    """
    sequence_list = SequenceList()
    sequence_string = '\
                       CreateSkinFolder \
                       CreateFieldLibrary \
                       CreateTemplateField \
                       CreateNewBusinessTemplate \
                       CheckUnusedTemplateFieldDetection \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

280
  def stepCreateWronglyProxifiedField(self, sequence=None,
281 282 283 284 285 286 287 288 289 290 291 292
                                      sequence_list=None, **kw):
    """
    Create a wrong proxy field
    """
    form = sequence.get('form')
    addField = form.manage_addProduct['Formulator'].manage_addField
    addField('my_title', 'Title', 'ProxyField')
    field = getattr(form, 'my_title')
    field.manage_edit_xmlrpc(dict(
            form_id='Organisation_view',
            field_id='my_title'))

293
  def stepCheckWrongProxificationDetection(self, sequence=None,
294 295 296 297 298 299 300
                                           sequence_list=None, **kw):
    """
    Check that the dialog detects the wrong proxification.
    """
    business_template = sequence.get('custom_business_template')
    modifiable_field_list = \
        business_template.BusinessTemplate_getModifiableFieldList()
301
    self.assertEqual(1, len(modifiable_field_list))
302
    modifiable_field = modifiable_field_list[0]
303
    self.assertEqual('2_unproxify_field',
304
                      modifiable_field.choice_item_list[0][1])
305
    self.assertEqual('%s/%s/my_title' % (self.skin_folder_name,
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
                                          self.form_id),
                      modifiable_field.object_id)

  def test_05_wrongProxification(self):
    """
    Create an business template with a skin folder containing a Field Library.
    Add a form to the skin folder.
    Add a proxy field (inside this form) linking to another Field Library.

    Check that the 'Manage Field Library' detects this wrong proxification.
    """
    sequence_list = SequenceList()
    sequence_string = '\
                       CreateSkinFolder \
                       CreateFieldLibrary \
                       CreateForm \
                       CreateWronglyProxifiedField \
                       CreateNewBusinessTemplate \
                       CheckWrongProxificationDetection \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

329
  def stepCreateWrongFieldLibrary(self, sequence=None,
330 331 332 333 334 335 336
                                  sequence_list=None, **kw):
    """
    Create a Field Library with a wrong name.
    """
    form = self.createForm(self.wrong_field_library_id)
    sequence.edit(wrong_field_library=form)

337
  def stepCheckWrongFieldLibraryDetection(self, sequence=None,
338 339 340 341 342 343 344
                                          sequence_list=None, **kw):
    """
    Check that the dialog detects the wrong field library.
    """
    business_template = sequence.get('custom_business_template')
    modifiable_field_list = \
        business_template.BusinessTemplate_getModifiableFieldList()
345
    self.assertEqual(1, len(modifiable_field_list))
346
    modifiable_field = modifiable_field_list[0]
347
    self.assertEqual('4_delete_form', modifiable_field.choice[0])
348 349
    self.assertEqual('%s/%s' % (self.skin_folder_name,
                                 self.wrong_field_library_id),
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
                      modifiable_field.object_id)

  def test_06_wrongFieldLibrary(self):
    """
    Create an business template with a skin folder containing a Field Library.
    Add aother field library in this skin folder.
    Check that the 'Manage Field Library' detects this wrong field library.
    """
    sequence_list = SequenceList()
    sequence_string = '\
                       CreateSkinFolder \
                       CreateFieldLibrary \
                       CreateWrongFieldLibrary \
                       CreateNewBusinessTemplate \
                       CheckWrongFieldLibraryDetection \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestFieldLibraryGuideline))
  return suite