Added a web-frontend to add companies to the search queue. (#375)

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>
This commit is contained in:
2023-11-16 17:24:43 +01:00
committed by GitHub
parent 8e6b28b311
commit 96d216fb74
5 changed files with 159 additions and 24 deletions

View File

@ -1,5 +1,5 @@
"""Tests if the about page can be created."""
from dash.development.base_component import Component
from dash import html
from aki_prj23_transparenzregister.ui import app
from aki_prj23_transparenzregister.ui.pages import about
@ -10,6 +10,4 @@ _ = app
def test_layout() -> None:
"""Checks if the about page can be created."""
result = about.layout()
assert isinstance(result, list)
for e in result:
assert isinstance(e, Component)
assert isinstance(result, html.Div)

View File

@ -0,0 +1,64 @@
"""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