Browse Source

Merge "Pass 'type' as metric_types in /v2/summary endpoints"

changes/68/680068/2
Zuul 1 week ago
parent
commit
c920108d5a

+ 2
- 0
cloudkitty/api/v2/summary/summary.py View File

@@ -47,10 +47,12 @@ class Summary(base.BaseResource):
47 47
         if not flask.request.context.is_admin:
48 48
             filters['project_id'] = flask.request.context.project_id
49 49
 
50
+        metric_types = [filters.pop('type')] if 'type' in filters else None
50 51
         total = self._storage.total(
51 52
             begin=begin, end=end,
52 53
             groupby=groupby,
53 54
             filters=filters,
55
+            metric_types=metric_types,
54 56
             offset=offset,
55 57
             limit=limit,
56 58
             paginate=True,

+ 0
- 0
cloudkitty/tests/api/v2/summary/__init__.py View File


+ 46
- 0
cloudkitty/tests/api/v2/summary/test_summary.py View File

@@ -0,0 +1,46 @@
1
+# Copyright 2019 Objectif Libre
2
+#
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.
14
+#
15
+import unittest
16
+
17
+import mock
18
+
19
+from cloudkitty.api.v2.summary import summary
20
+from cloudkitty import tzutils
21
+
22
+
23
+class TestSummaryEndpoint(unittest.TestCase):
24
+
25
+    def setUp(self):
26
+        super(TestSummaryEndpoint, self).setUp()
27
+        self.endpoint = summary.Summary()
28
+
29
+    def test_type_filter_is_passed_separately(self):
30
+        policy_mock = mock.patch('cloudkitty.common.policy.authorize')
31
+        with mock.patch.object(self.endpoint._storage, 'total') as total_mock:
32
+            with policy_mock, mock.patch('flask.request') as fmock:
33
+                total_mock.return_value = {'total': 0, 'results': []}
34
+                fmock.args.lists.return_value = [
35
+                    ('filters', 'a:b,type:awesome')]
36
+                self.endpoint.get()
37
+                total_mock.assert_called_once_with(
38
+                    begin=tzutils.get_month_start(),
39
+                    end=tzutils.get_next_month(),
40
+                    groupby=None,
41
+                    filters={'a': 'b'},
42
+                    metric_types=['awesome'],
43
+                    offset=0,
44
+                    limit=100,
45
+                    paginate=True,
46
+                )

Loading…
Cancel
Save