예제 #1
0
 def test_tag_keys_dynamic_field_validation_success(self):
     """Test that tag keys are validated as fields."""
     tag_keys = ['valid_tag']
     query_params = {'filter': {'valid_tag': 'value'}}
     serializer = OCPAzureQueryParamSerializer(data=query_params,
                                               tag_keys=tag_keys)
     self.assertTrue(serializer.is_valid())
예제 #2
0
 def test_invalid_delta_usage(self):
     """Test failure while handling invalid delta for usage requests."""
     query_params = {"delta": "usage"}
     req = Mock(path="/api/cost-management/v1/reports/azure/costs/")
     serializer = OCPAzureQueryParamSerializer(data=query_params, context={"request": req})
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #3
0
 def test_valid_delta_usage(self):
     """Test successful handling of valid delta for usage requests."""
     query_params = {'delta': 'usage'}
     req = Mock(path='/api/cost-management/v1/reports/azure/storage/')
     serializer = OCPAzureQueryParamSerializer(data=query_params,
                                               context={'request': req})
     self.assertTrue(serializer.is_valid())
예제 #4
0
 def test_tag_keys_dynamic_field_validation_failure(self):
     """Test that invalid tag keys are not valid fields."""
     tag_keys = ["valid_tag"]
     query_params = {"filter": {"bad_tag": "value"}}
     serializer = OCPAzureQueryParamSerializer(data=query_params, tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #5
0
 def test_valid_delta_costs(self):
     """Test successful handling of valid delta for cost requests."""
     query_params = {"delta": "cost"}
     req = Mock(path="/api/cost-management/v1/reports/azure/costs/")
     serializer = OCPAzureQueryParamSerializer(data=query_params,
                                               context={"request": req})
     self.assertTrue(serializer.is_valid())
예제 #6
0
 def test_invalid_delta_costs(self):
     """Test failure while handling invalid delta for cost requests."""
     query_params = {'delta': 'cost'}
     req = Mock(path='/api/cost-management/v1/reports/azure/storage/')
     serializer = OCPAzureQueryParamSerializer(data=query_params,
                                               context={'request': req})
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #7
0
 def test_order_by_service_with_groupby(self):
     """Test that order_by[service_name] works with a matching group-by."""
     query_params = {
         'group_by': {
             'service_name': 'asc'
         },
         'order_by': {
             'service_name': 'asc'
         },
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #8
0
 def test_order_by_service_with_groupby(self):
     """Test that order_by[service_name] works with a matching group-by."""
     query_params = {
         "group_by": {
             "service_name": "asc"
         },
         "order_by": {
             "service_name": "asc"
         }
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #9
0
 def test_query_params_invalid_order_by_usage(self):
     """Test parse of charge query params for invalid fields."""
     # Charge can't order by request or usage
     query_params = {
         "group_by": {"subscription_guid": [FAKE.uuid4()]},
         "order_by": {"usage": "asc"},
         "filter": {"resolution": "daily", "time_scope_value": "-10", "time_scope_units": "day"},
         "invalid": "param",
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #10
0
 def test_parse_query_azure_params_success(self):
     """Test parse of a query params successfully."""
     query_params = {
         "group_by": {"instance_type": [FAKE.word()]},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "subscription_guid": [FAKE.uuid4()],
         },
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #11
0
 def test_query_params_invalid_nested_fields(self):
     """Test parse of query params for invalid nested_fields."""
     query_params = {
         "group_by": {"invalid": ["invalid"]},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "subscription_guid": [FAKE.uuid4()],
         },
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #12
0
 def test_parse_query_azure_params_success(self):
     """Test parse of a query params successfully."""
     query_params = {
         'group_by': {
             'instance_type': [FAKE.word()]
         },
         'filter': {
             'resolution': 'daily',
             'time_scope_value': '-10',
             'time_scope_units': 'day',
             'subscription_guid': [FAKE.uuid4()],
         },
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #13
0
 def test_query_params_invalid_fields(self):
     """Test parse of query params for invalid fields."""
     query_params = {
         "group_by": {"instance_type": [FAKE.word()]},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_location": [FAKE.word()],
         },
         "invalid": "param",
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #14
0
 def test_parse_query_ocp_params_success(self):
     """Test parse of a query params successfully."""
     query_params = {
         "group_by": {"project": ["account1"]},
         "order_by": {"project": "asc"},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_scope": [],
         },
         "units": "byte",
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #15
0
 def test_query_params_invalid_nested_fields(self):
     """Test parse of query params for invalid nested_fields."""
     query_params = {
         'group_by': {
             'invalid': ['invalid']
         },
         'filter': {
             'resolution': 'daily',
             'time_scope_value': '-10',
             'time_scope_units': 'day',
             'subscription_guid': [FAKE.uuid4()],
         },
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #16
0
 def test_query_params_invalid_fields(self):
     """Test parse of query params for invalid fields."""
     query_params = {
         'group_by': {
             'instance_type': [FAKE.word()]
         },
         'filter': {
             'resolution': 'daily',
             'time_scope_value': '-10',
             'time_scope_units': 'day',
             'resource_location': [FAKE.word()],
         },
         'invalid': 'param',
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #17
0
 def test_parse_query_ocp_params_success(self):
     """Test parse of a query params successfully."""
     query_params = {
         'group_by': {
             'project': ['account1']
         },
         'order_by': {
             'project': 'asc'
         },
         'filter': {
             'resolution': 'daily',
             'time_scope_value': '-10',
             'time_scope_units': 'day',
             'resource_scope': []
         },
         'units': 'byte'
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #18
0
 def test_query_params_invalid_order_by_usage(self):
     """Test parse of charge query params for invalid fields."""
     # Charge can't order by request or usage
     query_params = {
         'group_by': {
             'subscription_guid': [FAKE.uuid4()]
         },
         'order_by': {
             'usage': 'asc'
         },
         'filter': {
             'resolution': 'daily',
             'time_scope_value': '-10',
             'time_scope_units': 'day',
         },
         'invalid': 'param',
     }
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #19
0
 def test_parse_units(self):
     """Test pass while parsing units query params."""
     query_params = {'units': 'bytes'}
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #20
0
 def test_order_by_service_without_groupby(self):
     """Test that order_by[service_name] fails without a matching group-by."""
     query_params = {'order_by': {'service_name': 'asc'}}
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #21
0
 def test_parse_units_failure(self):
     """Test failure while parsing units query params."""
     query_params = {'units': 'bites'}
     serializer = OCPAzureQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)