Exemplo n.º 1
0
 def test_all_filter_op_fields(self):
     """Test that the allowed fields pass."""
     for field in AzureFilterSerializer._opfields:
         field = "and:" + field
         filter_param = {field: ["1", "2"]}
         serializer = AzureFilterSerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
     for field in AzureFilterSerializer._opfields:
         field = "or:" + field
         filter_param = {field: ["1", "2"]}
         serializer = AzureFilterSerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
Exemplo n.º 2
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": "value"}
     serializer = AzureFilterSerializer(data=query_params,
                                        tag_keys=tag_keys)
     self.assertTrue(serializer.is_valid())
Exemplo n.º 3
0
 def test_parse_filter_params_no_time(self):
     """Test parse of a filter param no time filter."""
     filter_params = {'resource_location': FAKE.word(),
                      'subscription_guid': FAKE.uuid4(),
                      'instance_type': FAKE.word()}
     serializer = AzureFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
Exemplo n.º 4
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": "value"}
     serializer = AzureFilterSerializer(data=query_params,
                                        tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Exemplo n.º 5
0
 def test_filter_params_invalid_limit_time_scope_resolution(self):
     """Test parse of filter params for invalid resolution time_scope_units."""
     filter_params = {'resolution': 'monthly',
                      'time_scope_value': '-10',
                      'time_scope_units': 'day'}
     serializer = AzureFilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Exemplo n.º 6
0
 def test_filter_params_invalid_limit_time_scope_resolution(self):
     """Test parse of filter params for invalid resolution time_scope_units."""
     filter_params = {
         "resolution": "monthly",
         "time_scope_value": "-10",
         "time_scope_units": "day"
     }
     serializer = AzureFilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Exemplo n.º 7
0
 def test_parse_filter_params_success(self):
     """Test parse of a filter param successfully."""
     filter_params = {'resolution': 'daily',
                      'time_scope_value': '-10',
                      'time_scope_units': 'day',
                      'resource_location': FAKE.word(),
                      'subscription_guid': FAKE.uuid4(),
                      'instance_type': FAKE.word(),
                      'service_name': FAKE.word()}
     serializer = AzureFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
Exemplo n.º 8
0
 def test_parse_filter_params_success(self):
     """Test parse of a filter param successfully."""
     filter_params = {
         "resolution": "daily",
         "time_scope_value": "-10",
         "time_scope_units": "day",
         "resource_location": FAKE.word(),
         "subscription_guid": FAKE.uuid4(),
         "instance_type": FAKE.word(),
         "service_name": FAKE.word(),
     }
     serializer = AzureFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
Exemplo n.º 9
0
 def test_filter_params_invalid_fields(self):
     """Test parse of filter params for invalid fields."""
     filter_params = {"invalid": "param"}
     serializer = AzureFilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)