-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test_login_for_access_token_fails
+ change test_successful_login to test_login_for_access_token_success
- Loading branch information
1 parent
dc583ca
commit c744f3c
Showing
1 changed file
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,7 +283,7 @@ def test_health_check_wrong_url(client): | |
assert response.status_code == 404 # Not Found | ||
|
||
|
||
def test_successful_login( | ||
def test_login_for_access_token_success( | ||
client, | ||
mock_authenticate_user, | ||
mock_create_access_token_valid_token, | ||
|
@@ -314,3 +314,33 @@ def test_successful_login( | |
|
||
# # Ensure the authenticate_user was called with correct arguments | ||
mock_authenticate_user.assert_called_once_with("[email protected]", "test1fake_hash", db=db) | ||
|
||
|
||
def test__login_for_access_token_fails( | ||
client, | ||
mock_authenticate_user, | ||
mock_create_access_token_valid_token, | ||
valid_token, | ||
db, | ||
monkeypatch, | ||
): | ||
|
||
# Mock authenticate_user to return False | ||
mock_authenticate_user.return_value = False | ||
|
||
monkeypatch.setattr("app.api.auth.authenticate_user", mock_authenticate_user) | ||
monkeypatch.setattr("app.api.auth.create_access_token", mock_create_access_token_valid_token) | ||
|
||
# Prepare the data as if it is coming from OAuth2PasswordRequestForm | ||
login_data = {"username": "[email protected]", "password": "testfake_hash"} | ||
|
||
# Send a POST request to the /token endpoint | ||
response = client.post("/token", data=login_data) | ||
|
||
# Assert that the status code is 200 OK | ||
assert response.status_code == 400 | ||
|
||
assert response.json().get("detail") == "Incorrect username or password" | ||
|
||
# # Ensure the authenticate_user was called with correct arguments | ||
mock_authenticate_user.assert_called_once_with("[email protected]", "testfake_hash", db=db) |