mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-24 16:52:34 +02:00
test(utils): Cover added functiosnn in CompanyMongoService
This commit is contained in:
parent
4944372ebc
commit
2eaa1c5a65
@ -73,7 +73,7 @@ def test_by_id_no_result(mock_mongo_connector: Mock, mock_collection: Mock) -> N
|
||||
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 # type: ignore
|
||||
assert service.get_by_id("Does not exist") is None
|
||||
|
||||
|
||||
def test_by_id_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
@ -87,7 +87,7 @@ def test_by_id_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None
|
||||
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 # type: ignore
|
||||
assert service.get_by_id("Does exist") == mock_entry
|
||||
|
||||
|
||||
def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
@ -101,4 +101,50 @@ def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_result = 42
|
||||
mock_collection.insert_one.return_value = mock_result
|
||||
assert service.insert(Company(None, None, "", "", [])) == mock_result # type: ignore
|
||||
assert service.insert(Company(None, None, "", "", [])) == mock_result
|
||||
|
||||
|
||||
def test_get_by_object_id_no_result(
|
||||
mock_mongo_connector: Mock, mock_collection: Mock
|
||||
) -> None:
|
||||
mock_mongo_connector.database = {"companies": mock_collection}
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_result: list = []
|
||||
mock_collection.find.return_value = mock_result
|
||||
assert service.get_by_object_id("649f16a1e198338c3b44299e") is None
|
||||
|
||||
|
||||
def test_get_by_object_id(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
mock_mongo_connector.database = {"companies": mock_collection}
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_result: list = [{"_id": "abc", "brille?": "Fielmann", "Hotel?": "Trivago"}]
|
||||
mock_collection.find.return_value = mock_result
|
||||
assert service.get_by_object_id("612316a1e198338c3b44299e") == mock_result[0]
|
||||
|
||||
|
||||
def test_get_where_financial_no_results(
|
||||
mock_mongo_connector: Mock, mock_collection: Mock
|
||||
) -> None:
|
||||
mock_mongo_connector.database = {"companies": mock_collection}
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_result: list = [{"_id": "abc", "brille?": "Fielmann", "Hotel?": "Trivago"}]
|
||||
mock_collection.find.return_value = mock_result
|
||||
assert service.get_where_no_financial_results() == mock_result
|
||||
|
||||
|
||||
def test_get_where_financial_results(
|
||||
mock_mongo_connector: Mock, mock_collection: Mock
|
||||
) -> None:
|
||||
mock_mongo_connector.database = {"companies": mock_collection}
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_result: list = [{"_id": "abc", "brille?": "Fielmann", "Hotel?": "Trivago"}]
|
||||
mock_collection.find.return_value = mock_result
|
||||
assert service.get_where_yearly_results() == mock_result
|
||||
|
||||
|
||||
def test_add_yearly_reslults(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||
mock_mongo_connector.database = {"companies": mock_collection}
|
||||
service = CompanyMongoService(mock_mongo_connector)
|
||||
mock_result: list = [{"_id": "abc", "brille?": "Fielmann", "Hotel?": "Trivago"}]
|
||||
mock_collection.update_one.return_value = mock_result
|
||||
assert service.add_yearly_results("612316a1e198338c3b44299e", {}) == mock_result
|
||||
|
Loading…
x
Reference in New Issue
Block a user