Example #1
0
class OnlineScoreRequest(ApiRequest):
    first_name = CharField(required=False, nullable=True)
    last_name = CharField(required=False, nullable=True)
    email = EmailField(required=False, nullable=True)
    phone = PhoneField(required=False, nullable=True)
    birthday = BirthDayField(required=False, nullable=True)
    gender = GenderField(required=False, nullable=True)

    def validate(self, kwargs):
        super().validate(kwargs)
        validate_pairs = any([
            self.phone and self.email, self.first_name and self.last_name,
            self.gender is not None and self.birthday
        ])
        if not validate_pairs:
            logging.error(
                'At least one pair expected from the (first_name - last_name, email - phone, birthday - gender)'
            )
            raise ValidationError("Fields validate error")
Example #2
0
class OnlineScoreRequest(Request):
    first_name = CharField(required=False, nullable=True)
    last_name = CharField(required=False, nullable=True)
    email = EmailField(required=False, nullable=True)
    phone = PhoneField(required=False, nullable=True)
    birthday = BirthDayField(required=False, nullable=True)
    gender = GenderField(required=False, nullable=True)

    def __init__(self, body):
        super(OnlineScoreRequest, self).__init__(body)

        valid = any(
            ((self.first_name is not None and self.last_name is not None),
             (self.email is not None
              and self.phone is not None), (self.birthday is not None
                                            and self.gender is not None)))

        if not valid:
            self._errors.append('invalid arguments set')
Example #3
0
class OnlineScoreRequest(ApiRequest):
    first_name = CharField(required=False, nullable=True)
    last_name = CharField(required=False, nullable=True)
    email = EmailField(required=False, nullable=True)
    phone = PhoneField(required=False, nullable=True)
    birthday = BirthDayField(required=False, nullable=True)
    gender = GenderField(required=False, nullable=True)

    def validate(self):
        validating_pairs = [
            ('first_name', 'last_name'),
            ('email', 'phone'),
            ('birthday', 'gender'),
        ]
        if ('first_name' in self.has and 'last_name' in self.has) or \
            ('email' in self.has and 'phone' in self.has) or \
            ('birthday' in self.has and 'gender' in self.has):
            return True
        else:
            raise AttributeError(
                "Required at least one of this fields pars: ('first_name', 'last_name'), "
                "('email', 'phone'), ('birthday', 'gender')")
Example #4
0
class Person(object):

    name = NameField()
    birthday = BirthdayField()
    phone = PhoneField()
Example #5
0
class MyUser(User):
    phone = PhoneField()
Example #6
0
def test_phonefield_not_valid(required, nullable, value, ex_mes):
    field = PhoneField(required, nullable)
    with pytest.raises(ValidationError) as e:
        field.validate(value)
    assert str(e.value) == ex_mes
Example #7
0
def test_phonesfield_valid(required, nullable, value):
    field = PhoneField(required, nullable)
    assert not field.validate(value)