File tree Expand file tree Collapse file tree 4 files changed +25
-15
lines changed Expand file tree Collapse file tree 4 files changed +25
-15
lines changed Original file line number Diff line number Diff line change 2020from oslo_config import cfg
2121from oslo_log import log
2222from 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
2825
2926from cloudkitty .api import root as api_root
3027from cloudkitty .api .v1 import get_api_app as get_v1_app
Original file line number Diff line number Diff line change 1212# License for the specific language governing permissions and limitations
1313# under the License.
1414#
15+ import flask
16+
1517from unittest import mock
1618
1719from cloudkitty .api .v2 .dataframes import dataframes
@@ -28,12 +30,15 @@ def setUp(self):
2830
2931 def test_non_admin_request_is_filtered_on_project_id (self ):
3032 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+
3138 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 :
3340 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 = []
3742 self .endpoint .get ()
3843 ret_mock .assert_called_once_with (
3944 begin = tzutils .get_month_start (),
Original file line number Diff line number Diff line change 1212# License for the specific language governing permissions and limitations
1313# under the License.
1414#
15+ import flask
16+ import uuid
17+
1518from unittest import mock
1619
1720from cloudkitty .api .v2 .summary import summary
@@ -28,10 +31,15 @@ def setUp(self):
2831
2932 def test_type_filter_is_passed_separately (self ):
3033 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+
3139 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 :
3341 total_mock .return_value = {'total' : 0 , 'results' : []}
34- fmock .args . lists . return_value = [
42+ fmock .return_value = [
3543 ('filters' , 'a:b,type:awesome' )]
3644 self .endpoint .get ()
3745 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):
243243 self .assertEqual (
244244 list (test_func .input_schema .schema .keys ())[0 ], 'arg_one' )
245245
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 = {}
248248 test_func (self )
249249
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' }
252252 test_func (self )
253253
254254 def _test_multiple_add_input_schema_x (self , location ):
You can’t perform that action at this time.
0 commit comments