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 = OCPGCPFilterSerializer(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": "value"}
     serializer = OCPGCPFilterSerializer(data=query_params,
                                         tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
 def test_parse_filter_params_no_time(self):
     """Test parse of a filter param no time filter."""
     filter_params = {
         "account": FAKE.word(),
         "region": FAKE.uuid4(),
         "instance_type": FAKE.word()
     }
     serializer = OCPGCPFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
 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 = OCPGCPFilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
 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",
         "account": FAKE.word(),
         "region": FAKE.uuid4(),
         "instance_type": FAKE.word(),
         "service": FAKE.word(),
     }
     serializer = OCPGCPFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
 def test_all_filter_op_fields(self):
     """Test that the allowed fields pass."""
     for field in OCPGCPFilterSerializer._opfields:
         field = "and:" + field
         filter_param = {field: ["1", "2"]}
         serializer = OCPGCPFilterSerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
     for field in OCPGCPFilterSerializer._opfields:
         field = "or:" + field
         filter_param = {field: ["1", "2"]}
         serializer = OCPGCPFilterSerializer(data=filter_param)
         self.assertTrue(serializer.is_valid())
 def test_filter_params_invalid_fields(self):
     """Test parse of filter params for invalid fields."""
     filter_params = {"invalid": "param"}
     serializer = OCPGCPFilterSerializer(data=filter_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
 def test_parse_filter_node(self):
     """Test filter by node."""
     filter_params = {"node": ["*"]}
     serializer = OCPGCPFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
 def test_parse_filter_cluster(self):
     """Test filter by cluster."""
     filter_params = {"cluster": ["*"]}
     serializer = OCPGCPFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())
Exemple #10
0
 def test_parse_filter_project(self):
     """Test filter by project."""
     filter_params = {"project": ["*"]}
     serializer = OCPGCPFilterSerializer(data=filter_params)
     self.assertTrue(serializer.is_valid())