Script for the transfer of data from Mongo to SQL (#80)

This commit is contained in:
2023-09-11 20:21:35 +02:00
committed by GitHub
parent 2ea99c8c17
commit d64f53eca9
22 changed files with 1565 additions and 73 deletions

View File

@@ -1,3 +1,4 @@
"""Tests for the mongo news service."""
from unittest.mock import Mock, patch
import pytest
@@ -50,6 +51,7 @@ def test_init(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
def test_get_all(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
"""Tests the get_all function from the mongo connector."""
mock_mongo_connector.database = {"news": mock_collection}
service = MongoNewsService(mock_mongo_connector)
@@ -60,6 +62,7 @@ def test_get_all(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
def test_get_by_id_with_result(
mock_mongo_connector: Mock, mock_collection: Mock
) -> None:
"""Tests the get_by_id_with_result function from the mongo connector."""
mock_mongo_connector.database = {"news": mock_collection}
service = MongoNewsService(mock_mongo_connector)
@@ -72,6 +75,7 @@ def test_get_by_id_with_result(
def test_get_by_id_no_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
"""Test if the mongo connector can get an object by id."""
mock_mongo_connector.database = {"news": mock_collection}
service = MongoNewsService(mock_mongo_connector)
@@ -80,6 +84,7 @@ def test_get_by_id_no_result(mock_mongo_connector: Mock, mock_collection: Mock)
def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
"""Tests the insert function from the mongo connector."""
mock_mongo_connector.database = {"news": mock_collection}
service = MongoNewsService(mock_mongo_connector)
@@ -92,6 +97,7 @@ def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
def test_transform_ingoing() -> None:
"""Tests the transform_ingoing function from the mongo connector."""
news = News("42", None, None, None, None) # type: ignore
result = MongoEntryTransformer.transform_ingoing(news)
assert result["_id"] == "42"
@@ -99,6 +105,7 @@ def test_transform_ingoing() -> None:
def test_transform_outgoing() -> None:
"""Tests the transform_outgoing function from the mongo connector."""
data = {
"_id": "4711",
"title": "Hello",