-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make TEST_X_API_KEY use an environment variable of the same name
- Loading branch information
1 parent
0190345
commit 22508cf
Showing
1 changed file
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
from os import getenv | ||
from unittest import skipIf | ||
|
||
from fathomnet.api import xapikey | ||
|
||
# Set this to an API key in order to perform authentication and enable test cases decorated by @skipIfNoAuth | ||
TEST_X_API_KEY = None | ||
# Set the TEST_X_API_KEY environment variable an API key in order to perform authentication and enable test cases decorated by @skipIfNoAuth | ||
TEST_X_API_KEY = getenv("TEST_X_API_KEY") | ||
|
||
|
||
if ( | ||
TEST_X_API_KEY is not None | ||
): # If test X-API-Key is provided, authenticate session to enable cases | ||
# If test X-API-Key is provided, authenticate session to enable cases | ||
if TEST_X_API_KEY is not None: | ||
xapikey.auth(TEST_X_API_KEY) | ||
|
||
|
||
def skipIfNoAuth(f): # Decorator to skip test case if it needs auth | ||
def skipIfNoAuth(f: callable) -> callable: | ||
""" | ||
Decorator to skip test case if it needs auth. | ||
Args: | ||
f (callable): Test case function. | ||
Returns: | ||
callable: Test case function | ||
""" | ||
return skipIf( | ||
TEST_X_API_KEY is None, "Test X-API-Key not specified. (see test/__init__.py)" | ||
TEST_X_API_KEY is None, | ||
"TEST_X_API_KEY environment variable not specified", | ||
)(f) |