コード例 #1
0
    def test_delete_user_with_email(self):
        """
        This test cases test if the user service are able to
        remove correctly the user inside the DB
        Test flow
        - Create a new user with the service
        - delete a new user with service with user pass
        - check on db if this user is gone
        """

        form = UserForm()
        form.firstname.data = "Vincenzo"
        form.lastname.data = "Palazzo"
        form.password = "******"
        form.phone.data = "12345"
        form.dateofbirth = "12/12/2020"
        form.email.data = "*****@*****.**"
        user = User()
        form.populate_obj(user)
        user = UserService.create_user(user, form.password, 2)
        assert user is not None
        assert user.role_id is 2
        UserService.delete_user(email=user.email)
        user = db.session.query(User).filter_by(email=user.email).first()
        assert user is None
コード例 #2
0
    def test_modify_user_role_id(self, client):
        """
        With this code is tested the services to perform the user modification
        with service and have the result on db

        Test flow
        - Create user
        - Modify user
        - check user
        - delete user to clean the database
        """
        form = UserForm()
        form.firstname.data = "Vincenzo"
        form.lastname.data = "Palazzo"
        form.password = "******"
        form.phone.data = "12345"
        form.dateofbirth = "12/12/2020"
        form.email.data = "*****@*****.**"
        user = User()
        form.populate_obj(user)
        user = UserService.create_user(user, form.password, 2)
        assert user is not None
        assert user.role_id is 2

        response = login(client, form.email.data, form.password)
        assert response.status_code == 200
        assert "logged_test" in response.data.decode("utf-8")

        formTest = UserForm(obj=user)
        user_modified = UserService.modify_user(formTest, 3)
        assert user is not None
        assert user.role_id is not 2
        UserService.delete_user(user_modified.id)
        user_modified = get_user_with_email(user_modified.email)
        assert user_modified is None
コード例 #3
0
def user_delete():
    UserService.delete_user(current_user.id)
    return redirect("/logout")