🔧 fix(tests/conftest.py): remove unused imports and commented out code
🔧 fix(tests/conftest.py): remove unused fixture 'client' 🔧 fix(tests/conftest.py): remove unused import of 'langflow.main.create_app' 🔧 fix(tests/conftest.py): remove unused fixture 'client_fixture' 🔧 fix(tests/conftest.py): remove unused import of 'langflow.services.database.manager.DatabaseManager' 🔧 fix(tests/conftest.py): remove unused import of 'typer.testing.CliRunner' 🔧 fix(tests/conftest.py): remove unused import of 'sqlmodel.SQLModel' 🔧 fix(tests/conftest.py): remove unused import of 'sqlmodel.Session' 🔧 fix(tests/conftest.py): remove unused import of 'sqlmodel.create_engine' 🔧 fix(tests/conftest.py): remove unused import of 'sqlmodel.pool.StaticPool' 🔧 fix(tests/conftest.py): remove unused import of 'tempfile' 🔧 fix(tests/conftest.py): remove unused import of 'Path' 🔧 fix(tests/conftest.py): remove unused import of 'contextmanager' 🔧 fix(tests/test_custom_component.py): remove unused argument 'session_getter' from test functions 🔧 fix(tests/test_custom_component.py): remove unused import of 'db' 🔧 fix(tests/test_custom_component.py): remove unused import of 'Flow' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'DEFAULT_SUPERUSER_PASSWORD' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'Mock' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'User' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'reset_mock_credentials' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'mock_create_super_user' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'setup_superuser' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'mock_user' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'mock_get_session' 🔧 fix(tests/test_setup_superuser.py): remove unused import of 'mock_get_settings_manager'
This commit is contained in:
parent
916dd457e9
commit
82469752f8
3 changed files with 32 additions and 19 deletions
|
|
@ -15,6 +15,9 @@ from sqlmodel import SQLModel, Session, create_engine
|
|||
from sqlmodel.pool import StaticPool
|
||||
from typer.testing import CliRunner
|
||||
|
||||
# we need to import tmpdir
|
||||
import tempfile
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.services.database.manager import DatabaseManager
|
||||
|
||||
|
|
@ -46,14 +49,14 @@ async def async_client() -> AsyncGenerator:
|
|||
|
||||
|
||||
# Create client fixture for FastAPI
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def client():
|
||||
from langflow.main import create_app
|
||||
# @pytest.fixture(scope="module", autouse=True)
|
||||
# def client():
|
||||
# from langflow.main import create_app
|
||||
|
||||
app = create_app()
|
||||
# app = create_app()
|
||||
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
# with TestClient(app) as client:
|
||||
# yield client
|
||||
|
||||
|
||||
def get_graph(_type="basic"):
|
||||
|
|
@ -111,8 +114,13 @@ def session_fixture():
|
|||
yield session
|
||||
|
||||
|
||||
@pytest.fixture(name="client")
|
||||
def client_fixture(session: Session):
|
||||
@pytest.fixture(name="client", autouse=True)
|
||||
def client_fixture(session: Session, monkeypatch):
|
||||
# Set the database url to a test database
|
||||
db_dir = tempfile.mkdtemp()
|
||||
db_path = Path(db_dir) / "test.db"
|
||||
monkeypatch.setenv("LANGFLOW_DATABASE_URL", f"sqlite:///{db_path}")
|
||||
|
||||
def get_session_override():
|
||||
return session
|
||||
|
||||
|
|
@ -124,6 +132,9 @@ def client_fixture(session: Session):
|
|||
with TestClient(app) as client:
|
||||
yield client
|
||||
app.dependency_overrides.clear()
|
||||
monkeypatch.undo()
|
||||
# clear the temp db
|
||||
db_path.unlink()
|
||||
|
||||
|
||||
# @contextmanager
|
||||
|
|
|
|||
|
|
@ -518,13 +518,13 @@ def db(app):
|
|||
app.db.drop_all()
|
||||
|
||||
|
||||
def test_list_flows_return_type(component, session_getter):
|
||||
flows = component.list_flows(get_session=session_getter)
|
||||
def test_list_flows_return_type(component):
|
||||
flows = component.list_flows()
|
||||
assert isinstance(flows, list)
|
||||
|
||||
|
||||
def test_list_flows_flow_objects(component, session_getter):
|
||||
flows = component.list_flows(get_session=session_getter)
|
||||
def test_list_flows_flow_objects(component):
|
||||
flows = component.list_flows()
|
||||
assert all(isinstance(flow, Flow) for flow in flows)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,11 @@ def test_setup_superuser(
|
|||
DEFAULT_SUPERUSER_PASSWORD
|
||||
)
|
||||
|
||||
ADMIN_USER_NAME = "admin_user"
|
||||
# Test when username and password are default
|
||||
mock_settings_manager.auth_settings = Mock()
|
||||
mock_settings_manager.auth_settings.AUTO_LOGIN = False
|
||||
mock_settings_manager.auth_settings.SUPERUSER = "admin"
|
||||
mock_settings_manager.auth_settings.SUPERUSER = ADMIN_USER_NAME
|
||||
mock_settings_manager.auth_settings.SUPERUSER_PASSWORD = "password"
|
||||
mock_settings_manager.auth_settings.reset_credentials = Mock(
|
||||
side_effect=reset_mock_credentials
|
||||
|
|
@ -46,20 +47,20 @@ def test_setup_superuser(
|
|||
setup_superuser()
|
||||
mock_session.query.assert_called_once_with(User)
|
||||
actual_expr = mock_session.query.return_value.filter.call_args[0][0]
|
||||
expected_expr = User.username == "admin"
|
||||
expected_expr = User.username == ADMIN_USER_NAME
|
||||
|
||||
assert str(actual_expr) == str(expected_expr)
|
||||
mock_create_super_user.assert_called_once_with(
|
||||
db=mock_session, username="admin", password="password"
|
||||
db=mock_session, username=ADMIN_USER_NAME, password="password"
|
||||
)
|
||||
# Test that superuser credentials are reset
|
||||
mock_settings_manager.auth_settings.reset_credentials.assert_called_once()
|
||||
assert mock_settings_manager.auth_settings.SUPERUSER != "admin"
|
||||
assert mock_settings_manager.auth_settings.SUPERUSER != ADMIN_USER_NAME
|
||||
assert mock_settings_manager.auth_settings.SUPERUSER_PASSWORD != "password"
|
||||
|
||||
# Test when superuser already exists
|
||||
mock_settings_manager.auth_settings.AUTO_LOGIN = False
|
||||
mock_settings_manager.auth_settings.SUPERUSER = "admin"
|
||||
mock_settings_manager.auth_settings.SUPERUSER = ADMIN_USER_NAME
|
||||
mock_settings_manager.auth_settings.SUPERUSER_PASSWORD = "password"
|
||||
mock_user = Mock()
|
||||
mock_user.is_superuser = True
|
||||
|
|
@ -67,7 +68,7 @@ def test_setup_superuser(
|
|||
setup_superuser()
|
||||
mock_session.query.assert_called_with(User)
|
||||
actual_expr = mock_session.query.return_value.filter.call_args[0][0]
|
||||
expected_expr = User.username == "admin"
|
||||
expected_expr = User.username == ADMIN_USER_NAME
|
||||
|
||||
assert str(actual_expr) == str(expected_expr)
|
||||
|
||||
|
|
@ -108,9 +109,10 @@ def test_teardown_superuser_default_superuser(
|
|||
def test_teardown_superuser_no_default_superuser(
|
||||
mock_get_session, mock_get_settings_manager
|
||||
):
|
||||
ADMIN_USER_NAME = "admin_user"
|
||||
mock_settings_manager = MagicMock()
|
||||
mock_settings_manager.auth_settings.AUTO_LOGIN = False
|
||||
mock_settings_manager.auth_settings.SUPERUSER = "admin"
|
||||
mock_settings_manager.auth_settings.SUPERUSER = ADMIN_USER_NAME
|
||||
mock_settings_manager.auth_settings.SUPERUSER_PASSWORD = "password"
|
||||
mock_get_settings_manager.return_value = mock_settings_manager
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue