From a89158377f829720a98342cf434a18b962006ee7 Mon Sep 17 00:00:00 2001 From: pennae Date: Mon, 18 Jul 2022 17:12:52 +0200 Subject: speed up test suite mostly by grouping tests that can reuse the same account (which is expensive to create) into classes and scoping accounts to classes. --- tests/test_oauth.py | 109 ++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) (limited to 'tests/test_oauth.py') diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 3eb32ac..d809113 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -32,66 +32,67 @@ def test_destroy_invalid(oauth, args, code, errno, error, message): oauth.post("/destroy", args) assert e.value.details == {'code': code, 'errno': errno, 'error': error, 'message': message} -def test_destroy_access(oauth, access_token): - oauth.post("/verify", {'token': access_token}) - oauth.post("/destroy", {'access_token': access_token}) - with pytest.raises(ClientError) as e: +class TestOauth: + def test_destroy_access(self, oauth, access_token): oauth.post("/verify", {'token': access_token}) - assert e.value.details == { - 'code': 400, - 'errno': 109, - 'error': 'Bad Request', - 'message': 'invalid request parameter' - } + oauth.post("/destroy", {'access_token': access_token}) + with pytest.raises(ClientError) as e: + oauth.post("/verify", {'token': access_token}) + assert e.value.details == { + 'code': 400, + 'errno': 109, + 'error': 'Bad Request', + 'message': 'invalid request parameter' + } -def test_destroy_refresh(oauth, refresh_token): - refresh_token.get_a("/account/devices") - oauth.post("/destroy", {'refresh_token': refresh_token.bearer}) - with pytest.raises(ClientError) as e: + def test_destroy_refresh(self, oauth, refresh_token): refresh_token.get_a("/account/devices") - assert e.value.details == { - 'code': 401, - 'errno': 109, - 'error': 'Unauthorized', - 'message': 'invalid request signature' - } + oauth.post("/destroy", {'refresh_token': refresh_token.bearer}) + with pytest.raises(ClientError) as e: + refresh_token.get_a("/account/devices") + assert e.value.details == { + 'code': 401, + 'errno': 109, + 'error': 'Unauthorized', + 'message': 'invalid request signature' + } -def test_destroy_any(oauth, access_token, refresh_token): - oauth.post("/verify", {'token': access_token}) - oauth.post("/destroy", {'token': access_token}) - with pytest.raises(ClientError) as e: + def test_destroy_any(self, oauth, access_token, refresh_token): oauth.post("/verify", {'token': access_token}) - assert e.value.details == { - 'code': 400, - 'errno': 109, - 'error': 'Bad Request', - 'message': 'invalid request parameter' - } + oauth.post("/destroy", {'token': access_token}) + with pytest.raises(ClientError) as e: + oauth.post("/verify", {'token': access_token}) + assert e.value.details == { + 'code': 400, + 'errno': 109, + 'error': 'Bad Request', + 'message': 'invalid request parameter' + } - refresh_token.get_a("/account/devices") - oauth.post("/destroy", {'token': refresh_token.bearer}) - with pytest.raises(ClientError) as e: refresh_token.get_a("/account/devices") - assert e.value.details == { - 'code': 401, - 'errno': 109, - 'error': 'Unauthorized', - 'message': 'invalid request signature' - } + oauth.post("/destroy", {'token': refresh_token.bearer}) + with pytest.raises(ClientError) as e: + refresh_token.get_a("/account/devices") + assert e.value.details == { + 'code': 401, + 'errno': 109, + 'error': 'Unauthorized', + 'message': 'invalid request signature' + } -def test_oauth_verify(account, oauth, access_token): - assert oauth.post("/verify", {'token': access_token}) == { - 'user': account.props['uid'], - 'client_id': "5882386c6d801776", - 'scope': ['profile'], - } + def test_oauth_verify(self, account, oauth, access_token): + assert oauth.post("/verify", {'token': access_token}) == { + 'user': account.props['uid'], + 'client_id': "5882386c6d801776", + 'scope': ['profile'], + } -def test_oauth_verify_refresh(oauth, refresh_token): - with pytest.raises(ClientError) as e: - oauth.post("/verify", {'token': refresh_token.bearer}) - assert e.value.details == { - 'code': 400, - 'errno': 109, - 'error': 'Bad Request', - 'message': 'invalid request parameter' - } + def test_oauth_verify_refresh(self, oauth, refresh_token): + with pytest.raises(ClientError) as e: + oauth.post("/verify", {'token': refresh_token.bearer}) + assert e.value.details == { + 'code': 400, + 'errno': 109, + 'error': 'Bad Request', + 'message': 'invalid request parameter' + } -- cgit v1.2.3