Example #1
0
def user_data():
    message = None
    if request.method == "POST":
        form = UserEditForm()
        if form.validate_on_submit():
            UserService.modify_user(form)
            return render_template("user_data.html", form=form)
        print(form.errors.items())
        return render_template("user_data.html", form=form, error="Error in the data")
    else:
        q = User.query.filter_by(id=current_user.id).first()
        if q is not None:
            form = UserForm(obj=q)
            return render_template("user_data.html", form=form)
Example #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