From 8276f2c4a4deb25cedcac4f2fbbdca4e61e4e6cd Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Thu, 13 Apr 2017 11:35:40 -0700 Subject: [PATCH] refactor: path_args/kwargs -> args/kwargs more accurately reflects what's happening now and cyclone's path_args/kwargs are exactly the same as its calling args/kwargs anyway issue #695 --- autopush/tests/test_web_validation.py | 46 +++++++++++++-------------- autopush/web/base.py | 4 +-- autopush/web/log_check.py | 2 +- autopush/web/message.py | 2 +- autopush/web/registration.py | 8 ++--- autopush/web/simplepush.py | 4 +-- autopush/web/webpush.py | 4 +-- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/autopush/tests/test_web_validation.py b/autopush/tests/test_web_validation.py index 468c6e7a..d8682c14 100644 --- a/autopush/tests/test_web_validation.py +++ b/autopush/tests/test_web_validation.py @@ -158,13 +158,13 @@ def _make_fut(self): schema.context["log"] = Mock() return schema - def _make_test_data(self, headers=None, body="", path_args=None, - path_kwargs=None, arguments=None): + def _make_test_data(self, headers=None, body="", args=None, kwargs=None, + arguments=None): return dict( headers=headers or {}, body=body, - path_args=path_args or [], - path_kwargs=path_kwargs or {}, + args=args or [], + kwargs=kwargs or {}, arguments=arguments or {}, ) @@ -291,13 +291,13 @@ def _make_fut(self): schema.context["log"] = Mock() return schema - def _make_test_data(self, headers=None, body="", path_args=None, - path_kwargs=None, arguments=None): + def _make_test_data(self, headers=None, body="", args=None, kwargs=None, + arguments=None): return dict( headers=headers or {}, body=body, - path_args=path_args or [], - path_kwargs=path_kwargs or {}, + args=args or [], + kwargs=kwargs or {}, arguments=arguments or {}, ) @@ -784,13 +784,13 @@ def _make_fut(self): settings.fernet = self.fernet_mock = Mock() return schema - def _make_test_data(self, headers=None, body="", path_args=None, - path_kwargs=None, arguments=None): + def _make_test_data(self, headers=None, body="", args=None, kwargs=None, + arguments=None): return dict( headers=headers or {}, body=body, - path_args=path_args or [], - path_kwargs=path_kwargs or {"api_ver": "v2", "token": "xxx"}, + args=args or [], + kwargs=kwargs or {"api_ver": "v2", "token": "xxx"}, arguments=arguments or {}, ) @@ -816,7 +816,7 @@ def test_valid_vapid_crypto_header(self): sha256(utils.base64url_decode(crypto_key)).digest() info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -847,7 +847,7 @@ def test_valid_vapid_crypto_header_webpush(self): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -881,7 +881,7 @@ def test_invalid_vapid_crypto_header(self, mock_jwt): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -913,7 +913,7 @@ def test_invalid_too_far_exp_vapid_crypto_header(self): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -945,7 +945,7 @@ def test_invalid_bad_exp_vapid_crypto_header(self): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -981,7 +981,7 @@ def test_invalid_encryption_header(self, mock_jwt): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -1017,7 +1017,7 @@ def test_invalid_encryption_jwt(self, mock_jwt): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -1053,7 +1053,7 @@ def test_invalid_crypto_key_header_content(self, mock_jwt): ckey = 'keyid="a1";invalid="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -1086,7 +1086,7 @@ def test_expired_vapid_header(self): sha256(utils.base64url_decode(crypto_key)).digest() info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -1120,7 +1120,7 @@ def test_missing_vapid_header(self): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), @@ -1153,7 +1153,7 @@ def test_bogus_vapid_header(self): ckey = 'keyid="a1"; dh="foo";p256ecdsa="%s"' % crypto_key info = self._make_test_data( body="asdfasdfasdfasdf", - path_kwargs=dict( + kwargs=dict( api_ver="v2", token="asdfasdf", ), diff --git a/autopush/web/base.py b/autopush/web/base.py index f25531c6..bdd60cce 100644 --- a/autopush/web/base.py +++ b/autopush/web/base.py @@ -55,8 +55,8 @@ def _validate_request(self, request_handler, *args, **kwargs): data = { "headers": request_handler.request.headers, "body": request_handler.request.body, - "path_args": args, - "path_kwargs": kwargs, + "args": args, + "kwargs": kwargs, "arguments": request_handler.request.arguments, } schema = self.schema() diff --git a/autopush/web/log_check.py b/autopush/web/log_check.py index 46e13dec..a6e384a8 100644 --- a/autopush/web/log_check.py +++ b/autopush/web/log_check.py @@ -11,7 +11,7 @@ class LogCheckSchema(Schema): @pre_load def extract_data(self, req): - return dict(err_type=req['path_kwargs'].get('err_type')) + return dict(err_type=req['kwargs'].get('err_type')) class LogCheckHandler(BaseWebHandler): diff --git a/autopush/web/message.py b/autopush/web/message.py index 76ae7ef2..07f26d45 100644 --- a/autopush/web/message.py +++ b/autopush/web/message.py @@ -13,7 +13,7 @@ class MessageSchema(Schema): @pre_load def extract_data(self, req): - message_id = req['path_kwargs'].get('message_id') + message_id = req['kwargs'].get('message_id') if not message_id: raise InvalidRequest("Missing Token", status_code=400) diff --git a/autopush/web/registration.py b/autopush/web/registration.py index 0a05a563..1b432993 100644 --- a/autopush/web/registration.py +++ b/autopush/web/registration.py @@ -55,8 +55,8 @@ def extract_data(self, req): # UAID and CHID may be empty. This can trigger different behaviors # in the handlers, so we can't set default values here. - uaid = req['path_kwargs'].get('uaid') - chid = req['path_kwargs'].get('chid', router_data.get("channelID")) + uaid = req['kwargs'].get('uaid') + chid = req['kwargs'].get('chid', router_data.get("channelID")) if uaid: try: u_uuid = uuid.UUID(uaid) @@ -81,8 +81,8 @@ def extract_data(self, req): status_code=410, errno=106) return dict( - router_type=req['path_kwargs'].get('router_type'), - router_token=req['path_kwargs'].get('router_token'), + router_type=req['kwargs'].get('router_type'), + router_token=req['kwargs'].get('router_token'), router_data=router_data, uaid=uaid, chid=chid, diff --git a/autopush/web/simplepush.py b/autopush/web/simplepush.py index 86b8c77b..f25aa64e 100644 --- a/autopush/web/simplepush.py +++ b/autopush/web/simplepush.py @@ -75,8 +75,8 @@ def validate_data(self, value): @pre_load def token_prep(self, d): d["token_info"] = dict( - api_ver=d["path_kwargs"].get("api_ver"), - token=d["path_kwargs"].get("token"), + api_ver=d["kwargs"].get("api_ver"), + token=d["kwargs"].get("token"), ) return d diff --git a/autopush/web/webpush.py b/autopush/web/webpush.py index 08606fb7..4f90d4d7 100644 --- a/autopush/web/webpush.py +++ b/autopush/web/webpush.py @@ -297,8 +297,8 @@ def validate_data(self, value): @pre_load def token_prep(self, d): d["token_info"] = dict( - api_ver=d["path_kwargs"].get("api_ver"), - token=d["path_kwargs"].get("token"), + api_ver=d["kwargs"].get("api_ver"), + token=d["kwargs"].get("token"), ckey_header=d["headers"].get("crypto-key", ""), auth_header=d["headers"].get("authorization", ""), )