diff --git a/cloudkitty/api/v2/summary/summary.py b/cloudkitty/api/v2/summary/summary.py index 5bbc48ff..ff705037 100644 --- a/cloudkitty/api/v2/summary/summary.py +++ b/cloudkitty/api/v2/summary/summary.py @@ -47,10 +47,12 @@ class Summary(base.BaseResource): if not flask.request.context.is_admin: filters['project_id'] = flask.request.context.project_id + metric_types = [filters.pop('type')] if 'type' in filters else None total = self._storage.total( begin=begin, end=end, groupby=groupby, filters=filters, + metric_types=metric_types, offset=offset, limit=limit, paginate=True, diff --git a/cloudkitty/tests/api/v2/summary/__init__.py b/cloudkitty/tests/api/v2/summary/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cloudkitty/tests/api/v2/summary/test_summary.py b/cloudkitty/tests/api/v2/summary/test_summary.py new file mode 100644 index 00000000..b0ae3b01 --- /dev/null +++ b/cloudkitty/tests/api/v2/summary/test_summary.py @@ -0,0 +1,46 @@ +# Copyright 2019 Objectif Libre +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +import unittest + +import mock + +from cloudkitty.api.v2.summary import summary +from cloudkitty import tzutils + + +class TestSummaryEndpoint(unittest.TestCase): + + def setUp(self): + super(TestSummaryEndpoint, self).setUp() + self.endpoint = summary.Summary() + + def test_type_filter_is_passed_separately(self): + policy_mock = mock.patch('cloudkitty.common.policy.authorize') + with mock.patch.object(self.endpoint._storage, 'total') as total_mock: + with policy_mock, mock.patch('flask.request') as fmock: + total_mock.return_value = {'total': 0, 'results': []} + fmock.args.lists.return_value = [ + ('filters', 'a:b,type:awesome')] + self.endpoint.get() + total_mock.assert_called_once_with( + begin=tzutils.get_month_start(), + end=tzutils.get_next_month(), + groupby=None, + filters={'a': 'b'}, + metric_types=['awesome'], + offset=0, + limit=100, + paginate=True, + )