Exemplo n.º 1
0
    def test_execute_query_current_month_monthly(self):
        """Test execute_query for current month on monthly breakdown."""
        url = '?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=daily'
        query_params = self.mocked_query_params(url, OCPAWSCostView)
        handler = OCPAWSReportQueryHandler(query_params)
        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', 0),
            current_totals.get('cost', 1))
Exemplo n.º 2
0
    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'))
Exemplo n.º 3
0
    def test_execute_sum_query_storage(self):
        """Test that the sum query runs properly."""
        query_params = {}
        handler = OCPAWSReportQueryHandler(
            query_params,
            '',
            self.tenant,
            **{'report_type': 'storage'}
        )

        filt = {'product_family__contains': 'Storage'}
        filt.update(self.ten_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'))
Exemplo n.º 4
0
 def test_execute_sum_query_instance_types(self):
     """Test that the sum query runs properly for instance-types."""
     url = '?'
     query_params = self.mocked_query_params(url, OCPAWSInstanceTypeView)
     handler = OCPAWSReportQueryHandler(query_params)
     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')
Exemplo n.º 5
0
 def test_execute_sum_query_instance_types(self):
     """Test that the sum query runs properly for instance-types."""
     url = "?"
     query_params = self.mocked_query_params(url, OCPAWSInstanceTypeView)
     handler = OCPAWSReportQueryHandler(query_params)
     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_query_by_partial_filtered_service(self):
        """Test execute_query monthly breakdown by filtered service."""
        # '?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[service]=eC2'
        params = {
            'filter': {
                'resolution': 'monthly',
                'time_scope_value': -1,
                'time_scope_units': 'month'
            },
            'group_by': {
                'service': ['eC2']
            }
        }
        query_params = FakeQueryParameters(params, tenant=self.tenant)
        handler = OCPAWSReportQueryHandler(query_params.mock_qp)
        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_instance_types(self):
     """Test that the sum query runs properly for instance-types."""
     # '?'
     query_params = FakeQueryParameters({},
                                        report_type='instance_type',
                                        tenant=self.tenant)
     handler = OCPAWSReportQueryHandler(query_params.mock_qp)
     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_current_month_monthly(self):
        """Test execute_query for current month on monthly breakdown."""
        # '?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=daily'
        params = {
            'filter': {
                'resolution': 'daily',
                'time_scope_value': -1,
                'time_scope_units': 'month'
            }
        }
        query_params = FakeQueryParameters(params, tenant=self.tenant)
        handler = OCPAWSReportQueryHandler(query_params.mock_qp)
        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'))
Exemplo n.º 9
0
    def test_execute_query_by_account_by_service(self):
        """Test execute_query for current month breakdown by account by service."""
        url = "?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[account]=*&group_by[service]=*"  # noqa: E501
        query_params = self.mocked_query_params(url, OCPAWSCostView)
        handler = OCPAWSReportQueryHandler(query_params)
        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("total", {}).get("value", 0), current_totals.get("cost_total", 1))

        cmonth_str = DateHelper().this_month_start.strftime("%Y-%m")
        for data_item in data:
            month_val = data_item.get("date", "not-a-date")
            month_data = data_item.get("accounts", "not-a-string")
            self.assertEqual(month_val, cmonth_str)
            self.assertIsInstance(month_data, list)
            for month_item in month_data:
                self.assertIsInstance(month_item.get("services"), list)