Fixed tests & set status after writing json

This commit is contained in:
josefgasewicz
2021-10-07 22:21:16 +01:00
parent fe276eac64
commit 1366911be6
2 changed files with 9 additions and 9 deletions

View File

@@ -420,8 +420,8 @@ class UserTokenListAPIHandler(APIHandler):
# retrieve the model # retrieve the model
token_model = self.token_model(orm.APIToken.find(self.db, api_token)) token_model = self.token_model(orm.APIToken.find(self.db, api_token))
token_model['token'] = api_token token_model['token'] = api_token
self.set_status(201)
self.write(json.dumps(token_model)) self.write(json.dumps(token_model))
self.set_status(201)
class UserTokenAPIHandler(APIHandler): class UserTokenAPIHandler(APIHandler):

View File

@@ -1366,8 +1366,8 @@ async def test_get_new_token_deprecated(app, headers, status):
@mark.parametrize( @mark.parametrize(
"headers, status, note, expires_in", "headers, status, note, expires_in",
[ [
({}, 200, 'test note', None), ({}, 201, 'test note', None),
({}, 200, '', 100), ({}, 201, '', 100),
({'Authorization': 'token bad'}, 403, '', None), ({'Authorization': 'token bad'}, 403, '', None),
], ],
) )
@@ -1386,7 +1386,7 @@ async def test_get_new_token(app, headers, status, note, expires_in):
app, 'users/admin/tokens', method='post', headers=headers, data=body app, 'users/admin/tokens', method='post', headers=headers, data=body
) )
assert r.status_code == status assert r.status_code == status
if status != 200: if status != 201:
return return
# check the new-token reply # check the new-token reply
reply = r.json() reply = r.json()
@@ -1424,10 +1424,10 @@ async def test_get_new_token(app, headers, status, note, expires_in):
@mark.parametrize( @mark.parametrize(
"as_user, for_user, status", "as_user, for_user, status",
[ [
('admin', 'other', 200), ('admin', 'other', 201),
('admin', 'missing', 403), ('admin', 'missing', 403),
('user', 'other', 403), ('user', 'other', 403),
('user', 'user', 200), ('user', 'user', 201),
], ],
) )
async def test_token_for_user(app, as_user, for_user, status): async def test_token_for_user(app, as_user, for_user, status):
@@ -1448,7 +1448,7 @@ async def test_token_for_user(app, as_user, for_user, status):
) )
assert r.status_code == status assert r.status_code == status
reply = r.json() reply = r.json()
if status != 200: if status != 201:
return return
assert 'token' in reply assert 'token' in reply
@@ -1486,7 +1486,7 @@ async def test_token_authenticator_noauth(app):
data=json.dumps(data) if data else None, data=json.dumps(data) if data else None,
noauth=True, noauth=True,
) )
assert r.status_code == 200 assert r.status_code == 201
reply = r.json() reply = r.json()
assert 'token' in reply assert 'token' in reply
r = await api_request(app, 'authorizations', 'token', reply['token']) r = await api_request(app, 'authorizations', 'token', reply['token'])
@@ -1509,7 +1509,7 @@ async def test_token_authenticator_dict_noauth(app):
data=json.dumps(data) if data else None, data=json.dumps(data) if data else None,
noauth=True, noauth=True,
) )
assert r.status_code == 200 assert r.status_code == 201
reply = r.json() reply = r.json()
assert 'token' in reply assert 'token' in reply
r = await api_request(app, 'authorizations', 'token', reply['token']) r = await api_request(app, 'authorizations', 'token', reply['token'])