def test_execute_query_for_project(self): """Test that the execute query runs properly with project query.""" subscription_guid = None with tenant_context(self.tenant): obj = AzureCostEntryLineItemDailySummary.objects\ .values('subscription_guid')\ .first() subscription_guid = obj.get('subscription_guid') query_params = { 'filter': { 'resolution': 'daily', 'time_scope_value': -10, 'time_scope_units': 'day', 'subscription_guid': subscription_guid }, } query_string = '?filter[resolution]=daily&' + \ 'filter[time_scope_value]=-10&' + \ 'filter[time_scope_units]=day&' + \ 'filter[project]={}'.format(subscription_guid) handler = AzureTagQueryHandler(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)
def test_execute_query_two_month_parameters(self): """Test that the execute query runs properly with two month query.""" url = "?filter[time_scope_units]=month&filter[time_scope_value]=-2&filter[resolution]=monthly" query_params = self.mocked_query_params(url, AzureTagView) handler = AzureTagQueryHandler(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)
def test_execute_query_10_day_parameters_only_keys(self): """Test that the execute query runs properly with 10 day query.""" url = "?filter[time_scope_units]=day&filter[time_scope_value]=-10&filter[resolution]=daily&key_only=True" query_params = self.mocked_query_params(url, AzureTagView) handler = AzureTagQueryHandler(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)
def test_execute_query_no_query_parameters(self): """Test that the execute query runs properly with no query.""" url = "?" query_params = self.mocked_query_params(url, AzureTagView) handler = AzureTagQueryHandler(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)
def test_execute_query_month_parameters(self): """Test that the execute query runs properly with single month query.""" url = '?filter[resolution]=monthly&filter[time_scope_value]=-1&filter[time_scope_units]=month' query_params = self.mocked_query_params(url, AzureTagView) handler = AzureTagQueryHandler(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)
def test_execute_query_30_day_parameters(self): """Test that the execute query runs properly with 30 day query.""" url = '?filter[time_scope_units]=day&filter[time_scope_value]=-30&filter[resolution]=daily' query_params = self.mocked_query_params(url, AzureTagView) handler = AzureTagQueryHandler(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)
def test_execute_query_no_query_parameters(self): """Test that the execute query runs properly with no query.""" query_params = {} handler = AzureTagQueryHandler(query_params, '', 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)
def test_execute_query_no_query_parameters(self): """Test that the execute query runs properly with no query.""" # '? handler = AzureTagQueryHandler( FakeQueryParameters({}, tenant=self.tenant).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)
def test_execute_query_for_project(self): """Test that the execute query runs properly with project query.""" subscription_guid = None with tenant_context(self.tenant): obj = AzureCostEntryLineItemDailySummary.objects.values("subscription_guid").first() subscription_guid = obj.get("subscription_guid") url = f"?filter[time_scope_units]=day&filter[time_scope_value]=-10&filter[resolution]=daily&filter[subscription_guid]={subscription_guid}" # noqa: E501 query_params = self.mocked_query_params(url, AzureTagView) handler = AzureTagQueryHandler(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)
def test_execute_query_month_parameters(self): """Test that the execute query runs properly with single month query.""" params = { 'filter': { 'resolution': 'monthly', 'time_scope_value': -1, 'time_scope_units': 'month' } } query_params = FakeQueryParameters(params, tenant=self.tenant) handler = AzureTagQueryHandler(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, -1)
def test_execute_query_30_day_parameters(self): """Test that the execute query runs properly with 30 day query.""" # '?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 = AzureTagQueryHandler(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)
def test_execute_query_30_day_parameters(self): """Test that the execute query runs properly with 30 day query.""" 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 = AzureTagQueryHandler(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)
def test_execute_query_two_month_parameters(self): """Test that the execute query runs properly with two month query.""" 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 = AzureTagQueryHandler(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)
def test_execute_query_for_project(self): """Test that the execute query runs properly with project query.""" subscription_guid = None with tenant_context(self.tenant): obj = AzureCostEntryLineItemDailySummary.objects\ .values('subscription_guid')\ .first() subscription_guid = obj.get('subscription_guid') # '?filter[time_scope_units]=day&filter[time_scope_value]=-10&filter[resolution]=daily&filter[subscription_guid]=some_uuid' params = { 'filter': { 'resolution': 'daily', 'time_scope_value': -10, 'time_scope_units': 'day', 'subscription_guid': subscription_guid } } query_params = FakeQueryParameters(params, tenant=self.tenant) handler = AzureTagQueryHandler(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)