Ejemplo n.º 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")
Ejemplo n.º 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')
Ejemplo n.º 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')")
Ejemplo n.º 4
0
class PandaSerializer(Serializer):
    name = CharField()
    email = EmailField()
    created_at = DateTimeField()
Ejemplo n.º 5
0
def test_emailsfield_valid(required, nullable, value):
    field = EmailField(required, nullable)
    assert not field.validate(value)
Ejemplo n.º 6
0
def test_emailfield_not_valid(required, nullable, value, ex_mes):
    field = EmailField(required, nullable)
    with pytest.raises(ValidationError) as e:
        field.validate(value)
    assert str(e.value) == ex_mes
Ejemplo n.º 7
0
class CommentSerializer(Serializer):
    email = EmailField()
    content = CharField()
    created_at = DateTimeField()