mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-22 22:22:54 +02:00
This webfrontent adds a company to the search que or resets the search que entry to be searched again. This will allow for directed growth or an initiallisation. --------- Co-authored-by: Tristan Nolde <tristan.nolde@yahoo.de>
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
"""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
|