SIENTIAPDE-1163
SIENTIAPDE-1163 Refactor Ingestor and DataManager classes to enhance metadata handling - Updated Ingestor class to include additional metadata fields: 'workflow_name' and 'schema_name'. - Modified DataManager to accept metadata during initialization. - Adjusted unit tests to validate the new metadata structure and ensure proper functionality across various managers. - Removed unused logger initialization in tests for cleaner code.
This commit is contained in:
@@ -6,9 +6,8 @@ from ingestor.ingestor import Ingestor
|
||||
|
||||
|
||||
@patch("ingestor.ingestor.getenv")
|
||||
@patch("ingestor.ingestor.Ingestor.init_logger")
|
||||
@patch("ingestor.ingestor.NotificationHandler")
|
||||
def test___init__(notification_handler, init_logger, getenv):
|
||||
def test___init__(notification_handler, getenv):
|
||||
getenv.side_effect = [
|
||||
"localhost:9092,localhost:35", # KAFKA_SERVERS
|
||||
"true", # EXPORT_TO_KAFKA
|
||||
@@ -20,7 +19,7 @@ def test___init__(notification_handler, init_logger, getenv):
|
||||
'200', # HEARTBEAT_TTL
|
||||
"localhost1", # HOSTNAME
|
||||
'50', # POLL_INTERVAL
|
||||
"mongodb://localhost:27017", # MONGODB_URL
|
||||
"localhost:27017", # MONGODB_URL
|
||||
"sientia", # MONGODB_USERNAME
|
||||
"sientia", # MONGODB_PASSWORD
|
||||
"sientia" # MONGODB_DATABASE
|
||||
@@ -47,10 +46,16 @@ def test___init__(notification_handler, init_logger, getenv):
|
||||
assert ingestor.heartbeat_ttl == 200
|
||||
assert ingestor.pod_id == "localhost1"
|
||||
assert ingestor.poll_interval == 50
|
||||
assert ingestor.metadata == {
|
||||
"model_id": "-",
|
||||
"model_name": "-",
|
||||
"workflow_name": "OPC_INGESTOR",
|
||||
"schema_name": "OPC_INGESTOR",
|
||||
}
|
||||
|
||||
init_logger.assert_called_once()
|
||||
notification_handler.assert_called_once_with(
|
||||
servers=["localhost:9092", "localhost:35"],
|
||||
connection_string="mongodb://sientia:sientia@localhost:27017",
|
||||
database="sientia",
|
||||
logger=ingestor.logger,
|
||||
project_name="OPC_INGESTOR"
|
||||
)
|
||||
@@ -58,9 +63,8 @@ def test___init__(notification_handler, init_logger, getenv):
|
||||
|
||||
@fixture
|
||||
@patch("ingestor.ingestor.getenv")
|
||||
@patch("ingestor.ingestor.Ingestor.init_logger")
|
||||
@patch("ingestor.ingestor.NotificationHandler")
|
||||
def ingestor(_notification_handler, _init_logger, _getenv):
|
||||
def ingestor(_notification_handler, _getenv):
|
||||
ing = Ingestor()
|
||||
ing.logger = MagicMock()
|
||||
|
||||
@@ -73,25 +77,6 @@ def ingestor_manager_started(ingestor):
|
||||
return ingestor
|
||||
|
||||
|
||||
@patch("ingestor.ingestor.getLogger")
|
||||
@patch("ingestor.ingestor.StreamHandler")
|
||||
@patch("ingestor.ingestor.Formatter")
|
||||
def test_init_logger(formatter, stream_handler, get_logger, ingestor):
|
||||
ingestor.logger = None
|
||||
ingestor.init_logger()
|
||||
|
||||
get_logger.assert_called_once_with('ingestor.ingestor')
|
||||
stream_handler.assert_called_once()
|
||||
formatter.assert_called_once_with(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
ingestor.logger.setLevel.assert_called_once_with(
|
||||
getenv("LOG_LEVEL", "INFO"))
|
||||
ingestor.logger.addHandler.assert_called_once_with(
|
||||
stream_handler.return_value)
|
||||
stream_handler.return_value.setFormatter.assert_called_once_with(
|
||||
formatter.return_value)
|
||||
|
||||
|
||||
def test_handle_acquired_tags_not_acquired(ingestor_manager_started):
|
||||
ingestor_manager_started.handle_acquired_tags([])
|
||||
|
||||
@@ -118,22 +103,23 @@ def test_prepare_ingestor(ingestor_manager_mock, ingestor):
|
||||
ingestor.prepare_ingestor()
|
||||
|
||||
ingestor_manager_mock.assert_called_once_with(
|
||||
ingestor.kafka_servers,
|
||||
{
|
||||
kafka_servers=ingestor.kafka_servers,
|
||||
redis_data={
|
||||
"host": ingestor.redis_host,
|
||||
"port": ingestor.redis_port,
|
||||
"username": ingestor.redis_username,
|
||||
"password": ingestor.redis_password
|
||||
},
|
||||
ingestor.lease_ttl,
|
||||
ingestor.heartbeat_ttl,
|
||||
ingestor.pod_id,
|
||||
ingestor.poll_interval,
|
||||
ingestor.mongo_connection_string,
|
||||
ingestor.mongo_database,
|
||||
ingestor.logger,
|
||||
ingestor.notification_handler,
|
||||
ingestor.export_to_kafka
|
||||
lease_ttl=ingestor.lease_ttl,
|
||||
heartbeat_ttl=ingestor.heartbeat_ttl,
|
||||
pod_id=ingestor.pod_id,
|
||||
poll_interval=ingestor.poll_interval,
|
||||
mongo_connection_string=ingestor.mongo_connection_string,
|
||||
mongo_database=ingestor.mongo_database,
|
||||
metadata=ingestor.metadata,
|
||||
logger=ingestor.logger,
|
||||
notification_handler=ingestor.notification_handler,
|
||||
export_to_kafka=ingestor.export_to_kafka,
|
||||
)
|
||||
ingestor_manager.declare_active.assert_called_once()
|
||||
ingestor_manager.get_slot_leases.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user