✨ feat(test_login.py): add tests for login functionality
🐛 fix(test_login.py): fix typo in test_login_unsuccessful_wrong_username test 🐛 fix(test_login.py): fix typo in test_login_unsuccessful_wrong_password test
This commit is contained in:
parent
7e3d329df9
commit
7b897906b9
1 changed files with 47 additions and 0 deletions
47
tests/test_login.py
Normal file
47
tests/test_login.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import pytest
|
||||
from langflow.services.database.models.user import User
|
||||
from langflow.services.auth.utils import get_password_hash
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_user():
|
||||
return User(
|
||||
username="testuser",
|
||||
password=get_password_hash(
|
||||
"testpassword"
|
||||
), # Assuming password needs to be hashed
|
||||
is_active=True,
|
||||
is_superuser=False,
|
||||
)
|
||||
|
||||
|
||||
def test_login_successful(client, test_user, session):
|
||||
# Adding the test user to the database
|
||||
session.add(test_user)
|
||||
session.commit()
|
||||
|
||||
response = client.post(
|
||||
"api/v1/login", data={"username": "testuser", "password": "testpassword"}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert "access_token" in response.json()
|
||||
|
||||
|
||||
def test_login_unsuccessful_wrong_username(client):
|
||||
response = client.post(
|
||||
"api/v1/login", data={"username": "wrongusername", "password": "testpassword"}
|
||||
)
|
||||
assert response.status_code == 401
|
||||
assert response.json()["detail"] == "Incorrect username or password"
|
||||
|
||||
|
||||
def test_login_unsuccessful_wrong_password(client, test_user, session):
|
||||
# Adding the test user to the database
|
||||
session.add(test_user)
|
||||
session.commit()
|
||||
|
||||
response = client.post(
|
||||
"api/v1/login", data={"username": "testuser", "password": "wrongpassword"}
|
||||
)
|
||||
assert response.status_code == 401
|
||||
assert response.json()["detail"] == "Incorrect username or password"
|
||||
Loading…
Add table
Add a link
Reference in a new issue