示例#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 = {"valid_tag": "*"}
     serializer = OCPGCPGroupBySerializer(data=query_params,
                                          tag_keys=tag_keys)
     self.assertTrue(serializer.is_valid())
示例#2
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 = OCPGCPGroupBySerializer(data=query_params,
                                          tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
示例#3
0
 def test_group_by_params_string_list_fields(self):
     """Test group_by params for handling string to list fields."""
     group_params = {"instance_type": FAKE.word()}
     serializer = OCPGCPGroupBySerializer(data=group_params)
     validation = serializer.is_valid()
     self.assertTrue(validation)
     result = serializer.data.get("instance_type")
     self.assertIsInstance(result, list)
示例#4
0
 def test_all_group_by_op_fields(self):
     """Test that the allowed fields pass."""
     for field in OCPGCPGroupBySerializer._opfields:
         field = "and:" + field
         filter_param = {field: ["1", "2"]}
         serializer = OCPGCPGroupBySerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
     for field in OCPGCPGroupBySerializer._opfields:
         field = "or:" + field
         filter_param = {field: ["1", "2"]}
         serializer = OCPGCPGroupBySerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
示例#5
0
 def test_group_by_node(self):
     """Test group by node."""
     group_params = {"node": ["*"]}
     serializer = OCPGCPGroupBySerializer(data=group_params)
     self.assertTrue(serializer.is_valid())
示例#6
0
 def test_group_by_cluster(self):
     """Test group by cluster."""
     group_params = {"cluster": ["*"]}
     serializer = OCPGCPGroupBySerializer(data=group_params)
     self.assertTrue(serializer.is_valid())
示例#7
0
 def test_parse_group_by_project(self):
     """Test group by project."""
     group_params = {"project": ["*"]}
     serializer = OCPGCPGroupBySerializer(data=group_params)
     self.assertTrue(serializer.is_valid())
示例#8
0
 def test_group_by_params_invalid_fields(self):
     """Test parse of group_by params for invalid fields."""
     group_params = {"account": [FAKE.word()], "invalid": "param"}
     serializer = OCPGCPGroupBySerializer(data=group_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
示例#9
0
 def test_parse_group_by_params_success(self):
     """Test parse of a group_by param successfully."""
     group_params = {"region": [FAKE.uuid4()]}
     serializer = OCPGCPGroupBySerializer(data=group_params)
     self.assertTrue(serializer.is_valid())