def __call__(self, owner_email):

        if validate_email(owner_email):
            query_products = User.get_products_by_user(owner_email)
            if not query_products:
                return {"message": f"{owner_email} doesn't have products yet"}
            else:
                product_schema = ProductSchema(many=True, exclude=("owner", ))
                products = product_schema.dump(query_products)
                return jsonify({"Products": products})
        else:
            return jsonify({"message": f"{owner_email} is not a valid email"})
Exemple #2
0
 def __call__(self, user_email):
     if not validate_email(user_email):
         return response_message(False, "{user_email} is not a valid email")
     delete_user = User.query.filter_by(active=True,
                                        email=user_email).first()
     if delete_user:
         if delete_user.delete():
             return response_message(True, "Successfull delete")
         else:
             return response_message(True, "Couldn't delete {delete_user}")
     else:
         return response_message(False,
                                 "Not found user with email {user_email}")
Exemple #3
0
    def __call__(self, user_email):

        if validate_email(user_email):
            query_user = User.query.filter_by(active=True,
                                              email=user_email).first()
            if query_user:
                user_schema = UserSchema()
                user = user_schema.dump(query_user)
                return jsonify({'user': user})
            else:
                return response_message(False, f"{user_email} doesn't exists")
        else:
            return response_message(False,
                                    f"{user_email} is not a valid email")
Exemple #4
0
 def validate(self):
     """
     Validates the fields.
     """
     try:
         assert type(self.first_name) in (str, unicode)
         assert len(self.first_name) != 0
         assert type(self.last_name) in (str, unicode)
         assert len(self.first_name) != 0
         assert validate_email(self.email) is True
         assert self.active in (True, False)
         if self.country:
             assert type(self.country) in (str, unicode)
         if self.state:
             assert type(self.state) in (str, unicode)
         if self.city:
             assert type(self.city) in (str, unicode)
         if self.zip_code:
             assert type(self.zip_code) is int
             assert self.zip_code > 0
         return True
     except AssertionError:
         return False
Exemple #5
0
def test_email_validator():
    assert validate_email('*****@*****.**')
    assert validate_email('*****@*****.**')
    assert not validate_email('example.com')