Skip to content

Commit

Permalink
Place authentication in importable file for use with test cases place…
Browse files Browse the repository at this point in the history
…d in multiple files (at-gmbh#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 <[email protected]>
  • Loading branch information
Philip Flohr and klamann committed Jan 15, 2021
1 parent aa801a7 commit c03e1d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions tests/apitest_shared.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os

from functools import lru_cache

import pytest

from personio_py import Personio, PersonioError
Expand All @@ -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]
2 changes: 1 addition & 1 deletion tests/test_api_raw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .apitest_shared import *
from tests.apitest_shared import *


@skip_if_no_auth
Expand Down

0 comments on commit c03e1d1

Please sign in to comment.