🔧 fix(endpoints.py): move import statement to the top of the file for better organization and readability 🔧 fix(getters.py): change service type from DATABASE_MANAGER to DATABASE_SERVICE for consistency and clarity 🔧 fix(getters.py): change service type from CACHE_MANAGER to CACHE_SERVICE for consistency and clarity 🔧 fix(getters.py): change service type from SESSION_MANAGER to SESSION_SERVICE for consistency and clarity 🔧 fix(getters.py): change service type from TASK_MANAGER to TASK_SERVICE for consistency and clarity 🔧 fix(getters.py): remove unused function get_chat_service() to improve code cleanliness and maintainability 🔧 fix(getters.py): remove duplicate function get_settings_service() to improve code cleanliness and maintainability 🔧 fix(getters.py): remove duplicate function get_db_service() to improve code cleanliness and maintainability 🔧 fix(getters.py): remove duplicate function get_session() to improve code cleanliness and maintainability 🔧 fix(utils.py): remove unused import statement to improve code cleanliness and maintainability 🔧 fix(utils.py): remove unused function setup_superuser() to improve code cleanliness and maintainability 🔧 fix(utils.py): remove unused function teardown_superuser() to improve code cleanliness and maintainability 🔧 fix(utils.py): remove unused function teardown_services() to improve code cleanliness and maintainability 🔧 fix(utils.py): remove unused function initialize_settings_manager() to improve code cleanliness and maintainability 🔧 fix(utils.py): remove unused function initialize_session_manager() to improve code cleanliness and maintainability 🔧 fix(utils.py): remove unused function initialize_services() to improve code cleanliness and maintainability 🔧 fix(conftest.py): remove unused import statement to improve code cleanliness and maintainability 🔧 fix(conftest.py): remove unused function get_session_override() to improve code cleanliness and maintainability 🔧 fix(conftest.py): remove unused function distributed_client_fixture() to improve code cleanliness and maintainability 🔧 fix(conftest.py): remove unused function client_fixture() to improve code cleanliness and maintainability 🔧 fix(conftest.py): remove unused function test_user() to improve code cleanliness and maintainability 🔧 fix(conftest.py): remove unused function active_user 🐛 fix(test_endpoints.py): update import statements to use get_db_service instead of get_db_manager to improve code semantics 🐛 fix(test_login.py): update import statements to use get_db_service instead of get_db_manager to improve code semantics 🐛 fix(test_setup_superuser.py): update import statements to use get_db_service instead of get_db_manager to improve code semantics 🐛 fix(test_user.py): update import statements to use get_db_service instead of get_db_manager to improve code semantics
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from langflow.services.database.utils import session_getter
|
|
from langflow.services.getters import get_db_service
|
|
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):
|
|
# Adding the test user to the database
|
|
with session_getter(get_db_service()) as session:
|
|
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"
|