Exemple #1
0
    def test_duplicate_sta_candidature_in_same_category(self):
        '''
        Try to create twice a candidature in the same category for a partner
        '''
        jacques_partner_id = self.ref('%s.res_partner_jacques' %
                                      self._module_ns)
        conseil_comm_cat_id = self.ref('%s.mc_conseiller_communal' %
                                       self._module_ns)
        selection_committee_id = self.ref('%s.sc_tete_huy_communale' %
                                          self._module_ns)

        committee = self.registry('sta.selection.committee').browse(
            self.cr, self.uid, selection_committee_id)

        assembly_id = committee.designation_int_assembly_id.id
        data = dict(mandate_category_id=conseil_comm_cat_id,
                    selection_committee_id=selection_committee_id,
                    designation_int_assembly_id=assembly_id,
                    legislature_id=committee.legislature_id.id,
                    electoral_district_id=committee.electoral_district_id.id,
                    sta_assembly_id=committee.assembly_id.id,
                    partner_id=jacques_partner_id)

        with testtool.disable_log_error(self.cr):
            self.assertRaises(psycopg2.IntegrityError,
                              self.registry('sta.candidature').create, self.cr,
                              self.uid, data)
Exemple #2
0
    def test_legislature_early_closing(self):
        '''
        Test the mass update of mandates if deadline date of legislature
        is changed
        '''
        mandate = self.browse_ref(
            '%s.stam_pauline_bourgmestre' % self._module_ns)
        legislature = mandate.legislature_id
        start = mandate.start_date
        dstart = fields.Date.from_string(start)
        today = fields.Date.today()
        dtoday = fields.Date.from_string(today)

        dpast = dtoday - TD(days=1)
        with self.assertRaises(orm.except_orm):
            legislature.write({'deadline_date': fields.Date.to_string(dpast)})
        if dtoday < dstart:
            dfuture = dstart + TD(days=3)
            future = fields.Date.to_string(dfuture)
            legislature.write({'deadline_date': future})
            self.assertEqual(legislature.deadline_date, future)
            self.assertEqual(mandate.deadline_date, future)
            dpast = dstart - TD(days=1)
            with testtool.disable_log_error(self.env.cr):
                with self.assertRaises(psycopg2.IntegrityError):
                    legislature.write(
                        {'deadline_date': fields.Date.to_string(dpast)})
Exemple #3
0
    def test_duplicate_ext_candidature_in_same_category(self):
        '''
        Try to create twice a candidature in the same category for a partner
        '''
        jacques_partner_id = self.ref('%s.res_partner_jacques' %
                                      self._module_ns)
        membre_eff_cat_id = self.ref('%s.mc_membre_effectif_ag' %
                                     self._module_ns)
        selection_committee_id = self.ref('%s.sc_membre_effectif_ag' %
                                          self._module_ns)

        committee = self._committee_pool.browse(self.cr, self.uid,
                                                selection_committee_id)
        assembly_id = committee.designation_int_assembly_id.id
        data = dict(mandate_category_id=membre_eff_cat_id,
                    selection_committee_id=selection_committee_id,
                    designation_int_assembly_id=assembly_id,
                    ext_assembly_id=committee.assembly_id.id,
                    partner_id=jacques_partner_id)

        self._candidature_pool.create(self.cr, self.uid, data)

        with testtool.disable_log_error(self.cr):
            self.assertRaises(psycopg2.IntegrityError,
                              self._candidature_pool.create, self.cr, self.uid,
                              data)
Exemple #4
0
 def test_unique_postal_mail(self):
     '''
         Postal mail name must be unique
     '''
     self._postal_mail_pool.create(self.cr, self.uid,
                                   {'name': 'Postal Mail'})
     with testtool.disable_log_error(self.cr):
         self.assertRaises(psycopg2.IntegrityError,
                           self._postal_mail_pool.create, self.cr, self.uid,
                           {'name': 'Postal Mail'})
Exemple #5
0
 def test_involvement_category_integrity_1(self):
     # create a category with negative deadline rule: NOK
     vals = {
         'name': 'Le tour du monde en 80 jours',
         'nb_deadline_days': -80,
     }
     with testtool.disable_log_error(self.cr):
         self.assertRaises(psycopg2.IntegrityError,
                           self.env['partner.involvement.category'].create,
                           vals)
