Ejemplo n.º 1
0
    def test__parse_required_fields_should_raise_exception_if_need_req_field(
            self):
        req_fields_mapping = [
            FieldMapping(required=True, target_field=Field(id=3, name='email'))
        ]
        with self.assertRaises(AuditError) as cm:
            lead_authenticity._parse_required_fields(req_fields_mapping, {})
        self.assertEquals('Field "email" is required', str(cm.exception))

        req_fields_mapping = [
            FieldMapping(required=True, target_field=Field(id=3,
                                                           name='email')),
            FieldMapping(required=True, target_field=Field(id=1, name='name'))
        ]
        with self.assertRaises(AuditError) as cm:
            lead_authenticity._parse_required_fields(req_fields_mapping,
                                                     {'email': '*****@*****.**'})
        self.assertEquals('Field "name" is required', str(cm.exception))

        req_fields_mapping = [
            FieldMapping(required=True, target_field=Field(id=3,
                                                           name='email')),
            FieldMapping(required=True, target_field=Field(id=1, name='name'))
        ]
        with self.assertRaises(AuditError) as cm:
            lead_authenticity._parse_required_fields(req_fields_mapping, {
                'email': '*****@*****.**',
                '111': '222'
            })
        self.assertEquals('Field "name" is required', str(cm.exception))
Ejemplo n.º 2
0
 def test__check_input_required_fieldsets_pass_first_fieldset(self):
     input_fields = {'email': '*****@*****.**', 'name': 'test', '111': '222'}
     fs1 = [Field(name='email'), Field(name='name')]
     fs2 = [Field(name='name'), Field(name='phone'), Field(name='address')]
     self._check_input_required_fieldsets_helper(input_fields, fs1, fs2,
                                                 [call(input_fields, fs1)],
                                                 [True, False])
Ejemplo n.º 3
0
 def __check_input_required_fieldset_fields_helper(self,
                                                   exp,
                                                   input_fields,
                                                   fields=None):
     if fields is None:
         fields = [Field(id=3, name='email'), Field(id=1, name='name')]
     self.assertEquals(
         exp,
         lead_duplication._check_input_required_fieldset_fields(
             input_fields, fields))
Ejemplo n.º 4
0
 def test__parse_required_fields_should_return_only_required_fields(self):
     req_fields_mapping = [
         FieldMapping(required=True, target_field=Field(id=3,
                                                        name='email')),
         FieldMapping(required=True, target_field=Field(id=1, name='name'))
     ]
     res = lead_authenticity._parse_required_fields(req_fields_mapping, {
         'email': '*****@*****.**',
         'name': 'test',
         '111': '222'
     })
     self.assertEquals([('email', '*****@*****.**'), ('name', 'test')],
                       sorted(res.items()))
Ejemplo n.º 5
0
 def test__check_input_required_fieldsets_raise_error_if_no_fieldset_passed(
         self):
     lead_duplication._check_input_required_fieldset_fields = MagicMock(
         return_value=False)
     Fieldset = namedtuple('req_fieldset', ('fields', ))
     fs1 = [Field(name='email'), Field(name='name')]
     fs2 = [Field(name='name'), Field(name='phone'), Field(name='address')]
     fieldsets = [
         Fieldset(fields=ManyRelatedManagerHelper(fs1)),
         Fieldset(fields=ManyRelatedManagerHelper(fs2))
     ]
     input_fields = {'111': '222'}
     with self.assertRaises(AuditError) as cm:
         res = lead_duplication._check_input_required_fieldsets(
             input_fields, fieldsets)
     self.assertEquals(
         'Need minimal required fields (email, name) or (name, phone, address)',
         str(cm.exception))
     lead_duplication._check_input_required_fieldset_fields.assert_has_calls(
         [call(input_fields, fs1),
          call(input_fields, fs2)])
Ejemplo n.º 6
0
 def test__check_input_required_fieldset_fields_fail_if_no_required_fields_set(
         self):
     input_fields = {'111': '222'}
     fields = [Field(id=3, name='email')]
     self.__check_input_required_fieldset_fields_helper(
         False, input_fields, fields)