"""Tests if the search que page can be created.""" from collections.abc import Generator import dash import pytest from dash import html from sqlalchemy.orm import Session from aki_prj23_transparenzregister.ui import app from aki_prj23_transparenzregister.ui.pages import search_queue from aki_prj23_transparenzregister.ui.session_handler import SessionHandler from aki_prj23_transparenzregister.utils.sql import entities _ = app def test_layout() -> None: """Checks if the about page can be created.""" result = search_queue.layout() assert isinstance(result, html.Div) @pytest.mark.parametrize("input_text", ["", None]) def test_empty(input_text: str | None) -> None: """Tests if nothing happens on an empty string.""" assert search_queue.add_company_to_search_que(input_text) == dash.no_update @pytest.mark.parametrize("input_text", ["test"]) def test_missing_db(input_text: str | None) -> None: """Tests what happens if no db is defined.""" with pytest.raises(ValueError, match="No session created."): search_queue.add_company_to_search_que(input_text) @pytest.fixture() def _set_session(full_db: Session) -> Generator[None, None, None]: """Sets a session for the dash application to be used.""" SessionHandler.session = full_db yield SessionHandler.session = None @pytest.mark.usefixtures("_set_session") @pytest.mark.parametrize("name", ["added-company", "second", "third"]) def test_add_company_to_queue(name: str) -> None: """Adds a company to the search que via the webgui.""" db = SessionHandler.session assert db assert not ( db.query(entities.MissingCompany) .filter(entities.MissingCompany.name == name) .first() ) for n_lines in [1000, 2000, 3000]: search_queue.add_company_to_search_que(name) result = ( db.query(entities.MissingCompany) .filter(entities.MissingCompany.name == name) .first() ) assert result assert result.number_of_links == n_lines # noqa: PLR2004 del result