Ejemplo n.º 1
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 = AzureGroupBySerializer(data=group_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Ejemplo n.º 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 = AzureGroupBySerializer(data=query_params,
                                         tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Ejemplo n.º 3
0
 def test_all_group_by_op_fields(self):
     """Test that the allowed fields pass."""
     for field in AzureGroupBySerializer._opfields:
         field = "and:" + field
         filter_param = {field: ["1", "2"]}
         serializer = AzureGroupBySerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
     for field in AzureGroupBySerializer._opfields:
         field = "or:" + field
         filter_param = {field: ["1", "2"]}
         serializer = AzureGroupBySerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
Ejemplo n.º 4
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 = AzureGroupBySerializer(data=query_params,
                                         tag_keys=tag_keys)
     self.assertTrue(serializer.is_valid())
Ejemplo n.º 5
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 = AzureGroupBySerializer(data=group_params)
     validation = serializer.is_valid()
     self.assertTrue(validation)
     result = serializer.data.get("instance_type")
     self.assertIsInstance(result, list)
Ejemplo n.º 6
0
 def test_parse_group_by_params_success(self):
     """Test parse of a group_by param successfully."""
     group_params = {"subscription_guid": [FAKE.uuid4()]}
     serializer = AzureGroupBySerializer(data=group_params)
     self.assertTrue(serializer.is_valid())