Пример #1
0
    def test_get_tag_keys(self):
        """Test that all OCP-on-AWS tag keys are returned."""
        query_params = {'filter': {'resolution': 'monthly',
                                   'time_scope_value': -2,
                                   'time_scope_units': 'month'},
                        }
        query_string = '?filter[resolution]=monthly&' + \
                       'filter[time_scope_value]=-2&' + \
                       'filter[time_scope_units]=month&'
        handler = OCPAWSTagQueryHandler(
            query_params,
            query_string,
            self.tenant,
            **{}
        )

        with tenant_context(self.tenant):
            tag_keys = OCPAWSCostLineItemDailySummary.objects\
                .annotate(tag_keys=JSONBObjectKeys('tags'))\
                .values('tag_keys')\
                .distinct()\
                .all()
            tag_keys = [tag.get('tag_keys') for tag in tag_keys]

        result = handler.get_tag_keys()
        self.assertEqual(sorted(result), sorted(tag_keys))
Пример #2
0
    def test_no_parameters(self):
        """Test that the execute_query() succeeds with no parameters."""
        handler = OCPAWSTagQueryHandler({}, '', self.tenant, **{})

        query_output = handler.execute_query()
        self.assertIsNotNone(query_output.get('data'))
        self.assertEqual(handler.time_scope_units, 'day')
        self.assertEqual(handler.time_scope_value, -10)
Пример #3
0
 def test_30_day(self):
     """Test that execute_query() succeeds with 30 day parameters."""
     url = "?filter[time_scope_units]=day&filter[time_scope_value]=-30&filter[resolution]=daily"  # noqa: E501
     query_params = self.mocked_query_params(url, OCPAWSTagView)
     handler = OCPAWSTagQueryHandler(query_params)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get("data"))
     self.assertEqual(handler.time_scope_units, "day")
     self.assertEqual(handler.time_scope_value, -30)
Пример #4
0
 def test_10_day_only_keys(self):
     """Test that execute_query() succeeds with 10 day parameters, keys-only."""
     url = '?filter[time_scope_units]=day&filter[time_scope_value]=-10&filter[resolution]=daily&key_only=True'  # noqa: E501
     query_params = self.mocked_query_params(url, OCPAWSTagView)
     handler = OCPAWSTagQueryHandler(query_params)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get('data'))
     self.assertEqual(handler.time_scope_units, 'day')
     self.assertEqual(handler.time_scope_value, -10)
Пример #5
0
 def test_last_month(self):
     """Test that execute_query() succeeds with last-month parameters."""
     url = "?filter[time_scope_units]=month&filter[time_scope_value]=-2&filter[resolution]=monthly"
     query_params = self.mocked_query_params(url, OCPAWSTagView)
     handler = OCPAWSTagQueryHandler(query_params)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get("data"))
     self.assertEqual(handler.time_scope_units, "month")
     self.assertEqual(handler.time_scope_value, -2)
Пример #6
0
 def test_no_parameters(self):
     """Test that the execute_query() succeeds with no parameters."""
     url = "?"
     query_params = self.mocked_query_params(url, OCPAWSTagView)
     handler = OCPAWSTagQueryHandler(query_params)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get("data"))
     self.assertEqual(handler.time_scope_units, "day")
     self.assertEqual(handler.time_scope_value, -10)
Пример #7
0
 def test_specific_account(self):
     """Test that execute_query() succeeds with account parameter."""
     url = f"?filter[time_scope_units]=day&filter[time_scope_value]=-10&filter[resolution]=daily&filter[account]={str(self.fake.ean8())}"  # noqa: E501
     query_params = self.mocked_query_params(url, OCPAWSTagView)
     handler = OCPAWSTagQueryHandler(query_params)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get("data"))
     self.assertEqual(handler.time_scope_units, "day")
     self.assertEqual(handler.time_scope_value, -10)
Пример #8
0
 def test_1_month(self):
     """Test that execute_query() succeeds with 1-month parameters."""
     url = '?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly'
     query_params = self.mocked_query_params(url, OCPAWSTagView)
     handler = OCPAWSTagQueryHandler(query_params)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get('data'))
     self.assertEqual(handler.time_scope_units, 'month')
     self.assertEqual(handler.time_scope_value, -1)
Пример #9
0
    def test_get_tag_keys(self):
        """Test that all OCP-on-AWS tag keys are returned."""
        url = '?filter[time_scope_units]=month&filter[time_scope_value]=-2&filter[resolution]=monthly'
        query_params = self.mocked_query_params(url, OCPAWSTagView)
        handler = OCPAWSTagQueryHandler(query_params)

        with tenant_context(self.tenant):
            tag_keys = (OCPAWSCostLineItemDailySummary.objects.annotate(
                tag_keys=JSONBObjectKeys('tags')).values(
                    'tag_keys').distinct().all())
            tag_keys = [tag.get('tag_keys') for tag in tag_keys]

        result = handler.get_tag_keys()
        self.assertEqual(sorted(result), sorted(tag_keys))
