コード例 #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 = {"filter": {"bad_tag": "value"}}
     serializer = GCPQueryParamSerializer(data=query_params, tag_keys=tag_keys)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
コード例 #2
0
 def test_query_params_invalid_nested_fields(self):
     """Test parse of query params for invalid nested_fields."""
     query_params = {
         "group_by": {"invalid": ["invalid"]},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "subscription_guid": [FAKE.uuid4()],
         },
     }
     serializer = GCPQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
コード例 #3
0
 def test_query_params_invalid_fields(self):
     """Test parse of query params for invalid fields."""
     query_params = {
         "group_by": {"account": [FAKE.word()]},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_location": [FAKE.word()],
         },
         "invalid": "param",
     }
     serializer = GCPQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
コード例 #4
0
 def test_valid_deltas(self):
     """Test successful handling of valid delta for cost requests."""
     valid_delta_map = {
         "/api/cost-management/v1/reports/gcp/costs/": ["cost", "cost_total"],
         "/api/cost-management/v1/reports/gcp/instance-types/": ["usage"],
         "/api/cost-management/v1/reports/gcp/storage/": ["usage"],
     }
     for url, delta_list in valid_delta_map.items():
         req = Mock(path=url)
         for valid_delta in delta_list:
             query_params = {"delta": valid_delta}
             serializer = GCPQueryParamSerializer(data=query_params, context={"request": req})
             self.assertTrue(serializer.is_valid())
コード例 #5
0
 def test_parse_query_params_success(self):
     """Test parse of a query params successfully."""
     query_params = {
         "group_by": {"project": [FAKE.word()]},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "account": [FAKE.uuid4()],
         },
     }
     serializer = GCPQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())