Exemple #6
0
    def test_avoid_duplicate_mandate_category(self):
        '''
            Test unique name of mandate category
        '''
        data = dict(type='sta', name='category_01')
        self.registry('mandate.category').create(self.cr, self.uid, data)

        with testtool.disable_log_error(self.cr):
            self.assertRaises(psycopg2.IntegrityError,
                              self.registry('mandate.category').create,
                              self.cr, self.uid, data)
 def test_newsletter_code_unique(self):
     cr, uid, context = self.cr, self.uid, {}
     vals = dict(name='Newsletter Sample 1',
                 code='SAMPLE1',
                 newsletter=True)
     self.dl_obj.create(cr, uid, vals, context=context)
     vals = dict(name='Newsletter Sample 2',
                 code='SAMPLE1',
                 newsletter=True)
     with testtool.disable_log_error(cr):
         self.assertRaises(psycopg2.IntegrityError, self.dl_obj.create, cr,
                           uid, vals, context)
Exemple #8
0
 def test_involvement_category_integrity_2(self):
     mc_id = self.ref('%s.mc_secretaire_regional' % self._module_ns)
     # create a category without deadline rule but with a mandate: NOK
     vals = {
         'name': 'Le tour du monde en 80 jours',
         'nb_deadline_days': 0,
         'mandate_category_id': mc_id,
     }
     with testtool.disable_log_error(self.cr):
         self.assertRaises(psycopg2.IntegrityError,
                           self.env['partner.involvement.category'].create,
                           vals)
Exemple #9
0
    def test_add_bounce(self):
        """
        1/ test reference data
        2/ create a valid wz
        3/ execute it and test the new counter value
        4/ reset the counter and test its value
        5/ create an invalid wz
        """
        cr, uid, context = self.cr, self.uid, self.context

        # 1/ Check for reference data
        bc = self.model_coordinate.read(cr,
                                        uid,
                                        self.model_coordinate_id,
                                        ['bounce_counter'],
                                        context=context)['bounce_counter']
        self.assertFalse(bc, 'Wrong expected reference data for this test')

        # 2/ Create wizard record
        wiz_id = self.create_bounce_data(2)

        # 3/ Execute wizard
        self.model_wizard.update_bounce_datas(cr,
                                              uid, [wiz_id],
                                              context=context)
        coord = self.model_coordinate.read(
            cr,
            uid,
            self.model_coordinate_id, ['bounce_counter', 'bounce_description'],
            context=context)
        self.assertEqual(coord['bounce_counter'], 2,
                         'Update coordinate fails with wrong bounce_counter')
        self.assertEqual(
            coord['bounce_description'], DESC,
            'Update coordinate fails with wrong bounce_description')

        # 4/ Reset counter
        self.model_coordinate.button_reset_counter(cr,
                                                   uid,
                                                   self.model_coordinate_id,
                                                   context=context)
        bc = self.model_coordinate.read(cr,
                                        uid,
                                        self.model_coordinate_id,
                                        ['bounce_counter'],
                                        context=context)['bounce_counter']
        self.assertFalse(bc, 'Reset counter fails with wrong bounce_counter')

        # 5/ Try to create an invalid wizard record
        with testtool.disable_log_error(cr):
            self.assertRaises(psycopg2.IntegrityError, self.create_bounce_data,
                              -2)
Exemple #10
0
 def test_unicity_fractionation_line(self):
     '''
         Test reference to a power level must unique within a fractionation
     '''
     fractionation_02_id = self.ref('%s.f_sample_02' % self._module_ns)
     int_power_level_01_id = self.ref('mozaik_structure.int_power_level_01')
     data = dict(fractionation_id=fractionation_02_id,
                 power_level_id=int_power_level_01_id,
                 percentage=20)
     with testtool.disable_log_error(self.cr):
         self.assertRaises(psycopg2.IntegrityError,
                           self.registry('fractionation.line').create,
                           self.cr, self.uid, data)