Пример #10
0
 def test_30_day(self):
     """Test that execute_query() succeeds with 30 day parameters."""
     # '?filter[time_scope_units]=day&filter[time_scope_value]=-30&filter[resolution]=daily'
     params = {
         'filter': {
             'resolution': 'daily',
             'time_scope_value': -30,
             'time_scope_units': 'day'
         }
     }
     query_params = FakeQueryParameters(params, tenant=self.tenant)
     handler = OCPAWSTagQueryHandler(query_params.mock_qp)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get('data'))
     self.assertEqual(handler.time_scope_units, 'day')
     self.assertEqual(handler.time_scope_value, -30)
Пример #11
0
 def test_last_month(self):
     """Test that execute_query() succeeds with last-month parameters."""
     # '?filter[time_scope_units]=month&filter[time_scope_value]=-2&filter[resolution]=monthly'
     params = {
         'filter': {
             'resolution': 'monthly',
             'time_scope_value': -2,
             'time_scope_units': 'month'
         }
     }
     query_params = FakeQueryParameters(params, tenant=self.tenant)
     handler = OCPAWSTagQueryHandler(query_params.mock_qp)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get('data'))
     self.assertEqual(handler.time_scope_units, 'month')
     self.assertEqual(handler.time_scope_value, -2)
Пример #12
0
 def test_10_day_only_keys(self):
     """Test that execute_query() succeeds with 10 day parameters, keys-only."""
     # '?filter[time_scope_units]=day&filter[time_scope_value]=-10&filter[resolution]=daily&key_only=True'
     params = {
         'filter': {
             'resolution': 'daily',
             'time_scope_value': -10,
             'time_scope_units': 'day'
         },
         'key_only': True
     }
     query_params = FakeQueryParameters(params, tenant=self.tenant)
     handler = OCPAWSTagQueryHandler(query_params.mock_qp)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get('data'))
     self.assertEqual(handler.time_scope_units, 'day')
     self.assertEqual(handler.time_scope_value, -10)
Пример #13
0
 def test_specific_account(self):
     """Test that execute_query() succeeds with account parameter."""
     # '?filter[time_scope_units]=day&filter[time_scope_value]=-10&filter[resolution]=daily&filter[account]=some_account'
     params = {
         'filter': {
             'resolution': 'daily',
             'time_scope_value': -10,
             'time_scope_units': 'day',
             'account': str(self.fake.ean8())
         }
     }
     query_params = FakeQueryParameters(params, tenant=self.tenant)
     handler = OCPAWSTagQueryHandler(query_params.mock_qp)
     query_output = handler.execute_query()
     self.assertIsNotNone(query_output.get('data'))
     self.assertEqual(handler.time_scope_units, 'day')
     self.assertEqual(handler.time_scope_value, -10)
Пример #14
0
    def test_specific_account(self):
        """Test that execute_query() succeeds with account parameter."""
        account = self.fake.ean8()
        query_params = {'filter': {'account': account},
                        }
        query_string = '?filter[account]={}'.format(account)

        handler = OCPAWSTagQueryHandler(
            query_params,
            query_string,
            self.tenant,
            **{}
        )

        query_output = handler.execute_query()
        self.assertIsNotNone(query_output.get('data'))
        self.assertEqual(handler.time_scope_units, 'day')
        self.assertEqual(handler.time_scope_value, -10)
Пример #15
0
    def test_last_month(self):
        """Test that execute_query() succeeds with last-month parameters."""
        query_params = {'filter': {'resolution': 'monthly',
                                   'time_scope_value': -2,
                                   'time_scope_units': 'month'},
                        }
        query_string = '?filter[resolution]=monthly&' + \
                       'filter[time_scope_value]=-2&' + \
                       'filter[time_scope_units]=month&'
        handler = OCPAWSTagQueryHandler(
            query_params,
            query_string,
            self.tenant,
            **{}
        )

        query_output = handler.execute_query()
        self.assertIsNotNone(query_output.get('data'))
        self.assertEqual(handler.time_scope_units, 'month')
        self.assertEqual(handler.time_scope_value, -2)
Пример #16
0
    def test_30_day(self):
        """Test that execute_query() succeeds with 30 day parameters."""
        query_params = {'filter': {'resolution': 'daily',
                                   'time_scope_value': -30,
                                   'time_scope_units': 'day'},
                        }
        query_string = '?filter[resolution]=daily&' + \
                       'filter[time_scope_value]=-30&' + \
                       'filter[time_scope_units]=day&'
        handler = OCPAWSTagQueryHandler(
            query_params,
            query_string,
            self.tenant,
            **{}
        )

        query_output = handler.execute_query()
        self.assertIsNotNone(query_output.get('data'))
        self.assertEqual(handler.time_scope_units, 'day')
        self.assertEqual(handler.time_scope_value, -30)
Пример #17
0
    def test_10_day_only_keys(self):
        """Test that execute_query() succeeds with 10 day parameters, keys-only."""
        query_params = {'filter': {'resolution': 'daily',
                                   'time_scope_value': -10,
                                   'time_scope_units': 'day',
                                   'key_only': True}
                        }
        query_string = '?filter[resolution]=daily&' + \
                       'filter[time_scope_value]=-10&' + \
                       'filter[time_scope_units]=day&' + \
                       'key_only=True'
        handler = OCPAWSTagQueryHandler(
            query_params,
            query_string,
            self.tenant,
            **{}
        )

        query_output = handler.execute_query()
        self.assertIsNotNone(query_output.get('data'))
        self.assertEqual(handler.time_scope_units, 'day')
        self.assertEqual(handler.time_scope_value, -10)