testERP5eGov.py 14.2 KB
Newer Older
1
# -*- coding: utf-8 -*-
2 3
##############################################################################
#
4 5
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
#                 Mayoro DIAGNE <mayoro@gmail.com>
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
#
# 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.
#
##############################################################################


31 32 33 34
import unittest
import transaction

from Testing import ZopeTestCase
35 36
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager
37 38 39 40 41 42
from Products.ERP5Type.tests.utils import FileUpload

from zLOG import LOG
import os

TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_data')
43

44 45
def makeFilePath(name):
  return os.path.join(os.path.dirname(__file__), 'test_data', name)
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
def makeFileUpload(name, as_name=None):
  if as_name is None:
    as_name = name
  path = makeFilePath(name)
  return FileUpload(path, as_name)

class TestEgov(ERP5TypeTestCase):
  """
  This is the list of test for erp5_egov

  """
  # define all username corresponding to all roles used in eGov
  assignor_login = 'chef'
  assignee_login = 'agent'
  auditor_login = 'reviewer'
  associate_login = 'agent_requested'

  def getBusinessTemplateList(self):
    """return list of business templates to be installed. """
    bt_list = ['erp5_base',
               'erp5_web',
               'erp5_xhtml_style',
	       'erp5_ingestion',
               'erp5_dms',
               'erp5_egov_mysql_innodb_catalog',
72
               'erp5_egov']
73
    return bt_list
74 75

  def getTitle(self):
76
    return "Test ERP5 EGov"
77

78 79 80 81 82 83 84
  #XXX mayoro: these functions will be removed and replaced by subscriptions
  def createCitizenUser(self):
    """
    Create a user with Agent role to allow create and submit requests
    """
    uf = self.getPortal().acl_users
    uf._doAddUser('citizen', '', ['Agent',], [])
85

86 87 88 89
  def createValidatorUser(self):
    """
    Create a user with Agent role to allow create and submit requests
    """
90
    uf = self.getPortal().acl_users
91 92
    uf._doAddUser('major', '', ['Assignor',], [])

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  def createCategories(self):
    """Create the categories for our test. """
    # create categories
    for cat_string in self.getNeededCategoryList():
      base_cat = cat_string.split("/")[0]
      path = self.getPortal().portal_categories[base_cat]
      for cat in cat_string.split("/")[1:]:
        if not cat in path.objectIds():
          path = path.newContent(
            portal_type='Category',
            id=cat,)
        else:
          path = path[cat]
    self.tic()
    transaction.commit()
    # check categories have been created
    for cat_string in self.getNeededCategoryList() :
      self.assertNotEquals(None,
                self.getCategoryTool().restrictedTraverse(cat_string),
                cat_string)

  def getNeededCategoryList(self):
    """Returns a list of categories that should be created."""
    return ('group/client','group/client/dgid/di', 'group/client/dgid/bf',
            'function/impots/taxes_indirectes', 'function/impots/section/chef',
            'role/entreprise')

120 121 122 123 124
  def afterSetUp(self):
    uf = self.getPortal().acl_users
    uf._doAddUser('seb', '', ['Manager', 'Assignor','Assignee'], [])
    self.login('seb')
    user = uf.getUserById('seb').__of__(uf)
125
    newSecurityManager(None, user)
126
    self.portal = self.getPortalObject()
127
    self.createCategories()
128 129 130 131 132 133 134 135 136 137 138
    # enable preferences
    pref = self.portal.portal_preferences._getOb(
                  'flare_cache_preference', None)
    if pref is not None:
      if pref.getPreferenceState() == 'disabled':
        pref.enable()
    pref = self.portal.portal_preferences._getOb(
                  'egov_preference', None)
    if pref is not None:
      if pref.getPreferenceState() == 'disabled':
        pref.enable()
139

140 141 142 143 144 145 146 147 148
  def beforeTearDown(self):
    """
    remove all created objects between two tests, tests are stand-alone
    """
    transaction.abort()
    for module in [ self.getPersonModule(),
		    self.getOrganisationModule(),
		      ]:
      module.manage_delObjects(list(module.objectIds()))
