Exemplo n.º 1
0
    def test_contact_info_json_field(self):

        contact_info_field = models.fields.ContactInfoJSONField(
            default=dict, blank=True)
        # valid inputs
        empty = {}
        just_email = {'email': '*****@*****.**'}
        all_methods = {
            'email': '*****@*****.**',
            'sms': '+19993334444',
            'voicemail': '+19993334444',
            'snailmail': '123 Main St\nOakland, CA\n94609'
        }
        # invalid inputs
        nonexistent_method = {'twitter': '@someone'}
        empty_contact_info = {'email': ''}
        not_dict = [[], '', ' ', 10, True, None]

        valid_cases = [empty, just_email, all_methods]
        for valid_data in valid_cases:
            validators.contact_info_json(
                valid_data
            )
            contact_info_field.validate(valid_data, Mock())

        invalid_cases = [nonexistent_method, empty_contact_info, *not_dict]
        for invalid_data in invalid_cases:
            with self.assertRaises(ValidationError):
                validators.contact_info_json(invalid_data)
            with self.assertRaises(ValidationError):
                contact_info_field.validate(invalid_data, Mock())
Exemplo n.º 2
0
 def validate(self, value, model_instance):
     validators.contact_info_json(value)
     super().validate(value, model_instance)
Exemplo n.º 3
0
 def validate(self, value, model_instance):
     validators.contact_info_json(value)
     super().validate(value, model_instance)