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 = OCPQueryParamSerializer(data=query_params, tag_keys=tag_keys) self.assertTrue(serializer.is_valid())
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 = OCPQueryParamSerializer(data=query_params, tag_keys=tag_keys) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_parse_query_params_success(self): """Test parse of a query params successfully.""" query_params = { "group_by": {"project": ["project1"]}, "filter": { "resolution": "daily", "time_scope_value": "-10", "time_scope_units": "day", "resource_scope": [], }, } serializer = OCPQueryParamSerializer(data=query_params) self.assertTrue(serializer.is_valid())
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", "resource_scope": [], }, } serializer = OCPQueryParamSerializer(data=query_params) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_parse_query_params_success(self): """Test parse of a query params successfully.""" query_params = { 'group_by': { 'project': ['project1'] }, 'filter': { 'resolution': 'daily', 'time_scope_value': '-10', 'time_scope_units': 'day', 'resource_scope': [] }, } serializer = OCPQueryParamSerializer(data=query_params) self.assertTrue(serializer.is_valid())
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', 'resource_scope': [] } } serializer = OCPQueryParamSerializer(data=query_params) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_parse_units_failure(self): """Test failure while parsing units query params.""" query_params = {'units': 'bites'} serializer = OCPQueryParamSerializer(data=query_params) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_parse_units(self): """Test pass while parsing units query params.""" query_params = {'units': 'bytes'} serializer = OCPQueryParamSerializer(data=query_params) self.assertTrue(serializer.is_valid())