mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-22 00:14:01 +02:00
Chore/rework workflow (#52)
* Reworked the lint action * Removed the file change requirement * Repaired mypy * Repaired pip-audit
This commit is contained in:
@ -6,12 +6,12 @@ import pytest
|
||||
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
||||
|
||||
|
||||
def test_json_provider_init_fail():
|
||||
def test_json_provider_init_fail() -> None:
|
||||
with pytest.raises(FileNotFoundError):
|
||||
JsonFileConfigProvider("file-that-does-not-exist")
|
||||
|
||||
|
||||
def test_json_provider_init_no_json():
|
||||
def test_json_provider_init_no_json() -> None:
|
||||
with patch("os.path.isfile") as mock_isfile, patch(
|
||||
"builtins.open", mock_open(read_data="fhdaofhdoas")
|
||||
):
|
||||
@ -20,7 +20,7 @@ def test_json_provider_init_no_json():
|
||||
JsonFileConfigProvider("non-json-file")
|
||||
|
||||
|
||||
def test_json_provider_init():
|
||||
def test_json_provider_init() -> None:
|
||||
data = {"hello": "world"}
|
||||
input_data = json.dumps(data)
|
||||
with patch("os.path.isfile") as mock_isfile:
|
||||
@ -30,7 +30,7 @@ def test_json_provider_init():
|
||||
assert provider.__data__ == data
|
||||
|
||||
|
||||
def test_json_provider_get_postgre():
|
||||
def test_json_provider_get_postgres() -> None:
|
||||
data = {
|
||||
"postgres": {
|
||||
"username": "user",
|
||||
@ -52,7 +52,7 @@ def test_json_provider_get_postgre():
|
||||
assert config.port == data["postgres"]["port"]
|
||||
|
||||
|
||||
def test_json_provider_get_mongo():
|
||||
def test_json_provider_get_mongo() -> None:
|
||||
data = {
|
||||
"mongo": {
|
||||
"username": "user",
|
||||
|
7
tests/ui/company_stats_dash_test.py
Normal file
7
tests/ui/company_stats_dash_test.py
Normal file
@ -0,0 +1,7 @@
|
||||
"""Test the compy stats dash file."""
|
||||
from aki_prj23_transparenzregister.ui import company_stats_dash
|
||||
|
||||
|
||||
def test_company_stats_dash_import() -> None:
|
||||
"""Since there is no single method to test the import is tested instead."""
|
||||
assert company_stats_dash
|
@ -10,7 +10,7 @@ from aki_prj23_transparenzregister.utils.mongo.company_mongo_service import (
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def mock_mongo_connector(mocker) -> Mock:
|
||||
def mock_mongo_connector(mocker: Mock) -> Mock:
|
||||
"""Mock MongoConnector class.
|
||||
|
||||
Args:
|
||||
@ -37,7 +37,7 @@ def mock_collection() -> Mock:
|
||||
return Mock()
|
||||
|
||||
|
||||
def test_init(mock_mongo_connector, mock_collection):
|
||||
def test_init(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
"""Test CompanyMongoService constructor.
|
||||
|
||||
Args:
|
||||
@ -49,7 +49,7 @@ def test_init(mock_mongo_connector, mock_collection):
|
||||
assert service.collection == mock_collection
|
||||
|
||||
|
||||
def test_get_all(mock_mongo_connector, mock_collection):
|
||||
def test_get_all(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
"""Test CompanyMongoService get_all method.
|
||||
|
||||
Args:
|
||||
@ -63,7 +63,7 @@ def test_get_all(mock_mongo_connector, mock_collection):
|
||||
assert service.get_all() == mock_result
|
||||
|
||||
|
||||
def test_by_id_no_result(mock_mongo_connector, mock_collection):
|
||||
def test_by_id_no_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
"""Test CompanyMongoService get_by_id with no result.
|
||||
|
||||
Args:
|
||||
@ -73,10 +73,10 @@ def test_by_id_no_result(mock_mongo_connector, mock_collection):
|
||||
mock_mongo_connector.database = {"companies": mock_collection}
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_collection.find.return_value = []
|
||||
assert service.get_by_id("Does not exist") is None
|
||||
assert service.get_by_id("Does not exist") is None # type: ignore
|
||||
|
||||
|
||||
def test_by_id_result(mock_mongo_connector, mock_collection):
|
||||
def test_by_id_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
"""Test CompanyMongoService get_by_id with result.
|
||||
|
||||
Args:
|
||||
@ -87,10 +87,10 @@ def test_by_id_result(mock_mongo_connector, mock_collection):
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_entry = {"id": "Does exist", "vaue": 42}
|
||||
mock_collection.find.return_value = [mock_entry]
|
||||
assert service.get_by_id("Does exist") == mock_entry
|
||||
assert service.get_by_id("Does exist") == mock_entry # type: ignore
|
||||
|
||||
|
||||
def test_insert(mock_mongo_connector, mock_collection):
|
||||
def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
"""Test CompanyMongoService insert method.
|
||||
|
||||
Args:
|
||||
@ -101,4 +101,4 @@ def test_insert(mock_mongo_connector, mock_collection):
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_result = 42
|
||||
mock_collection.insert_one.return_value = mock_result
|
||||
assert service.insert(Company(None, None, "", "", [])) == mock_result
|
||||
assert service.insert(Company(None, None, "", "", [])) == mock_result # type: ignore
|
||||
|
@ -6,22 +6,22 @@ from aki_prj23_transparenzregister.utils.mongo.connector import (
|
||||
)
|
||||
|
||||
|
||||
def test_get_conn_string_no_credentials():
|
||||
def test_get_conn_string_no_credentials() -> None:
|
||||
conn = MongoConnection("localhost", "", 27017, None, None)
|
||||
assert conn.get_conn_string() == "mongodb://localhost:27017"
|
||||
|
||||
|
||||
def test_get_conn_string_no_port_but_credentials():
|
||||
def test_get_conn_string_no_port_but_credentials() -> None:
|
||||
conn = MongoConnection("localhost", "", None, "admin", "password")
|
||||
assert conn.get_conn_string() == "mongodb+srv://admin:password@localhost"
|
||||
|
||||
|
||||
def test_get_conn_simple():
|
||||
def test_get_conn_simple() -> None:
|
||||
conn = MongoConnection("localhost", "", None, None, None)
|
||||
assert conn.get_conn_string() == "mongodb+srv://localhost"
|
||||
|
||||
|
||||
def test_mongo_connector():
|
||||
def test_mongo_connector() -> None:
|
||||
with patch("pymongo.MongoClient") as mock_mongo_client:
|
||||
expected_result = 42
|
||||
mock_mongo_client.return_value = {"db": expected_result}
|
||||
|
@ -10,7 +10,7 @@ from aki_prj23_transparenzregister.utils.mongo.news_mongo_service import (
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def mock_mongo_connector(mocker) -> Mock:
|
||||
def mock_mongo_connector(mocker: Mock) -> Mock:
|
||||
"""Mock MongoConnector class.
|
||||
|
||||
Args:
|
||||
@ -37,7 +37,7 @@ def mock_collection() -> Mock:
|
||||
return Mock()
|
||||
|
||||
|
||||
def test_init(mock_mongo_connector, mock_collection):
|
||||
def test_init(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
"""Test CompanyMongoService constructor.
|
||||
|
||||
Args:
|
||||
@ -49,7 +49,7 @@ def test_init(mock_mongo_connector, mock_collection):
|
||||
assert service.collection == mock_collection
|
||||
|
||||
|
||||
def test_get_all(mock_mongo_connector, mock_collection):
|
||||
def test_get_all(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
mock_mongo_connector.database = {"news": mock_collection}
|
||||
service = MongoNewsService(mock_mongo_connector)
|
||||
|
||||
@ -57,7 +57,9 @@ def test_get_all(mock_mongo_connector, mock_collection):
|
||||
assert service.get_all() == []
|
||||
|
||||
|
||||
def test_get_by_id_with_result(mock_mongo_connector, mock_collection):
|
||||
def test_get_by_id_with_result(
|
||||
mock_mongo_connector: Mock, mock_collection: Mock
|
||||
) -> None:
|
||||
mock_mongo_connector.database = {"news": mock_collection}
|
||||
service = MongoNewsService(mock_mongo_connector)
|
||||
|
||||
@ -69,7 +71,7 @@ def test_get_by_id_with_result(mock_mongo_connector, mock_collection):
|
||||
assert service.get_by_id("foadh") == {}
|
||||
|
||||
|
||||
def test_get_by_id_no_result(mock_mongo_connector, mock_collection):
|
||||
def test_get_by_id_no_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
mock_mongo_connector.database = {"news": mock_collection}
|
||||
service = MongoNewsService(mock_mongo_connector)
|
||||
|
||||
@ -77,7 +79,7 @@ def test_get_by_id_no_result(mock_mongo_connector, mock_collection):
|
||||
assert service.get_by_id("foadh") is None
|
||||
|
||||
|
||||
def test_insert(mock_mongo_connector, mock_collection):
|
||||
def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
mock_mongo_connector.database = {"news": mock_collection}
|
||||
service = MongoNewsService(mock_mongo_connector)
|
||||
|
||||
@ -86,17 +88,17 @@ def test_insert(mock_mongo_connector, mock_collection):
|
||||
) as mock_in:
|
||||
mock_collection.insert_one.return_value = {}
|
||||
mock_in.return_value = {}
|
||||
assert service.insert({}) == {}
|
||||
assert service.insert({}) == {} # type: ignore
|
||||
|
||||
|
||||
def test_transform_ingoing():
|
||||
news = News("42", None, None, None, None)
|
||||
def test_transform_ingoing() -> None:
|
||||
news = News("42", None, None, None, None) # type: ignore
|
||||
result = MongoEntryTransformer.transform_ingoing(news)
|
||||
assert result["_id"] == "42"
|
||||
assert "id" not in result
|
||||
|
||||
|
||||
def test_transform_outgoing():
|
||||
def test_transform_outgoing() -> None:
|
||||
data = {
|
||||
"_id": "4711",
|
||||
"title": "Hello",
|
||||
|
@ -4,7 +4,7 @@ from aki_prj23_transparenzregister.config.config_template import PostgreConnecti
|
||||
from aki_prj23_transparenzregister.utils.postgres.connector import get_engine, init_db
|
||||
|
||||
|
||||
def test_get_engine():
|
||||
def test_get_engine() -> None:
|
||||
conn_args = PostgreConnectionString("", "", "", "", 42)
|
||||
with patch(
|
||||
"aki_prj23_transparenzregister.utils.postgres.connector.create_engine"
|
||||
@ -14,7 +14,7 @@ def test_get_engine():
|
||||
assert get_engine(conn_args) == result
|
||||
|
||||
|
||||
def test_init_db():
|
||||
def test_init_db() -> None:
|
||||
with patch(
|
||||
"aki_prj23_transparenzregister.utils.postgres.connector.get_engine"
|
||||
) as mock_get_engine, patch(
|
||||
|
@ -1,4 +1,4 @@
|
||||
def test_import():
|
||||
def test_import() -> None:
|
||||
from aki_prj23_transparenzregister.utils.postgres import entities
|
||||
|
||||
assert entities is not None
|
||||
|
Reference in New Issue
Block a user