149

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    vat_portal_type = self.portal.portal_types.getTypeInfo('Vat Declaration')
    vat_module_portal_type = self.portal.portal_types.getTypeInfo('Vat Declaration Module')
    if vat_portal_type is not None and vat_module_portal_type is not None:
      vat_module = self.portal.getDefaultModule('Vat Declaration')
      self.portal.portal_types.manage_delObjects([vat_portal_type.getId(), vat_module_portal_type.getId()])
      self.portal.manage_delObjects([vat_module.getId(),]) 
    self.portal.portal_caches.clearAllCache()
    transaction.commit()
    self.tic()

  def changeSkin(self, skin_name):
    """
      Change current Skin
    """
    request = self.app.REQUEST
    self.portal.portal_skins.changeSkin(skin_name)
    request.set('portal_skin', skin_name)

  def createNewProcedure(self):
    """
     This function create a new EGov Type   
    """
    return self.portal.portal_types.newContent(portal_type='EGov Type')


  def fillProcedureForm(self, procedure=None, procedure_title='fooo'):
    """
     This function fill the form of a given procedure. Filled field allow to 
     generate portal_type and portal_type module of this procedure, it also allow
     configuring securities of the new module and renaming actions   
    """
    # initialize values for new procedure
    # use accessors to verify if they are dynamically generated
    if procedure is None:
      return
185
    procedure.setOrganisationDirectionService('client/dgid/di')
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    procedure.setProcedureTitle(procedure_title)
    procedure.setProcedurePublicationSection('impots/taxes_indirectes')
    procedure.setProcedureTarget('entreprise')
    procedure.setStepAuthentication(1)
    procedure.setStepPrevalidation(1)
    procedure.setStepAttachment(1)
    procedure.setStepPostpayment(1)
    procedure.setStepDecision(1)
    procedure.setStepRemittance(1)
    # add one attchment
    procedure.setAttachmentTitle1('Justificatif numero 1')
    procedure.setAttachmentRequired1(1)
    procedure.setAttachmentModel1('PDF')
    procedure.setAttachmentJustificative1(1)

    # add security configuration
    # define security for agent to process (assignor)
203
    procedure.setInvolvedServiceGroup1('client/dgid/di')
204 205 206 207 208 209 210
    procedure.setInvolvedServiceFunction1('impots/section/chef')
    procedure.setInvolvedServiceProcess1(0)
    procedure.setInvolvedServiceValidate1(1)
    procedure.setInvolvedServiceView1(0)
    procedure.setInvolvedServiceAssociate1(0)
    # define security for agent to just process assigned
    # applications (Assignee)
211
    procedure.setInvolvedServiceGroup2('client/dgid/di')
212 213 214 215 216 217 218 219
    procedure.setInvolvedServiceFunction2('impots/inspecteur')
    procedure.setInvolvedServiceProcess2(1)
    procedure.setInvolvedServiceValidate2(0)
    procedure.setInvolvedServiceView2(0)
    procedure.setInvolvedServiceAssociate2(0)

    # define security for external agent to contribute
    # in processing (Associate)
220
    procedure.setInvolvedServiceGroup3('client/dgid/bf')
221 222 223 224 225 226 227
    procedure.setInvolvedServiceFunction3('impots/section/chef')
    procedure.setInvolvedServiceProcess3(0)
    procedure.setInvolvedServiceValidate3(0)
    procedure.setInvolvedServiceView3(0)
    procedure.setInvolvedServiceAssociate3(1)

    # define security for agent to just view (auditor)