Exemple #11
0
    def test_fractionation_line_percentage(self):
        '''
            Test percentage of line must be lower or equal to 100
        '''
        fractionation_02_id = self.ref('%s.f_sample_02' % self._module_ns)
        int_power_level_02_id = self.ref('%s.int_power_level_02' %
                                         self._module_ns)
        data = dict(fractionation_id=fractionation_02_id,
                    power_level_id=int_power_level_02_id,
                    percentage=142)

        with testtool.disable_log_error(self.cr):
            self.assertRaises(psycopg2.IntegrityError,
                              self.registry('fractionation.line').create,
                              self.cr, self.uid, data)
 def test_multi(self):
     """
     Check for multiple involvements
     """
     # create an involvement category
     cat = self.env['partner.involvement.category'].create({
         'name':
         'Buvons un coup ma serpette...',
     })
     # create an involvement
     involvement = self.env['partner.involvement'].create({
         'partner_id':
         self.paul.id,
         'involvement_category_id':
         cat.id,
     })
     # check for effective_time
     self.assertFalse(involvement.effective_time)
     # copy it: NOK
     self.assertRaises(ValidationError, involvement.copy)
     # allow miltiple involvements
     cat.allow_multi = True
     # check for effective_time
     self.assertTrue(involvement.effective_time)
     involvement.unlink()
     # create a new involvement
     now = (datetime.now() + timedelta(hours=-1)).strftime(DATETIME_FORMAT)
     involvement = self.env['partner.involvement'].create({
         'partner_id':
         self.paul.id,
         'involvement_category_id':
         cat.id,
         'effective_time':
         now,
     })
     # copy it: OK
     involvement.copy()
     # create an already existing involvement: NOK
     with testtool.disable_log_error(self.cr):
         self.assertRaises(
             psycopg2.IntegrityError,
             self.env['partner.involvement'].create, {
                 'partner_id': self.paul.id,
                 'involvement_category_id': cat.id,
                 'effective_time': now,
             })
     return
Exemple #13
0
    def test_add_bounce(self):
        """
        1/ test reference data
        2/ create a valid wz
        3/ execute it and test the new counter value
        4/ reset the counter and test its value
        5/ create an invalid wz
        """
        cr, uid, context = self.cr, self.uid, self.context

        # 1/ Check for reference data
        coord = self.model_coordinate.browse(cr,
                                             uid,
                                             self.model_coordinate_id,
                                             context=context)
        self.assertFalse(coord.bounce_counter)

        # 2/ Create wizard record
        wiz_id = self.create_bounce_data(2)

        # 3/ Execute wizard
        self.model_wizard.update_bounce_datas(cr,
                                              uid, [wiz_id],
                                              context=context)
        self.assertEqual(coord.bounce_counter, 2)
        self.assertEqual(coord.bounce_description, DESC)
        self.assertEqual(coord.first_bounce_date, coord.bounce_date)

        # 4/ Reset counter
        self.model_coordinate.button_reset_counter(cr,
                                                   uid,
                                                   self.model_coordinate_id,
                                                   context=context)
        self.assertFalse(coord.bounce_counter)
        self.assertFalse(coord.bounce_date)
        self.assertFalse(coord.first_bounce_date)

        # 5/ Try to create an invalid wizard record
        with testtool.disable_log_error(cr):
            self.assertRaises(psycopg2.IntegrityError, self.create_bounce_data,
                              -2)
 def test_unicity_of_abstract_coordinate(self):
     """
     ===================================
     test_unicity_of_abstract_coordinate
     ===================================
     Test the fact that the model coordinate must be unique with
     partner_id, model_id when no expire date
     """
     self.model_coordinate.create(
         self.cr, self.uid,
         {'partner_id': self.partner_id_1,
          self.model_coordinate._discriminant_field: self.field_id_1,
          'is_main': True})
     with testtool.disable_log_error(self.cr):
         self.assertRaises(
             psycopg2.IntegrityError,
             self.model_coordinate.create,
             self.cr, self.uid,
             {'partner_id': self.partner_id_1,
              self.model_coordinate._discriminant_field: self.field_id_1,
              'is_main': False,
              })