diff --git a/src/controller/auth_controller.py b/src/controller/auth_controller.py index e66e2ab..32e66ab 100644 --- a/src/controller/auth_controller.py +++ b/src/controller/auth_controller.py @@ -24,7 +24,7 @@ def login(): if user is None: session.close() - flash("That email does not exist. Please try again.", "danger") + flash("That username does not exist. Please try again.", "danger") elif not user_repo.check_password(password, user.password_hash): session.close() flash("Invalid password. Please try again.", "danger") diff --git a/tests/test_controller/test_auth_controller.py b/tests/test_controller/test_auth_controller.py index 9796b91..f96872d 100644 --- a/tests/test_controller/test_auth_controller.py +++ b/tests/test_controller/test_auth_controller.py @@ -42,4 +42,46 @@ def test_login_valid_credentails(client, app): # Ensure only paths are compared. Ignore protocl and hostname differences. response_path = urlparse(response.location).path expected_path = url_for("tasks.view_tasks", user_id=1, _external=False) - assert response_path == expected_path \ No newline at end of file + assert response_path == expected_path + + +def test_login_invalid_username(client, app): + with app.app_context(): + response = client.post( + url_for("auth.login"), + data={"username": "Jazz", "password": "CrushinOnHillary"}, + follow_redirects=True, + ) + + # Assert the login page is returned + assert response.status_code == 200 + assert b"That username does not exist. Please try again." in response.data + assert b"LOGIN" in response.data + + +def test_login_invalid_password(client, app): + with app.app_context(): + response = client.post( + url_for("auth.login"), + data={"username": "Will_Smith", "password": "wrong_password"}, + follow_redirects=True, + ) + + print(response.data.decode()) + # Assert the login page is returned + assert response.status_code == 200 + assert b"Invalid password. Please try again." in response.data + assert b"LOGIN" in response.data + + +def test_login_form_validation(client, app): + with app.app_context(): + response = client.post( + url_for("auth.login"), + data={"username": "", "password": ""}, + follow_redirects=True, + ) + + # Assert that validation errors are displayed + assert response.status_code == 200 + assert b"Because you're always on top of the mountain (or at least your to-do list)" in response.data \ No newline at end of file