示例#1
0
    def test_login_user_ok(self, client, db):
        """
        This function test the perform the  request to login the user
        :param client: flask test client
        :param db: database session
        """
        json_create = {
            "firstname": "Vincenzo",
            "lastname": "Palazzo",
            "password": "******",
            "phone": "100023",
            "dateofbirth": "1996-12-12",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json_create)
        assert user is not None

        json_login = {
            "email": json_create["email"],
            "password": json_create["password"],
        }
        response = Utils.login_user(client, json_login)
        user = Utils.get_user_on_db_with_email(db, json_create["email"])
        assert response.status_code == 200
        assert user.email in response.data.decode("utf-8")

        Utils.del_user_on_db_with_id(db, user.id)
        user = Utils.get_user_on_db_with_email(db, json_create["email"])
        assert user is None
示例#2
0
    def test_unmark_user_as_covid_positive(self, db):
        """
        This function test try to discover fault inside the
        mark postivive function inside the USerServices

        Flow tests is:
        - Create a new User
        - Mark this user as positive
        - check if the user if positive on the table
        - clean db (remove the user and the positive)
        """
        json = Utils.get_json_about_new_user()
        user = UserService.create_user(db, json)
        assert user is not None
        assert user.role_id is 3

        success_mark = UserService.mark_user_as_positive(
            db, json["email"], json["phone"])
        assert success_mark is True

        success_unmark = UserService.unmark_user_as_not_positive(db, user.id)
        assert success_unmark is True

        Utils.del_user_on_db_with_id(db, user.id)
        user = Utils.del_user_on_db_with_id(db, user.id)
        assert user is None
示例#3
0
    def test_get_user_by_id(self, client, db):
        """
        Test flow:
        - Create User
        - Get user by id
        - check user
        - clean db
        :param client: flask test client
        :param db: db session
        """
        json_create = {
            "firstname": "Vincenzo",
            "lastname": "Palazzo",
            "password": "******",
            "phone": "100023",
            "dateofbirth": "1996-12-12",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json_create)
        assert user is not None

        response = Utils.get_user_by_id(client, user.id)
        assert response.status_code == 200
        json = response.data.decode("utf-8")
        assert user.firstname in json
        assert user.phone in json
        assert user.email in json
        assert str(user.role_id) in json

        Utils.del_user_on_db_with_id(db, user.id)
        user = Utils.get_user_on_db_with_email(db, json_create["email"])
        assert user is None
示例#4
0
    def test_user_is_present_by_phone(self, db):
        """
        This test try to test the simple operation to create a new operator

         Test flow:
         - Make the JSON object with the correct data
         - user the UserService to share the request
         - clean DB
        """
        json = {
            "firstname": "Vincenzo",
            "lastname": "Palazzo",
            "password": "******",
            "phone": "345432234",
            "dateofbirth": "1996-12-12",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json, 2)
        assert user is not None
        assert user.role_id is not 3
        assert user.role_id is 2

        user = UserService.user_is_present(db, phone=json["phone"])
        assert user is not None

        Utils.del_user_on_db_with_id(db, user.id)
示例#5
0
    def test_delete_user_ok(self, client, db):
        """
        This test method perform the request to modify the user
        :param client: flask test client
        :param db: database session
        """
        json = {
            "firstname": "Bart",
            "lastname": "Simpson",
            "password": "******",
            "phone": "100023",
            "dateofbirth": "1996-12-12",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json)
        assert user is not None

        json_login = {
            "email": json["email"],
            "password": json["password"],
        }
        response = Utils.login_user(client, json_login)

        response = Utils.delete_user(client, user.id)
        assert response.status_code == 200
        assert "OK" in response.data.decode("utf-8")

        user = Utils.get_user_on_db_with_email(db, json["email"])
        assert user is None
