def test_publish_duration_metric(mock_session): fake_datetime = datetime(2019, 1, 1) proxy = MetricsPublisherProxy(ACCOUNT_ID, RESOURCE_TYPE) proxy.add_metrics_publisher(mock_session) proxy.publish_duration_metric(fake_datetime, Action.CREATE, 100) expected_calls = [ call.client("cloudwatch"), call.client().put_metric_data( Namespace="AWS/CloudFormation/123412341234/Aa/Bb/Cc", MetricData=[{ "MetricName": MetricTypes.HandlerInvocationDuration.name, "Dimensions": [ { "Name": "DimensionKeyActionType", "Value": "CREATE" }, { "Name": "DimensionKeyResourceType", "Value": "Aa::Bb::Cc" }, ], "Unit": StandardUnit.Milliseconds.name, "Timestamp": str(fake_datetime), "Value": 100, }], ), ] assert mock_session.mock_calls == expected_calls
def test_publish_log_delivery_exception_metric(mock_session): fake_datetime = datetime(2019, 1, 1) proxy = MetricsPublisherProxy(ACCOUNT_ID, RESOURCE_TYPE) proxy.add_metrics_publisher(mock_session) proxy.publish_log_delivery_exception_metric(fake_datetime, TypeError("test")) expected_calls = [ call.client("cloudwatch"), call.client().put_metric_data( Namespace="AWS/CloudFormation/123412341234/Aa/Bb/Cc", MetricData=[{ "MetricName": MetricTypes.HandlerException.name, "Dimensions": [ { "Name": "DimensionKeyActionType", "Value": "ProviderLogDelivery", }, { "Name": "DimensionKeyExceptionType", "Value": "<class 'TypeError'>", }, { "Name": "DimensionKeyResourceType", "Value": "Aa::Bb::Cc" }, ], "Unit": StandardUnit.Count.name, "Timestamp": str(fake_datetime), "Value": 1.0, }], ), ] assert mock_session.mock_calls == expected_calls
def test_publish_exception_metric(mock_session): fake_datetime = datetime(2019, 1, 1) proxy = MetricsPublisherProxy(RESOURCE_TYPE) proxy.add_metrics_publisher(mock_session) proxy.publish_exception_metric(fake_datetime, Action.CREATE, Exception("fake-err")) expected_calls = [ call.client("cloudwatch"), call.client().put_metric_data( Namespace="AWS/CloudFormation/Aa/Bb/Cc", MetricData=[{ "MetricName": MetricTypes.HandlerException.name, "Dimensions": [ { "Name": "DimensionKeyActionType", "Value": "CREATE" }, { "Name": "DimensionKeyExceptionType", "Value": "<class 'Exception'>", }, { "Name": "DimensionKeyResourceType", "Value": "Aa::Bb::Cc" }, ], "Unit": StandardUnit.Count.name, "Timestamp": str(fake_datetime), "Value": 1.0, }], ), ] assert mock_session.mock_calls == expected_calls
def test_metrics_publisher_proxy_add_metrics_publisher_none_safe(): proxy = MetricsPublisherProxy(ACCOUNT_ID, RESOURCE_TYPE) proxy.add_metrics_publisher(None) assert proxy._publishers == [] # pylint: disable=protected-access
def test_metrics_publisher_proxy_add_metrics_publisher_none_safe(): proxy = MetricsPublisherProxy() proxy.add_metrics_publisher(None, None) assert proxy._publishers == [] # pylint: disable=protected-access