testERP5eGov.py 15 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
import unittest

from Testing import ZopeTestCase
34 35
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager
36 37 38 39 40 41
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')
42

43 44
def makeFilePath(name):
  return os.path.join(os.path.dirname(__file__), 'test_data', name)
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
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. """
Ivan Tyagov's avatar
Ivan Tyagov committed
65 66 67
    bt_list = ['erp5_core_proxy_field_legacy',
               'erp5_full_text_myisam_catalog',
               'erp5_base',
68
               'erp5_web',
Ivan Tyagov's avatar
Ivan Tyagov committed
69 70
               'erp5_ingestion_mysql_innodb_catalog',
               'erp5_ingestion',
71 72
               'erp5_dms',
               'erp5_egov_mysql_innodb_catalog',
73
               'erp5_egov']
74
    return bt_list
75 76

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

79 80 81 82 83 84 85
  #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',], [])
86

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

94 95 96 97
  def createValidatorUser(self):
    """
    Create a user with Agent role to allow create and submit requests
    """
98
    uf = self.getPortal().acl_users
99 100
    uf._doAddUser('major', '', ['Assignor',], [])

101 102 103 104 105 106 107 108 109 110 111 112 113 114
  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()
115
    self.commit()
116 117 118 119 120 121 122 123 124 125
    # 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',
126
            'role/citoyen', 'role/citoyen/national', 'role/citoyen/etranger', 'role/gouvernement',
127 128
            'role/entreprise', 'role/entreprise/agence', 'role/entreprise/siege', 'role/entreprise/succursale', 
            'function/entreprise/mandataire')
129

130 131 132 133 134
  def afterSetUp(self):
    uf = self.getPortal().acl_users
    uf._doAddUser('seb', '', ['Manager', 'Assignor','Assignee'], [])
    self.login('seb')
    user = uf.getUserById('seb').__of__(uf)
135
    newSecurityManager(None, user)
136
    self.portal = self.getPortalObject()
137
    self.createCategories()
138 139 140 141 142 143 144 145 146 147 148
    # 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()
149

150
    self.tic()
151 152 153
    #set up the instance
    self.portal.EGov_setUpInstance()

154 155 156 157
  def beforeTearDown(self):
    """
    remove all created objects between two tests, tests are stand-alone
    """
158
    self.abort()
159
    for module in [ self.getPersonModule(),
160 161
                    self.getOrganisationModule(),
                      ]:
162
      module.manage_delObjects(list(module.objectIds()))
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    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()
    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
198
    procedure.setOrganisationDirectionService('client/dgid/di')
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    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)
216
    procedure.setInvolvedServiceGroup1('client/dgid/di')
217 218 219 220 221 222 223
    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)
224
    procedure.setInvolvedServiceGroup2('client/dgid/di')
225 226 227 228 229 230 231 232
    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)
233
    procedure.setInvolvedServiceGroup3('client/dgid/bf')
234 235 236 237 238 239 240
    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)
241
    procedure.setInvolvedServiceGroup2('client/dgid/di')
242 243 244 245 246 247 248 249 250 251 252
    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)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
253 254
    procedure.edit(scribus_form_file=scribus_file_data,
            pdf_form_file=pdf_file_data)
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
    self.tic()
    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)
326
    vat_declaration.newContent(portal_type='PDF', title='Justificatif numero 1')
327
    self.tic()
328
    self.commit()
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
    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())
353
    self.createAgentUser()
354
    self.logout()
355
    self.login('agent')
356 357 358 359
    vat_declaration.view()
    vat_declaration.PDFDocument_getApplicationIncomeDict()
    vat_declaration.PDFDocument_getReportSectionList()
    vat_declaration.PDFDocument_viewHistory()
360
    self.portal.portal_workflow.doActionFor(vat_declaration, 'receive_action')
361 362 363 364 365 366 367 368 369 370 371 372 373 374
    if vat_declaration.getTypeInfo().getStepReviewRequest() is None:
      self.assertEquals('completed', vat_declaration.getValidationState())
    """
    else:
      self.assertEquals('receivable', 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.createValidatorUser()
      self.logout()
      self.login('major')
      self.portal.portal_workflow.doActionFor(vat_declaration, 'complete_action')
      self.assertEquals('completed', vat_declaration.getValidationState())
    """
375 376 377

def test_suite():
  suite = unittest.TestSuite()
378
  suite.addTest(unittest.makeSuite(TestEgov))
379
  return suite
380