Exemple #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': 'value'}
     serializer = FilterSerializer(data=query_params, tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Exemple #2
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 = FilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Exemple #3
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_scope': []
     }
     serializer = FilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
 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_scope": [],
     }
     serializer = FilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
Exemple #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 = FilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Exemple #6
0
 def test_filter_params_invalid_fields(self):
     """Test parse of filter params for invalid fields."""
     filter_params = {
         'resolution': 'daily',
         'time_scope_value': '-10',
         'time_scope_units': 'day',
         'resource_scope': [],
         'invalid': 'param'
     }
     serializer = FilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
 def test_filter_params_invalid_fields(self):
     """Test parse of filter params for invalid fields."""
     filter_params = {
         "resolution": "daily",
         "time_scope_value": "-10",
         "time_scope_units": "day",
         "resource_scope": [],
         "invalid": "param",
     }
     serializer = FilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Exemple #8
0
 def test_all_filter_op_fields(self):
     """Test that the allowed fields pass."""
     for field in FilterSerializer._opfields:
         field = 'and:' + field
         filter_param = {field: ['1', '2']}
         serializer = FilterSerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
     for field in FilterSerializer._opfields:
         field = 'or:' + field
         filter_param = {field: ['1', '2']}
         serializer = FilterSerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
Exemple #9
0
 def test_parse_filter_params_no_time(self):
     """Test parse of a filter param no time filter."""
     filter_params = {'resource_scope': ['S3']}
     serializer = FilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
Exemple #10
0
 def test_infrastructure_field_validation_failure(self):
     """Test that infrastructure filter are validated for non-aws."""
     query_params = {'infrastructures': 'notaws'}
     serializer = FilterSerializer(data=query_params)
     self.assertFalse(serializer.is_valid())
Exemple #11
0
 def test_infrastructure_field_validation_success(self):
     """Test that infrastructure filter are validated for aws."""
     query_params = {'infrastructures': 'aws'}
     serializer = FilterSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
Exemple #12
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 = FilterSerializer(data=query_params, tag_keys=tag_keys)
     self.assertTrue(serializer.is_valid())