Refactor test cases for improved readability and consistency
- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation. - Adjusted assertions to use multi-line formatting for better readability. - Added new test cases for theme settings API to ensure proper functionality. - Ensured consistent use of line breaks and spacing across test files for uniformity.
This commit is contained in:
@@ -27,7 +27,8 @@ engine = create_engine(
|
||||
poolclass=StaticPool,
|
||||
)
|
||||
TestingSessionLocal = sessionmaker(
|
||||
autocommit=False, autoflush=False, bind=engine)
|
||||
autocommit=False, autoflush=False, bind=engine
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
@@ -37,19 +38,24 @@ def setup_database() -> Generator[None, None, None]:
|
||||
application_setting,
|
||||
capex,
|
||||
consumption,
|
||||
currency,
|
||||
distribution,
|
||||
equipment,
|
||||
maintenance,
|
||||
opex,
|
||||
parameters,
|
||||
production_output,
|
||||
role,
|
||||
scenario,
|
||||
simulation_result,
|
||||
theme_setting,
|
||||
user,
|
||||
) # noqa: F401 - imported for side effects
|
||||
|
||||
_ = (
|
||||
capex,
|
||||
consumption,
|
||||
currency,
|
||||
distribution,
|
||||
equipment,
|
||||
maintenance,
|
||||
@@ -57,8 +63,11 @@ def setup_database() -> Generator[None, None, None]:
|
||||
opex,
|
||||
parameters,
|
||||
production_output,
|
||||
role,
|
||||
scenario,
|
||||
simulation_result,
|
||||
theme_setting,
|
||||
user,
|
||||
)
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
@@ -86,22 +95,23 @@ def api_client(db_session: Session) -> Generator[TestClient, None, None]:
|
||||
finally:
|
||||
pass
|
||||
|
||||
from routes import dependencies as route_dependencies
|
||||
from routes.dependencies import get_db
|
||||
|
||||
app.dependency_overrides[route_dependencies.get_db] = override_get_db
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
app.dependency_overrides.pop(route_dependencies.get_db, None)
|
||||
app.dependency_overrides.pop(get_db, None)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def seeded_ui_data(db_session: Session) -> Generator[Dict[str, Any], None, None]:
|
||||
def seeded_ui_data(
|
||||
db_session: Session,
|
||||
) -> Generator[Dict[str, Any], None, None]:
|
||||
"""Populate a scenario with representative related records for UI tests."""
|
||||
scenario_name = f"Scenario Alpha {uuid4()}"
|
||||
scenario = Scenario(name=scenario_name,
|
||||
description="Seeded UI scenario")
|
||||
scenario = Scenario(name=scenario_name, description="Seeded UI scenario")
|
||||
db_session.add(scenario)
|
||||
db_session.flush()
|
||||
|
||||
@@ -161,7 +171,9 @@ def seeded_ui_data(db_session: Session) -> Generator[Dict[str, Any], None, None]
|
||||
iteration=index,
|
||||
result=value,
|
||||
)
|
||||
for index, value in enumerate((950_000.0, 975_000.0, 990_000.0), start=1)
|
||||
for index, value in enumerate(
|
||||
(950_000.0, 975_000.0, 990_000.0), start=1
|
||||
)
|
||||
]
|
||||
|
||||
db_session.add(maintenance)
|
||||
@@ -196,11 +208,15 @@ def seeded_ui_data(db_session: Session) -> Generator[Dict[str, Any], None, None]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def invalid_request_payloads(db_session: Session) -> Generator[Dict[str, Any], None, None]:
|
||||
def invalid_request_payloads(
|
||||
db_session: Session,
|
||||
) -> Generator[Dict[str, Any], None, None]:
|
||||
"""Provide reusable invalid request bodies for exercising validation branches."""
|
||||
duplicate_name = f"Scenario Duplicate {uuid4()}"
|
||||
existing = Scenario(name=duplicate_name,
|
||||
description="Existing scenario for duplicate checks")
|
||||
existing = Scenario(
|
||||
name=duplicate_name,
|
||||
description="Existing scenario for duplicate checks",
|
||||
)
|
||||
db_session.add(existing)
|
||||
db_session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user