From c03e1d1e12c830e707b1485b74fb7e04ab478c4f Mon Sep 17 00:00:00 2001 From: Philip Flohr Date: Thu, 3 Dec 2020 17:40:19 +0100 Subject: [PATCH] Place authentication in importable file for use with test cases placed in multiple files (#11) * Place authentication in importable file for use with test cases placed in multiple files * Readd existing tests * Update import statement * Don't use shared_test_data dict, cache retrieval of valid online user * Don't require python3.8 to run the tests * cleanup Co-authored-by: Sebastian Straub --- tests/apitest_shared.py | 19 ++++++------------- tests/test_api_raw.py | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/apitest_shared.py b/tests/apitest_shared.py index 5fd742b..3840109 100644 --- a/tests/apitest_shared.py +++ b/tests/apitest_shared.py @@ -1,4 +1,7 @@ import os + +from functools import lru_cache + import pytest from personio_py import Personio, PersonioError @@ -8,25 +11,15 @@ CLIENT_SECRET = os.getenv('CLIENT_SECRET') personio = Personio(client_id=CLIENT_ID, client_secret=CLIENT_SECRET) -shared_test_data = {} # deactivate all tests that rely on a specific personio instance try: personio.authenticate() can_authenticate = True - # This is used to ensure the test check for existing objects - test_employee = personio.get_employees()[0] - shared_test_data = { - 'test_employee': { - 'id': test_employee.id_, - 'first_name': test_employee.first_name, - 'last_name': test_employee.last_name, - 'email': test_employee.email, - 'hire_date': test_employee.hire_date - } - } except PersonioError: can_authenticate = False skip_if_no_auth = pytest.mark.skipif(not can_authenticate, reason="Personio authentication failed") - +@lru_cache(maxsize=1) +def get_test_employee(): + return personio.get_employees()[0] diff --git a/tests/test_api_raw.py b/tests/test_api_raw.py index 4adf618..557bce0 100644 --- a/tests/test_api_raw.py +++ b/tests/test_api_raw.py @@ -1,4 +1,4 @@ -from .apitest_shared import * +from tests.apitest_shared import * @skip_if_no_auth