예제 #1
0
 def test_order_by_delta_with_delta(self):
     """Test that order_by[delta] works with a delta param."""
     query_params = {
         "delta": "usage__request",
         "order_by": {
             "delta": "asc"
         }
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #2
0
 def test_order_by_delta_with_delta(self):
     """Test that order_by[delta] works with a delta param."""
     query_params = {
         'delta': 'usage__request',
         'order_by': {
             'delta': 'asc'
         }
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #3
0
 def test_order_by_node_with_groupby(self):
     """Test that order_by[node] works with a matching group-by."""
     query_params = {
         'group_by': {
             'node': 'asc'
         },
         'order_by': {
             'node': 'asc'
         }
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #4
0
 def test_order_by_node_with_groupby(self):
     """Test that order_by[node] works with a matching group-by."""
     query_params = {
         "group_by": {
             "node": "asc"
         },
         "order_by": {
             "node": "asc"
         }
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #5
0
 def test_parse_query_params_success(self):
     """Test parse of an inventory query params successfully."""
     query_params = {
         "group_by": {"project": ["project1"]},
         "order_by": {"usage": "asc"},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_scope": [],
         },
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #6
0
    def test_current_month_delta_success(self):
        """Test that a proper current month delta value is serialized."""
        query_params = {'delta': 'usage__request'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        self.assertTrue(serializer.is_valid())

        query_params = {'delta': 'usage__capacity'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        self.assertTrue(serializer.is_valid())

        query_params = {'delta': 'request__capacity'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        self.assertTrue(serializer.is_valid())
예제 #7
0
    def test_delta_success(self):
        """Test that a proper delta value is serialized."""
        query_params = {'delta': 'cost'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        self.assertTrue(serializer.is_valid())

        query_params = {'delta': 'usage'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        self.assertTrue(serializer.is_valid())

        query_params = {'delta': 'request'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        self.assertTrue(serializer.is_valid())
예제 #8
0
 def test_query_params_invalid_order_by(self):
     """Test parse of inventory query params for invalid fields."""
     # Pass requests instead of request
     query_params = {
         "group_by": {"account": ["account1"]},
         "order_by": {"requests": "asc"},
         "filter": {
             "resolution": "daily",
             "time_scope_value": "-10",
             "time_scope_units": "day",
             "resource_scope": [],
         },
         "invalid": "param",
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #9
0
 def test_parse_query_params_success(self):
     """Test parse of an inventory query params successfully."""
     query_params = {
         'group_by': {
             'project': ['project1']
         },
         'order_by': {
             'usage': 'asc'
         },
         'filter': {
             'resolution': 'daily',
             'time_scope_value': '-10',
             'time_scope_units': 'day',
             'resource_scope': []
         },
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     self.assertTrue(serializer.is_valid())
예제 #10
0
    def test_current_month_delta_failure(self):
        """Test that a bad current month delta value is not serialized."""
        query_params = {'delta': 'bad__delta'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        with self.assertRaises(serializers.ValidationError):
            serializer.is_valid(raise_exception=True)

        query_params = {'delta': 'usage__request__capacity'}
        serializer = OCPInventoryQueryParamSerializer(data=query_params)
        with self.assertRaises(serializers.ValidationError):
            serializer.is_valid(raise_exception=True)
예제 #11
0
 def test_query_params_invalid_order_by(self):
     """Test parse of inventory query params for invalid fields."""
     # Pass requests instead of request
     query_params = {
         'group_by': {
             'account': ['account1']
         },
         'order_by': {
             'requests': 'asc'
         },
         'filter': {
             'resolution': 'daily',
             'time_scope_value': '-10',
             'time_scope_units': 'day',
             'resource_scope': []
         },
         'invalid': 'param'
     }
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #12
0
 def test_order_by_node_without_groupby(self):
     """Test that order_by[node] fails without a matching group-by."""
     query_params = {'order_by': {'node': 'asc'}}
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #13
0
 def test_order_by_delta_without_delta(self):
     """Test that order_by[delta] does not work without a delta param."""
     query_params = {'order_by': {'delta': 'asc'}}
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
예제 #14
0
 def test_delta_failure(self):
     """Test that a bad delta value is not serialized."""
     query_params = {'delta': 'bad_delta'}
     serializer = OCPInventoryQueryParamSerializer(data=query_params)
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)