228
    procedure.setInvolvedServiceGroup2('client/dgid/di')
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
    procedure.setInvolvedServiceFunction2('impots')
    procedure.setInvolvedServiceProcess2(0)
    procedure.setInvolvedServiceValidate2(0)
    procedure.setInvolvedServiceView2(1)
    procedure.setInvolvedServiceAssociate2(0)

    # configure portal_type for displaying subobjects
    scribus_file_name = 'Certificat_Residence.sla'
    pdf_file_name = 'Certificat_Residence.pdf'
    pdf_file_data = makeFileUpload(pdf_file_name)
    scribus_file_data = makeFileUpload(scribus_file_name)
    procedure.edit(default_scribus_form=scribus_file_data,
            default_pdf_form=pdf_file_data)
    self.tic()
    transaction.commit()
    self.tic()

  def test_01_new_procedure_creation(self):
    """ 
    this test create one procedure, initialize it by some datas, validate it
    to generate the module and portal_types and verify some properties  
    """
    procedure = self.createNewProcedure()
    self.fillProcedureForm(procedure, 'vat declaration')
    procedure.validate()
    vat_module = self.portal.getDefaultModule('Vat Declaration')
    self.assertEquals(vat_module.getId(), 'vat_declaration_module')
    vat_portal_type = self.portal.portal_types.getTypeInfo('Vat Declaration')
    self.assertEquals(vat_portal_type.getId(), 'Vat Declaration')
    self.assertTrue(vat_portal_type.getDefaultScribusFormValue().getData()
                                                 not in ('', None))
    self.assertTrue(vat_portal_type.getDefaultPdfFormValue().getData()
                                                 not in ('', None))
    id_generator = vat_module.getIdGenerator()
    self.assertEquals(id_generator, '_generatePerDayId')

  def test_02_application_creation(self):
    """
    This test create a procedure: vat declaration and use it with a simple user
    to just create a vat declaration and access it in different mode
    """
    procedure = self.createNewProcedure()
    self.fillProcedureForm(procedure, 'vat declaration')
    procedure.validate()
    self.createCitizenUser()
    self.logout()
    self.login('citizen')
    #Allow citizen to have Agent role to create application
    vat_module = self.portal.getDefaultModule('Vat Declaration')
    vat_declaration = vat_module.newContent(portal_type='Vat Declaration')
    # test form generation
    # change to EGov skin which is defined in erp5_egov
    self.changeSkin('EGov') 
    vat_declaration.view()
    vat_declaration.PDFType_viewAsPdf()
    application_dict = vat_declaration.PDFDocument_getApplicationIncomeDict()
    self.assertEquals(len(application_dict), 1)
    report_section_list = vat_declaration.PDFDocument_getReportSectionList()
    self.assertEquals(len(report_section_list), 1)
    vat_declaration.PDFDocument_viewHistory()

  def test_03_submit_application(self):
    """
    This test create an application fill it, join required
    attachments and submit it 
    """
    procedure = self.createNewProcedure()
    self.fillProcedureForm(procedure, 'vat declaration')
    procedure.validate()
    self.createCitizenUser()
    self.logout()
    self.login('citizen')
    #Allow citizen to have Agent role to create application
    vat_module = self.portal.getDefaultModule('Vat Declaration')
    vat_declaration = vat_module.newContent(portal_type='Vat Declaration')
    # test form generation
    # change to EGov skin which is defined in erp5_egov
    self.changeSkin('EGov') 
    self.assertEquals('draft', vat_declaration.getValidationState())
    missing_file = vat_declaration.PDFDocument_getRequirementCount()
    self.assertEquals(missing_file, 1)  
    type_allowed_content_type_list = vat_declaration.getTypeInfo().getTypeAllowedContentTypeList()
    type_allowed_content_type_list.append('PDF')
    vat_declaration.getTypeInfo().setTypeAllowedContentTypeList(type_allowed_content_type_list)
    vat_declaration.getTypeInfo().setTypeHiddenContentTypeList(type_allowed_content_type_list)
    vat_declaration.newContent(portal_type='PDF', 
		           title='Justificatif numero 1')
    self.tic()
    transaction.commit()
    missing_file = vat_declaration.PDFDocument_getRequirementCount()
    self.assertEquals(missing_file, 0)
    self.portal.portal_workflow.doActionFor(vat_declaration, 'submit_draft_action')
    self.assertEquals('submitted', vat_declaration.getValidationState())

  def test_05_process_application(self):
    """
    This test process a submitted application and verify allowed transition
    according to steps define in the procedure 
    """
    procedure = self.createNewProcedure()
    self.fillProcedureForm(procedure, 'vat declaration')
    procedure.validate()
    self.createCitizenUser()
    self.logout()
    self.login('citizen')
    #Allow citizen to have Agent role to create application
    vat_module = self.portal.getDefaultModule('Vat Declaration')
    vat_declaration = vat_module.newContent(portal_type='Vat Declaration')
    # test form generation
    # change to EGov skin which is defined in erp5_egov
    self.changeSkin('EGov') 
    self.portal.portal_workflow.doActionFor(vat_declaration, 'submit_draft_action')
    self.assertEquals('submitted', vat_declaration.getValidationState())
    self.createValidatorUser()
    self.logout()
    self.login('major')
    vat_declaration.view()
    vat_declaration.PDFDocument_getApplicationIncomeDict()
    vat_declaration.PDFDocument_getReportSectionList()
    vat_declaration.PDFDocument_viewHistory()
    self.portal.portal_workflow.doActionFor(vat_declaration, 'accept_action')
    self.assertEquals('accepted', vat_declaration.getValidationState())
    self.assertEquals(vat_declaration.getTypeInfo().getStepReviewRequest(),None)
    self.portal.portal_workflow.doActionFor(vat_declaration, 'assign_action')
    self.assertEquals('assigned', vat_declaration.getValidationState())
    self.portal.portal_workflow.doActionFor(vat_declaration, 'complet_action')
    self.assertEquals('completed', vat_declaration.getValidationState())
356 357 358 359


def test_suite():
  suite = unittest.TestSuite()
360
  suite.addTest(unittest.makeSuite(TestEgov))
361
  return suite
362