def test_execute_sum_query_instance_types(self): """Test that the sum query runs properly for instance-types.""" query_params = {} handler = OCPAWSReportQueryHandler( query_params, '', self.tenant, **{'report_type': 'instance_type'} ) query_output = handler.execute_query() self.assertIsNotNone(query_output.get('data')) self.assertIsNotNone(query_output.get('total')) total = query_output.get('total') self.assertIsNotNone(total.get('cost')) self.assertIsInstance(total.get('cost'), dict) self.assertEqual(total.get('cost').get('value'), 0) self.assertEqual(total.get('cost').get('units'), 'USD') self.assertIsNotNone(total.get('usage')) self.assertIsInstance(total.get('usage'), dict) self.assertEqual(total.get('usage').get('value'), 0) self.assertEqual(total.get('usage').get('units'), 'Hrs') self.assertIsNotNone(total.get('count')) self.assertIsInstance(total.get('count'), dict) self.assertEqual(total.get('count').get('value'), 0) self.assertEqual(total.get('count').get('units'), 'instances')
def test_execute_query_by_account_by_service(self): """Test execute_query for current month breakdown by account by service.""" query_params = {'filter': {'resolution': 'monthly', 'time_scope_value': -1, 'time_scope_units': 'month'}, 'group_by': {'account': ['*'], 'service': ['*']}} query_string = '?group_by[account]=*&group_by[service]=*' handler = OCPAWSReportQueryHandler(query_params, query_string, self.tenant, **{'report_type': 'costs'}) query_output = handler.execute_query() data = query_output.get('data') self.assertIsNotNone(data) self.assertIsNotNone(query_output.get('total')) total = query_output.get('total') self.assertIsNotNone(total.get('cost')) aggregates = handler._mapper.report_type_map.get('aggregates') current_totals = self.get_totals_by_time_scope(aggregates, self.this_month_filter) self.assertEqual(total.get('cost', {}).get('value'), current_totals.get('cost')) cmonth_str = DateHelper().this_month_start.strftime('%Y-%m') for data_item in data: month_val = data_item.get('date') month_data = data_item.get('accounts') self.assertEqual(month_val, cmonth_str) self.assertIsInstance(month_data, list) for month_item in month_data: self.assertIsInstance(month_item.get('services'), list)
def test_query_by_partial_filtered_service(self): """Test execute_query monthly breakdown by filtered service.""" query_params = {'filter': {'resolution': 'monthly', 'time_scope_value': -1, 'time_scope_units': 'month'}, 'group_by': {'service': ['eC2']}} handler = OCPAWSReportQueryHandler(query_params, '?group_by[service]=eC2', self.tenant, **{'report_type': 'costs'}) query_output = handler.execute_query() data = query_output.get('data') self.assertIsNotNone(data) self.assertIsNotNone(query_output.get('total')) total = query_output.get('total') self.assertIsNotNone(total.get('cost')) aggregates = handler._mapper.report_type_map.get('aggregates') current_totals = self.get_totals_by_time_scope(aggregates, self.this_month_filter) self.assertEqual(total.get('cost', {}).get('value'), current_totals.get('cost')) cmonth_str = DateHelper().this_month_start.strftime('%Y-%m') for data_item in data: month_val = data_item.get('date') month_data = data_item.get('services') self.assertEqual(month_val, cmonth_str) self.assertIsInstance(month_data, list) for month_item in month_data: compute = month_item.get('service') self.assertEqual(compute, 'AmazonEC2') self.assertIsInstance(month_item.get('values'), list)
def test_execute_sum_query_storage(self): """Test that the sum query runs properly.""" handler = OCPAWSReportQueryHandler({}, '', self.tenant, report_type='storage') filt = {'product_family__contains': 'Storage'} filt.update(self.one_day_filter) aggregates = handler._mapper.report_type_map.get('aggregates') current_totals = self.get_totals_by_time_scope(aggregates, filt) query_output = handler.execute_query() self.assertIsNotNone(query_output.get('data')) self.assertIsNotNone(query_output.get('total')) total = query_output.get('total') self.assertEqual(total.get('total'), current_totals.get('total'))
def test_execute_query_current_month_monthly(self): """Test execute_query for current month on monthly breakdown.""" query_params = {'filter': {'resolution': 'monthly', 'time_scope_value': -1, 'time_scope_units': 'month'}} handler = OCPAWSReportQueryHandler(query_params, '', self.tenant, **{'report_type': 'costs'}) query_output = handler.execute_query() self.assertIsNotNone(query_output.get('data')) self.assertIsNotNone(query_output.get('total')) total = query_output.get('total') self.assertIsNotNone(total.get('cost')) aggregates = handler._mapper.report_type_map.get('aggregates') current_totals = self.get_totals_by_time_scope(aggregates, self.this_month_filter) self.assertEqual(total.get('cost', {}).get('value'), current_totals.get('cost'))