Beispiel #1
0
 def test_query_params_valid_cost_delta(self):
     """Test parse of delta charge query params for valid fields."""
     query_params = {
         "group_by": {
             "account": ["account1"]
         },
         "order_by": {
             "usage": "asc"
         },
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_scope": [],
         },
         "delta": "cost",
     }
     req = Mock(
         path=
         "/api/cost-management/v1/reports/openshift/infrastructures/all/costs/"
     )
     serializer = OCPAllQueryParamSerializer(data=query_params,
                                             context={"request": req})
     serializer.is_valid(raise_exception=True)
     query_params["delta"] = "cost_total"
     req = Mock(
         path=
         "/api/cost-management/v1/reports/openshift/infrastructures/all/costs/"
     )
     serializer = OCPAllQueryParamSerializer(data=query_params,
                                             context={"request": req})
     serializer.is_valid(raise_exception=True)
Beispiel #2
0
 def test_query_params_valid_cost_delta(self):
     """Test parse of delta charge query params for valid fields."""
     query_params = {
         "group_by": {
             "account": ["account1"]
         },
         "order_by": {
             "usage": "asc"
         },
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_scope": [],
         },
         "delta": "cost",
     }
     context = self._create_request_context(
         {
             "account_id": "10001",
             "schema_name": self.schema_name
         },
         self._create_user_data(),
         create_tenant=True,
         path=
         "/api/cost-management/v1/reports/openshift/infrastructures/all/costs/",
     )
     serializer = OCPAllQueryParamSerializer(data=query_params,
                                             context=context)
     serializer.is_valid(raise_exception=True)
     query_params["delta"] = "cost_total"
     serializer = OCPAllQueryParamSerializer(data=query_params,
                                             context=context)
     serializer.is_valid(raise_exception=True)
Beispiel #3
0
 def test_parse_query_params_success(self):
     """Test parse of a query params successfully."""
     query_params = {
         "group_by": {
             "project": ["account1"]
         },
         "order_by": {
             "project": "asc"
         },
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_scope": [],
         },
         "units": "byte",
     }
     serializer = OCPAllQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
Beispiel #4
0
 def test_query_params_valid_delta(self):
     """Test parse of delta charge query params for valid fields."""
     # Charge can't order by request or usage
     query_params = {
         "group_by": {
             "account": ["account1"]
         },
         "order_by": {
             "usage": "asc"
         },
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_scope": [],
         },
         "delta": "usage",
     }
     serializer = OCPAllQueryParamSerializer(data=query_params)
     serializer.is_valid(raise_exception=True)
Beispiel #5
0
 def test_query_params_invalid_cost_type(self):
     """Test parse of invalid cost_type param."""
     query_params = {"cost_type": "invalid_cost"}
     serializer = OCPAllQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
Beispiel #6
0
 def test_query_params_valid_cost_type(self):
     """Test parse of valid cost_type param."""
     query_params = {"cost_type": "blended_cost"}
     serializer = OCPAllQueryParamSerializer(
         data=query_params, context=self.alt_request_context)
     serializer.is_valid(raise_exception=True)