Fix flaky OAuth tests under tor

The `> 0` check fails if the code was found first in the query string, which can occasionally happen under tox due to the `PYTHONHASHSEED` var changing. We simply change to use a proper parse and check to avoid this issue entirely.
This commit is contained in:
Joseph Schorr 2017-02-14 13:51:58 -05:00
parent 2b189694a8
commit 2f4487c184

View file

@ -1,6 +1,7 @@
import json as py_json
import time
import unittest
import urlparse
import jwt
@ -59,7 +60,8 @@ class OAuthLoginTestCase(EndpointTestCase):
def test_google_oauth(self):
@urlmatch(netloc=r'accounts.google.com', path='/o/oauth2/token')
def account_handler(_, request):
if request.body.find("code=somecode") > 0:
parsed = dict(urlparse.parse_qsl(request.body))
if parsed['code'] == 'somecode':
content = {'access_token': 'someaccesstoken'}
return py_json.dumps(content)
else:
@ -81,7 +83,8 @@ class OAuthLoginTestCase(EndpointTestCase):
def test_github_oauth(self):
@urlmatch(netloc=r'github.com', path='/login/oauth/access_token')
def account_handler(url, _):
if url.query.find("code=somecode") > 0:
parsed = dict(urlparse.parse_qsl(url.query))
if parsed['code'] == 'somecode':
content = {'access_token': 'someaccesstoken'}
return py_json.dumps(content)
else: