def test_get_cloudwatch_metric_data_points_none(): region = 'us-east-1' metrics_helper = MetricsHelper(region) client_stubber = Stubber(metrics_helper.client) workspace_id = '123qwer' list_time_ranges = [{ 'end_time': '2021-05-06T00:00:00Z', 'start_time': '2021-05-01T00:00:00Z' }] client_stubber.add_client_error('get_metric_statistics', 'InvalidRequest') client_stubber.activate() result = metrics_helper.get_cloudwatch_metric_data_points( workspace_id, list_time_ranges, "UserConnected") assert result is None
def test_get_cloudwatch_metric_data_points(): region = 'us-east-1' metrics_helper = MetricsHelper(region) client_stubber = Stubber(metrics_helper.client) workspace_id = '123qwer' start_time = '2021-05-01T00:00:00Z' end_time = '2021-05-06T00:00:00Z' list_time_ranges = [{ 'end_time': '2021-05-06T00:00:00Z', 'start_time': '2021-05-01T00:00:00Z' }] response = { 'Label': 'UserConnected', 'Datapoints': [{ 'Timestamp': datetime.datetime(2021, 5, 2, 11, 0, tzinfo=tzutc()), 'Maximum': 1.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 1, 7, 0, tzinfo=tzutc()), 'Maximum': 1.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 2, 6, 0, tzinfo=tzutc()), 'Maximum': 1.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 1, 2, 0, tzinfo=tzutc()), 'Maximum': 0.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 2, 1, 0, tzinfo=tzutc()), 'Maximum': 0.0, 'Unit': 'Count' }] } expected_params = { 'Dimensions': [{ 'Name': 'WorkspaceId', 'Value': workspace_id }], 'Namespace': 'AWS/WorkSpaces', 'MetricName': 'UserConnected', 'StartTime': start_time, 'EndTime': end_time, 'Period': 300, 'Statistics': ['Maximum'] } client_stubber.add_response('get_metric_statistics', response, expected_params) client_stubber.activate() result = metrics_helper.get_cloudwatch_metric_data_points( workspace_id, list_time_ranges, "UserConnected") assert result == [{ 'Timestamp': datetime.datetime(2021, 5, 2, 11, 0, tzinfo=tzutc()), 'Maximum': 1.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 1, 7, 0, tzinfo=tzutc()), 'Maximum': 1.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 2, 6, 0, tzinfo=tzutc()), 'Maximum': 1.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 1, 2, 0, tzinfo=tzutc()), 'Maximum': 0.0, 'Unit': 'Count' }, { 'Timestamp': datetime.datetime(2021, 5, 2, 1, 0, tzinfo=tzutc()), 'Maximum': 0.0, 'Unit': 'Count' }]