예제 #1
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 = {"bad_tag": "*"}
     serializer = GroupBySerializer(data=query_params, tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #2
0
 def test_group_by_params_string_list_fields(self):
     """Test group_by params for handling string to list fields."""
     group_params = {"account": "account1"}
     serializer = GroupBySerializer(data=group_params)
     validation = serializer.is_valid()
     self.assertTrue(validation)
     account_result = serializer.data.get("account")
     self.assertIsInstance(account_result, list)
예제 #3
0
 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())
예제 #4
0
 def test_multiple_params(self):
     """Test that multiple group_by parameters works."""
     group_by_params = {"account": "account1", "project": "project1"}
     serializer = GroupBySerializer(data=group_by_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #5
0
 def test_group_by_params_with_and_failure_bad_param(self):
     """Test that and/or does not work on a field it is not allowed on."""
     group_by_params = {"and:resolution": "daily"}
     serializer = GroupBySerializer(data=group_by_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #6
0
 def test_group_by_params_with_and_list_success_single_item(self):
     """Test that the and: prefix is okay with one item."""
     group_by_params = {"and:account": ["account1"]}
     serializer = GroupBySerializer(data=group_by_params)
     self.assertTrue(serializer.is_valid())
예제 #7
0
 def test_group_by_params_with_and_list_success(self):
     """Test that the and: prefix is allowed with a list."""
     group_by_params = {"and:account": ["account1", "account2"]}
     serializer = GroupBySerializer(data=group_by_params)
     self.assertTrue(serializer.is_valid())
예제 #8
0
 def test_group_by_params_with_and_string_success(self):
     """Test that the and: prefix is allowed with a string of items."""
     group_by_params = {"and:account": "account1,account2"}
     serializer = GroupBySerializer(data=group_by_params)
     self.assertTrue(serializer.is_valid())
예제 #9
0
 def test_group_by_params_with_or_list_success_single_item(self):
     """Test that the or: prefix is allowed with a list."""
     group_by_params = {"or:account": ["account1"]}
     serializer = GroupBySerializer(data=group_by_params)
     self.assertTrue(serializer.is_valid())
예제 #10
0
 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())
예제 #11
0
 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)
예제 #12
0
 def test_parse_group_by_params_success(self):
     """Test parse of a group_by param successfully."""
     group_params = {"account": ["account1"]}
     serializer = GroupBySerializer(data=group_params)
     self.assertTrue(serializer.is_valid())
예제 #13
0
 def test_group_by_params_with_or_list_success_multi_item(self):
     """Test that the or: prefix is allowed with a list."""
     group_by_params = {'or:account': ['account1', 'account2']}
     serializer = GroupBySerializer(data=group_by_params)
     self.assertTrue(serializer.is_valid())
예제 #14
0
 def test_group_by_params_with_or_string_success_multi_item(self):
     """Test that the or: prefix is allowed with a string of items."""
     group_by_params = {'or:account': 'account1,account2'}
     serializer = GroupBySerializer(data=group_by_params)
     self.assertTrue(serializer.is_valid())
예제 #15
0
 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)