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