File tree 4 files changed +25
-15
lines changed
4 files changed +25
-15
lines changed Original file line number Diff line number Diff line change 20
20
from oslo_config import cfg
21
21
from oslo_log import log
22
22
from paste import deploy
23
- try :
24
- from werkzeug .middleware import dispatcher
25
- # In case we have werkzeug<0.15
26
- except ImportError :
27
- from werkzeug import wsgi as dispatcher
23
+
24
+ from werkzeug .middleware import dispatcher
28
25
29
26
from cloudkitty .api import root as api_root
30
27
from cloudkitty .api .v1 import get_api_app as get_v1_app
Original file line number Diff line number Diff line change 12
12
# License for the specific language governing permissions and limitations
13
13
# under the License.
14
14
#
15
+ import flask
16
+
15
17
from unittest import mock
16
18
17
19
from cloudkitty .api .v2 .dataframes import dataframes
@@ -28,12 +30,15 @@ def setUp(self):
28
30
29
31
def test_non_admin_request_is_filtered_on_project_id (self ):
30
32
policy_mock = mock .patch ('cloudkitty.common.policy.authorize' )
33
+
34
+ flask .request .context = mock .Mock ()
35
+ flask .request .context .project_id = 'test-project'
36
+ flask .request .context .is_admin = False
37
+
31
38
with mock .patch .object (self .endpoint ._storage , 'retrieve' ) as ret_mock :
32
- with policy_mock , mock .patch ('flask.request' ) as fmock :
39
+ with policy_mock , mock .patch ('flask.request.args.lists ' ) as fmock :
33
40
ret_mock .return_value = {'total' : 42 , 'dataframes' : []}
34
- fmock .args .lists .return_value = []
35
- fmock .context .is_admin = False
36
- fmock .context .project_id = 'test-project'
41
+ fmock .return_value = []
37
42
self .endpoint .get ()
38
43
ret_mock .assert_called_once_with (
39
44
begin = tzutils .get_month_start (),
Original file line number Diff line number Diff line change 12
12
# License for the specific language governing permissions and limitations
13
13
# under the License.
14
14
#
15
+ import flask
16
+ import uuid
17
+
15
18
from unittest import mock
16
19
17
20
from cloudkitty .api .v2 .summary import summary
@@ -28,10 +31,15 @@ def setUp(self):
28
31
29
32
def test_type_filter_is_passed_separately (self ):
30
33
policy_mock = mock .patch ('cloudkitty.common.policy.authorize' )
34
+
35
+ flask .request .context = mock .Mock ()
36
+ flask .request .context .project_id = str (uuid .uuid4 ())
37
+ flask .request .context .is_admin = True
38
+
31
39
with mock .patch .object (self .endpoint ._storage , 'total' ) as total_mock :
32
- with policy_mock , mock .patch ('flask.request' ) as fmock :
40
+ with policy_mock , mock .patch ('flask.request.args.lists ' ) as fmock :
33
41
total_mock .return_value = {'total' : 0 , 'results' : []}
34
- fmock .args . lists . return_value = [
42
+ fmock .return_value = [
35
43
('filters' , 'a:b,type:awesome' )]
36
44
self .endpoint .get ()
37
45
total_mock .assert_called_once_with (
Original file line number Diff line number Diff line change @@ -243,12 +243,12 @@ def test_func(self, arg_one=None):
243
243
self .assertEqual (
244
244
list (test_func .input_schema .schema .keys ())[0 ], 'arg_one' )
245
245
246
- with mock .patch ('flask.request' ) as m :
247
- m .get_json . return_value = {}
246
+ with mock .patch ('flask.request.get_json ' ) as m :
247
+ m .return_value = {}
248
248
test_func (self )
249
249
250
- with mock .patch ('flask.request' ) as m :
251
- m .get_json . return_value = {'arg_one' : 'one' }
250
+ with mock .patch ('flask.request.get_json ' ) as m :
251
+ m .return_value = {'arg_one' : 'one' }
252
252
test_func (self )
253
253
254
254
def _test_multiple_add_input_schema_x (self , location ):
You can’t perform that action at this time.
0 commit comments