def test_create_new_user_with_email_already_in_db(init_db):
    new_user = User("*****@*****.**")
    new_user.insert_user_in_db()
    email = new_user.email
    user_data = new_user.find_user_data_by_email(email)
    with pytest.raises(UserErrors.UserAccountAlreadyExists):
        new_user.check_user_data_is_not_none(user_data)
    new_user.delete_by_email()
Beispiel #2
0
def login_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        try:
            if User.validate_user_login(email, password):
                session['email'] = email
                session['user_id'] = User.find_user_id_by_email(email)
                return redirect(url_for("tasks.task_portal"))
        except UserErrors.UserError as e:
            return e.message
    return render_template("users/login.html")
def test_check_poor_password(init_db):
    new_user = User("*****@*****.**", )
    auth_code = Utils.generate_auth_code()
    new_user.password = Utils.hash_password(auth_code)
    with pytest.raises(UserErrors.PoorPasswordError):
        new_user.check_registration_password_same_as_auth_code(
            auth_code, new_user.password)
    new_user.delete_by_email()
Beispiel #4
0
def authenticate_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        try:
            if User.authenticate_user(email, password):
                return redirect(url_for("users.register_user"))
        except UserErrors.UserError as e:
            return e.message
    return render_template("users/auth.html")
Beispiel #5
0
def create_task():
    if request.method == 'POST':
        task_name = request.form['task_name']
        priority = request.form['priority']
        description = request.form['description']
        task = Task(task_name, description, priority)
        task.check_task_id_length()
        task.check_priority_category()
        email = session['email']
        task.user_id_task_owner = User.find_user_id_by_email(email)
        task.save_to_db()
        return redirect(url_for('tasks.task_portal'))
    return render_template('tasks/create_task.html')
Beispiel #6
0
def sign_up_email():
    if request.method == 'POST':
        email = request.form['email']
        try:
            user_data = User(email)
            user_data.check_email_valid()
            user_data.send_auth_code_email()
            return redirect("/")
        except UserErrors.UserError as e:
            return e.message
    return render_template("users/sign_up.html")
def test_check_user_id_task_owner_is_not_valid(init_db):
    new_user = User("*****@*****.**")
    new_user.insert_user_in_db()
    email = new_user.email
    user_data = new_user.find_user_data_by_email(email)
    new_user_id = user_data['_id']
    new_task = Task("Test task name",
                    "Test Description",
                    "High",
                    user_id_task_owner=new_user_id)
    new_task.save_to_db()
    new_user.delete_by_email()
    with pytest.raises(TaskErrors.TaskOwnerIdIsNoLongerValid):
        new_task.check_user_id_task_owner_is_not_valid(new_user_id)
    new_task.delete()
def test_check_poor_email_format(init_db):
    new_user = User("test.com")
    with pytest.raises(UserErrors.InvalidEmailError):
        new_user.check_email_format_valid()
def test_login_with_no_email_in_db(init_db):
    new_user = User("*****@*****.**")
    email = new_user.email
    user_data = new_user.find_user_data_by_email(email)
    with pytest.raises(UserErrors.UserDoesNotExistError):
        new_user.check_user_data_is_none(user_data)
def test_create_new_default_user(init_db):
    new_user = User("*****@*****.**")
    assert new_user.email == "*****@*****.**"
def remove_test_data(init_db):
    new_user = User("*****@*****.**")
    new_user.delete_many_by_email(new_user.email)
def remove_test_data(init_db):
    new_user = User("*****@*****.**")
    new_user.delete_many_by_email(new_user.email)
    new_task = Task("Test task name", "Test Description", "High")
    new_task.delete_many_by_task_name(new_task.task_name)
    new_task.delete()