mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-22 06:52:54 +02:00
129 lines
5.4 KiB
Python
129 lines
5.4 KiB
Python
"""Tests for ui elements."""
|
|
|
|
import pandas as pd
|
|
from sqlalchemy.orm import Session
|
|
|
|
from aki_prj23_transparenzregister.ui import data_elements
|
|
from aki_prj23_transparenzregister.utils.enum_types import SentimentLabel
|
|
|
|
|
|
def test_import() -> None:
|
|
"""Checks if an import co ui_elements can be made."""
|
|
assert data_elements is not None
|
|
|
|
|
|
def test_get_company_data(full_db: Session) -> None:
|
|
"""Checks if data from the company and district court tables can be accessed."""
|
|
company_df = data_elements.get_company_data(full_db)
|
|
test_data = pd.DataFrame(
|
|
{
|
|
"company_id": {0: 1, 1: 2, 2: 3},
|
|
"company_hr": {0: "HRB 123", 1: "HRB 123", 2: "HRB 12"},
|
|
"company_court_id": {0: 2, 1: 1, 2: 2},
|
|
"company_name": {
|
|
0: "Some Company GmbH",
|
|
1: "Other Company GmbH",
|
|
2: "Third Company GmbH",
|
|
},
|
|
"company_company_type": {0: None, 1: None, 2: None},
|
|
"company_founding_date": {0: "2010-08-07"},
|
|
"company_business_purpose": {
|
|
0: 'Say "Hello World"',
|
|
1: "Some purpose",
|
|
},
|
|
"company_street": {0: "Sesamstr.", 1: "Sesamstr."},
|
|
"company_house_number": {0: "1", 1: "2"},
|
|
"company_zip_code": {0: "58644", 1: "58636"},
|
|
"company_city": {0: "TV City", 1: "TV City"},
|
|
"company_longitude": {0: 7.6968, 1: 7.7032},
|
|
"company_latitude": {0: 51.3246, 1: 51.38},
|
|
"company_pos_accuracy": {0: 4.0, 1: 4.0},
|
|
"company_capital_value": {0: 1000000.0, 2: 10000.0},
|
|
"company_original_currency": {0: "DEUTSCHE_MARK", 2: "EURO"},
|
|
"company_capital_type": {0: "HAFTEINLAGE", 2: "GRUNDKAPITAL"},
|
|
"company_last_update": {
|
|
0: "2023-01-01",
|
|
1: "2023-01-01",
|
|
2: "2023-01-01",
|
|
},
|
|
"company_sector": {2: "Electronic"},
|
|
"district_court_name": {
|
|
0: "Amtsgericht Dortmund",
|
|
1: "Amtsgericht Bochum",
|
|
2: "Amtsgericht Dortmund",
|
|
},
|
|
}
|
|
)
|
|
test_data = test_data.set_index("company_id")
|
|
pd.testing.assert_frame_equal(company_df, test_data)
|
|
|
|
|
|
def test_get_finance_data(full_db: Session) -> None:
|
|
"""Checks if data from the company and finance tables can be accessed."""
|
|
finance_df = data_elements.get_finance_data(full_db)
|
|
test_data = pd.DataFrame(
|
|
{
|
|
"annual_finance_statement_id": {0: 1, 1: 2},
|
|
"annual_finance_statement_company_id": {0: 1, 1: 1},
|
|
"annual_finance_statement_date": {0: "2023-01-01", 1: "2022-01-01"},
|
|
"annual_finance_statement_revenue": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_net_income": {0: 100.0},
|
|
"annual_finance_statement_ebit": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_ebitda": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_gross_profit": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_operating_profit": {1: 1.0},
|
|
"annual_finance_statement_assets": {0: 1000.0, 1: 1100},
|
|
"annual_finance_statement_liabilities": {0: 0.0},
|
|
"annual_finance_statement_equity": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_current_assets": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_current_liabilities": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_long_term_debt": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_short_term_debt": {0: 1000.0, 1: 1100.0},
|
|
"annual_finance_statement_cash_and_cash_equivalents": {0: 1.0},
|
|
"annual_finance_statement_dividends": {0: 0.0},
|
|
"annual_finance_statement_cash_flow": {0: 1000.0, 1: 1100.0},
|
|
"company_name": {0: "Some Company GmbH", 1: "Some Company GmbH"},
|
|
"company_id": {0: 1, 1: 1},
|
|
}
|
|
)
|
|
pd.testing.assert_frame_equal(finance_df, test_data)
|
|
|
|
|
|
def test_get_news_of_one_company0(news_db: Session) -> None:
|
|
"""Tests what happens if no sentiment can be found."""
|
|
selected_company_id = 100
|
|
assert data_elements.get_news_of_one_company(selected_company_id, news_db).empty
|
|
|
|
|
|
def test_get_news_of_one_company1(news_db: Session) -> None:
|
|
"""Tests if the sentiments can be collected for a company specified."""
|
|
selected_company_id = 2
|
|
sentiment_df = data_elements.get_news_of_one_company(selected_company_id, news_db)
|
|
assert sentiment_df is not None
|
|
assert sentiment_df.to_dict(orient="records") == [
|
|
{
|
|
"overall_sentiment_certainty": 0.95,
|
|
"overall_sentiment_label": SentimentLabel.POSITIVE,
|
|
"source_domain": "example-news.com",
|
|
"source_url": "http://example-news.com/ai-revolution",
|
|
"times_named": 2,
|
|
"timestamp": pd.Timestamp("2023-11-01 15:30:00"),
|
|
"title": "AI Revolution in Tech",
|
|
},
|
|
]
|
|
|
|
|
|
def test_options(full_db: Session) -> None:
|
|
"""Tests if the options can be generated."""
|
|
options = data_elements.get_options(full_db)
|
|
assert options == {
|
|
"c_1": "Some Company GmbH",
|
|
"c_2": "Other Company GmbH",
|
|
"c_3": "Third Company GmbH",
|
|
"p_1": "Mustermann, Max",
|
|
"p_2": "Mustermann, Sabine",
|
|
"p_3": "Some Surname, Some Firstname",
|
|
"p_4": "Some Surname, Some Firstname",
|
|
"p_5": "Other Surname, Other Firstname",
|
|
}
|