diff options
author | Frederick Muriuki Muriithi | 2023-02-03 15:15:26 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-02-03 15:15:26 +0300 |
commit | e6dd74a3fab65355c0aa187ee31d5ee74a888649 (patch) | |
tree | 615214631357f96874b59919da4409d1b28cfe2b /tests/unit/auth/conftest.py | |
parent | ecce454ca9d0f374e22da8401206e3b1695dbded (diff) | |
download | genenetwork3-e6dd74a3fab65355c0aa187ee31d5ee74a888649.tar.gz |
auth: tests: mock token acquisition. Fix minor bugs.
Diffstat (limited to 'tests/unit/auth/conftest.py')
-rw-r--r-- | tests/unit/auth/conftest.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/unit/auth/conftest.py b/tests/unit/auth/conftest.py index 7082910..a7c64a8 100644 --- a/tests/unit/auth/conftest.py +++ b/tests/unit/auth/conftest.py @@ -1,2 +1,24 @@ """Module for fixtures and test utilities""" +import uuid +import datetime +from contextlib import contextmanager + +from gn3.auth.authentication.oauth2.models.oauth2token import OAuth2Token + from .fixtures import * # pylint: disable=[wildcard-import,unused-wildcard-import] + +def get_tokeniser(user): + """Get contextmanager for mocking token acquisition.""" + @contextmanager + def __token__(*args, **kwargs):# pylint: disable=[unused-argument] + yield { + usr.user_id: OAuth2Token( + token_id=uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b"), + client=None, token_type="Bearer", access_token="123456ABCDE", + refresh_token=None, revoked=False, expires_in=864000, + user=usr, issued_at=int(datetime.datetime.now().timestamp()), + scope="profile group role resource register-client") + for usr in TEST_USERS + }[user.user_id] + + return __token__ |