"""Projections ETL specific log unit tests.""" from copy import copy from datetime import datetime from unittest import mock from unittest.mock import patch from flows.theatrical_cuts import log, status @patch('flows.theatrical_cuts.log.datetime') @patch('flows.theatrical_cuts.log.datastore') def test_create(mock_datastore, mock_datetime, database_context): """Test create function.""" # mock required functions mock_now = datetime(1900, 1, 1, 1, 1, 1) mock_datastore.context = database_context mock_datetime.now.return_value = mock_now # prepare test data log_params = { 'correlation_id': 'cid', 'workflow_run_id': 'rid', 'upc': 123} expected = copy(log_params) expected['etl_start'] = mock_now expected['etl_status'] = status.STARTED # call test function log.create(**log_params) # check function calls mock_datastore.execute.assert_called_with(mock.ANY, expected) @patch('flows.theatrical_cuts.log.datastore') def test_update_status(mock_datastore, database_context): """Test a db row status update.""" mock_datastore.context = database_context log.update_status(correlation_id='cid123', status='test_status') log.update_status(correlation_id='cid123.1.2.3.4', status='test_status') call_list = mock_datastore.execute.call_args_list expected = { 'correlation_id': 'cid123', 'status': 'test_status'} assert call_list[0][0][1] == expected assert call_list[1][0][1] == expected