"""Unit tests for save_latest_timestamp.""" import pytest import snowflake_views.tasks as tasks from tests.tasks import conftest mock_timestamp = '2018-01-01 00:00:00' @pytest.fixture def mock_update_item_in_dynamo(mock_dynamo_table): """Mock update_item in Dynamo.""" return mock_dynamo_table.return_value.update_item @pytest.fixture def save_last_processed_timestamp( mock_activity, mock_ingestion_status_table, mock_dynamo_table, mock_aws_region): """Check Dynamo status.""" tasks.save_last_processed_timestamp( mock_activity, conftest.VIEW_NAME, mock_timestamp) def test_dynamo_resource_is_invoked( mock_boto3_resource, save_last_processed_timestamp): """Test Dynamo resource is invoked.""" mock_boto3_resource.assert_called_with( 'dynamodb', region_name=conftest.AWS_REGION) def test_dynamo_table_is_invoked( mock_dynamo_table, save_last_processed_timestamp): """Test Dynamo table is invoked.""" mock_dynamo_table.assert_called_with(conftest.INGESTION_STATUS_TABLE) def test_dynamo_table_is_queried( mock_update_item_in_dynamo, save_last_processed_timestamp): """Test Dynamo is queried.""" mock_update_item_in_dynamo.assert_called_with( Key={'view_name': conftest.VIEW_NAME}, UpdateExpression='SET last_processed_timestamp = :d', ExpressionAttributeValues={':d': mock_timestamp})