def test_tag_keys_dynamic_field_validation_failure(self): """Test that invalid tag keys are not valid fields.""" tag_keys = ['valid_tag'] query_params = {'bad_tag': '*'} serializer = GroupBySerializer(data=query_params, tag_keys=tag_keys) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_group_by_params_string_list_fields(self): """Test group_by params for handling string to list fields.""" group_params = {'node': 'localhost'} serializer = GroupBySerializer(data=group_params) validation = serializer.is_valid() self.assertTrue(validation) node_result = serializer.data.get('node') self.assertIsInstance(node_result, list)
def test_all_group_by_op_fields(self): """Test that the allowed fields pass.""" for field in GroupBySerializer._opfields: field = 'and:' + field filter_param = {field: ['1', '2']} serializer = GroupBySerializer(data=filter_param) self.assertTrue(serializer.is_valid()) for field in GroupBySerializer._opfields: field = 'or:' + field filter_param = {field: ['1', '2']} serializer = GroupBySerializer(data=filter_param) self.assertTrue(serializer.is_valid())
def test_tag_keys_dynamic_field_validation_success(self): """Test that tag keys are validated as fields.""" tag_keys = ['valid_tag'] query_params = {'valid_tag': '*'} serializer = GroupBySerializer(data=query_params, tag_keys=tag_keys) self.assertTrue(serializer.is_valid())
def test_group_by_params_invalid_fields(self): """Test parse of group_by params for invalid fields.""" group_params = {'account': ['account1'], 'invalid': 'param'} serializer = GroupBySerializer(data=group_params) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_parse_group_by_params_success(self): """Test parse of a group_by param successfully.""" group_params = {'cluster': ['cluster1']} serializer = GroupBySerializer(data=group_params) self.assertTrue(serializer.is_valid())
def test_group_by_params_invalid_fields(self): """Test parse of group_by params for invalid fields.""" group_params = {"account": ["account1"], "invalid": "param"} serializer = GroupBySerializer(data=group_params) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)