Skip to content

Commit 54f87d9

Browse files
committed
Clean test cases for oauth2
1 parent 521c13b commit 54f87d9

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

tests/oauth2/test_oauth2.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def test_oauth_authorize_invalid_url(self):
6767

6868
def test_oauth_authorize_valid_url(self):
6969
rv = self.client.get(authorize_url)
70-
# valid
71-
assert '</form>' in u(rv.data)
70+
assert b'</form>' in rv.data
7271

7372
rv = self.client.post(authorize_url, data=dict(
7473
confirm='no'
@@ -92,27 +91,27 @@ def test_oauth_authorize_valid_url(self):
9291
def test_get_access_token(self):
9392
rv = self.client.post(authorize_url, data={'confirm': 'yes'})
9493
rv = self.client.get(clean_url(rv.location))
95-
assert 'access_token' in u(rv.data)
94+
assert b'access_token' in rv.data
9695

9796
def test_full_flow(self):
9897
rv = self.client.post(authorize_url, data={'confirm': 'yes'})
9998
rv = self.client.get(clean_url(rv.location))
100-
assert 'access_token' in u(rv.data)
99+
assert b'access_token' in rv.data
101100

102101
rv = self.client.get('/')
103-
assert 'username' in u(rv.data)
102+
assert b'username' in rv.data
104103

105104
rv = self.client.get('/address')
106105
assert rv.status_code == 403
107106

108107
rv = self.client.get('/method/post')
109-
assert 'POST' in u(rv.data)
108+
assert b'POST' in rv.data
110109

111110
rv = self.client.get('/method/put')
112-
assert 'PUT' in u(rv.data)
111+
assert b'PUT' in rv.data
113112

114113
rv = self.client.get('/method/delete')
115-
assert 'DELETE' in u(rv.data)
114+
assert b'DELETE' in rv.data
116115

117116
def test_invalid_client_id(self):
118117
authorize_url = (
@@ -122,7 +121,7 @@ def test_invalid_client_id(self):
122121
)
123122
rv = self.client.post(authorize_url, data={'confirm': 'yes'})
124123
rv = self.client.get(clean_url(rv.location))
125-
assert 'Invalid' in u(rv.data)
124+
assert b'Invalid' in rv.data
126125

127126
def test_invalid_response_type(self):
128127
authorize_url = (
@@ -132,7 +131,7 @@ def test_invalid_response_type(self):
132131
)
133132
rv = self.client.post(authorize_url, data={'confirm': 'yes'})
134133
rv = self.client.get(clean_url(rv.location))
135-
assert 'error' in u(rv.data)
134+
assert b'error' in rv.data
136135

137136

138137
class TestWebAuthCached(TestWebAuth):
@@ -158,8 +157,8 @@ def test_get_access_token(self):
158157
rv = self.client.get(url, headers={
159158
'HTTP_AUTHORIZATION': 'Basic %s' % auth_code,
160159
}, data={'confirm': 'yes'})
161-
assert 'access_token' in u(rv.data)
162-
assert 'state' in u(rv.data)
160+
assert b'access_token' in rv.data
161+
assert b'state' in rv.data
163162

164163
def test_invalid_user_credentials(self):
165164
url = ('/oauth/token?grant_type=password&state=foo'
@@ -168,7 +167,7 @@ def test_invalid_user_credentials(self):
168167
'HTTP_AUTHORIZATION': 'Basic %s' % auth_code,
169168
}, data={'confirm': 'yes'})
170169

171-
assert 'Invalid credentials given' in u(rv.data)
170+
assert b'Invalid credentials given' in rv.data
172171

173172

174173
class TestPasswordAuthCached(TestPasswordAuth):
@@ -194,7 +193,7 @@ def test_refresh_token_in_password_grant(self):
194193
rv = self.client.get(url, headers={
195194
'HTTP_AUTHORIZATION': 'Basic %s' % auth_code,
196195
})
197-
assert 'access_token' in u(rv.data)
196+
assert b'access_token' in rv.data
198197
data = json.loads(u(rv.data))
199198

200199
args = (data.get('scope').replace(' ', '+'),
@@ -205,7 +204,7 @@ def test_refresh_token_in_password_grant(self):
205204
rv = self.client.get(url, headers={
206205
'HTTP_AUTHORIZATION': 'Basic %s' % auth_code,
207206
})
208-
assert 'access_token' in u(rv.data)
207+
assert b'access_token' in rv.data
209208

210209

211210
class TestRefreshTokenCached(TestRefreshToken):
@@ -231,15 +230,15 @@ def test_get_access_token(self):
231230
rv = self.client.get(url, headers={
232231
'HTTP_AUTHORIZATION': 'Basic %s' % auth_code,
233232
}, data={'confirm': 'yes'})
234-
assert 'access_token' in u(rv.data)
233+
assert b'access_token' in rv.data
235234

236235
def test_invalid_auth_header(self):
237236
url = ('/oauth/token?grant_type=client_credentials'
238237
'&scope=email+address&username=admin&password=admin')
239238
rv = self.client.get(url, headers={
240239
'HTTP_AUTHORIZATION': 'Basic foobar'
241240
}, data={'confirm': 'yes'})
242-
assert 'invalid_client' in u(rv.data)
241+
assert b'invalid_client' in rv.data
243242

244243
def test_no_client(self):
245244
auth_code = _base64('none:confidential')
@@ -248,7 +247,7 @@ def test_no_client(self):
248247
rv = self.client.get(url, headers={
249248
'HTTP_AUTHORIZATION': 'Basic %s' % auth_code,
250249
}, data={'confirm': 'yes'})
251-
assert 'invalid_client' in u(rv.data)
250+
assert b'invalid_client' in rv.data
252251

253252
def test_wrong_secret_client(self):
254253
auth_code = _base64('confidential:wrong')
@@ -257,7 +256,7 @@ def test_wrong_secret_client(self):
257256
rv = self.client.get(url, headers={
258257
'HTTP_AUTHORIZATION': 'Basic %s' % auth_code,
259258
}, data={'confirm': 'yes'})
260-
assert 'invalid_client' in u(rv.data)
259+
assert b'invalid_client' in rv.data
261260

262261

263262
class TestCredentialAuthCached(TestCredentialAuth):
@@ -285,4 +284,6 @@ def generator(request, refresh_token=False):
285284
def test_get_access_token(self):
286285
rv = self.client.post(authorize_url, data={'confirm': 'yes'})
287286
rv = self.client.get(clean_url(rv.location))
288-
assert 'foobar' in u(rv.data)
287+
data = json.loads(u(rv.data))
288+
assert data['access_token'] == 'foobar'
289+
assert data['refresh_token'] == 'foobar'

0 commit comments

Comments
 (0)