示例#6
0
    def test_modify_user_ok(self, client, db):
        """
        This test method perform the request to modify the user
        :param client: flask test client
        :param db: database session
        """
        json = {
            "firstname": "Bart",
            "lastname": "Simpson",
            "password": "******",
            "phone": "100023",
            "dateofbirth": "1996-12-12",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json)
        assert user is not None

        json["firstname"] = "Homer"
        json["role"] = user.role_id
        json["id"] = user.id

        response = Utils.modify_user(client, json)
        logging.debug(response.data)
        user = Utils.get_user_on_db_with_email(db, json["email"])
        assert response.status_code == 200
        assert "Homer" in response.data.decode("utf-8")
        assert "Bart" not in response.data.decode("utf-8")

        Utils.del_user_on_db_with_id(db, user.id)
        user = Utils.get_user_on_db_with_email(db, json["email"])
        assert user is None
示例#7
0
    def register(username):
        """Register a new user, with his username.

        Args :
            username: string
        """
        user = UserService.create_user(username, username, username, None)
        return user
示例#8
0
    def post(self, nickname):
        service = UserService()
        self.set_header("Content-type", "application/json")

        data = tornado.escape.json_decode(self.request.body)

        result, status = service.create_user(nickname, data)
        self.set_status(int(status))
        self.write(result)
示例#9
0
 def create_user_on_db(db_session, ran: int = randrange(100000)):
     json = {
         "firstname": "User_{}".format(ran),
         "lastname": "user_{}".format(ran),
         "password": "******".format(ran),
         "phone": "1234562344{}".format(ran),
         "dateofbirth": "12/12/2000",
         "email": "alibaba{}@alibaba.com".format(str(ran)),
     }
     return UserService.create_user(db_session, json)
示例#10
0
    def test_get_user_by_email(self, db):
        """
        This function contains the code to test the
        user service tha allows to retetrive the user having the email
        :param db: database session
        """
        json = Utils.get_json_about_new_user()
        user = UserService.create_user(db, json)
        assert user is not None
        assert user.role_id is 3

        assert UserService.get_user_by_email(db, user.email).id == user.id

        is_delete = UserService.delete_user(db, user.id)
        assert is_delete is True
示例#11
0
    def test_user_delete_ok(self, db):
        """
        This function contains the code to test the
        User services about the login, and I will aspect a good result.
        :param db: database session
        """
        json = Utils.get_json_about_new_user()
        user = UserService.create_user(db, json)
        assert user is not None
        assert user.role_id is 3
        user = UserService.user_login(db, user.email, json["password"])
        is_delete = UserService.delete_user(db, user.id)
        assert is_delete is True

        user = Utils.get_user_on_db_with_email(db, user.email)
        assert user is None
示例#12
0
    def test_report_positive_after_one(self, db):
        json = Utils.get_json_about_new_user()
        user = UserService.create_user(db, json)
        assert user is not None
        assert user.role_id is 3
        success_mark = UserService.mark_user_as_positive(
            db, json["email"], json["phone"])
        assert success_mark is True

        users = UserService.report_positive(db)
        assert len(users) == 1

        success_unmark = UserService.unmark_user_as_not_positive(db, user.id)
        assert success_unmark is True
        Utils.del_user_on_db_with_id(db, user.id)
        user = Utils.del_user_on_db_with_id(db, user.id)
        assert user is None
示例#13
0
    def test_user_modify_ok(self, db):
        """
        This function contains the code to test the
        User services about the login, and I will aspect a good result.
        :param db: database session
        """
        json = Utils.get_json_about_new_user()
        user = UserService.create_user(db, json)
        assert user is not None
        assert user.role_id is 3

        user = UserService.user_login(db, json["email"], json["password"])

        json["firstname"] = "Bart"
        json["role"] = user.role_id
        json["id"] = user.id
        user = UserService.modify_user(db, json)
        assert user is not None
        assert user.firstname == "Bart"
        Utils.del_user_on_db_with_id(db, user.id)
示例#14
0
    def test_unmark_a_not_positive(self, client, db):

        json_create = {
            "firstname": "Bobby",
            "lastname": "Bishop",
            "password": "******",
            "phone": "123456789",
            "dateofbirth": "1985-05-19",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json_create)
        assert user is not None

        body = {"key": "email", "value": user.email}
        response = client.put("/user/unmark", json=body, follow_redirects=True)
        assert response.status_code == 404
        json_data = response.json
        assert json_data["result"] == "User not positive"

        Utils.del_user_on_db_with_id(db, user.id)
示例#15
0
    def test_info_positive_customer_phone(self, client, db):
        json_create = {
            "firstname": "Bobby",
            "lastname": "Bishop",
            "password": "******",
            "phone": "123456789",
            "dateofbirth": "1985-05-19",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json_create)
        assert user is not None
        response = UserService.mark_user_as_positive(db, "", user.phone)
        assert response is True

        response = client.get(
            "/user/positiveinfo/phone/" + str(user.phone), follow_redirects=True
        )
        assert response.status_code == 200

        Utils.del_user_on_db_with_id(db, user.id)
示例#16
0
    def test_unmark_positive_customer_phone(self, client, db):

        json_create = {
            "firstname": "Bobby",
            "lastname": "Bishop",
            "password": "******",
            "phone": "123456789",
            "dateofbirth": "1985-05-19",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json_create)
        assert user is not None
        response = UserService.mark_user_as_positive(db, "", user.phone)
        assert response is True

        body = {"key": "phone", "value": user.phone}
        response = client.put("/user/unmark", json=body, follow_redirects=True)
        positive = UserService.user_is_positive(db, user.id)
        assert positive is None

        Utils.del_user_on_db_with_id(db, user.id)
示例#17
0
    def test_info_not_positive_customer(self, client, db):
        json_create = {
            "firstname": "Bobby",
            "lastname": "Bishop",
            "password": "******",
            "phone": "123456789",
            "dateofbirth": "1985-05-19",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json_create)
        assert user is not None

        response = client.get(
            "/user/positiveinfo/email/" + str(user.email), follow_redirects=True
        )

        assert response.status_code == 404
        json_data = response.json
        assert json_data["result"] == "Information not found"

        Utils.del_user_on_db_with_id(db, user.id)
示例#18
0
    def test_create_customer(self, db):
        """
        This test try to test the simple operation to create a new operator

         Test flow:
         - Make the JSON object with the correct data
         - user the UserService to share the request
         - clean DB
        """
        json = {
            "firstname": "Vincenzo",
            "lastname": "Palazzo",
            "password": "******",
            "phone": "100023",
            "dateofbirth": "1996-12-12",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json)
        assert user is not None
        assert user.role_id is 3

        Utils.del_user_on_db_with_id(db, user.id)
示例#19
0
    def test_create_operator(self, db):
        """
        This test try to test the simple operation to create a new operator

         Test flow:
         - Make the JSON object with the correct data
         - user the UserService to share the request
         - clean DB
        """
        json = {
            "firstname": "Vincenzo",
            "lastname": "Palazzo",
            "password": "******",
            "phone": "345432234",
            "dateofbirth": "1996-12-12",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json, 2)
        assert user is not None
        assert user.role_id is not 3
        assert user.role_id is 2

        db.query(User).filter_by(id=user.id).delete()
        db.commit()
示例#20
0
    def test_check_a_positive_customer_email(self, client, db):

        json_create = {
            "firstname": "Bobby",
            "lastname": "Bishop",
            "password": "******",
            "phone": "123456789",
            "dateofbirth": "1985-05-19",
            "email": "*****@*****.**",
        }
        user = UserService.create_user(db, json_create)
        assert user is not None
        response = UserService.mark_user_as_positive(db, user.email, "")
        assert response is True

        response = client.get(
            "/user/checkpositive/email/" + str(user.email), follow_redirects=True
        )

        assert response.status_code == 200
        json_data = response.json
        assert json_data["result"] == "Positive"

        Utils.del_user_on_db_with_id(db, user.id)
示例#21
0
async def sign_up(data: UserCreation = Body(...)):
    return UserService.create_user(data)