Skip to content

Commit

Permalink
API Tests: rename test & delete test (#321)
Browse files Browse the repository at this point in the history
* uncommented test and changed test name to be self documenting

* removed `test_create_api` test function

* updated `test_create_api_with_none` to get env vars from environment
  • Loading branch information
nh916 authored Sep 11, 2023
1 parent 9236fe5 commit d72b40c
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
from cript.nodes.exceptions import CRIPTNodeSchemaError


def test_create_api(cript_api: cript.API) -> None:
"""
tests that an API object can be successfully created with host and token
"""
# api = cript.API(host=None, api_token=None)
#
# # assertions
# assert api is not None
# assert isinstance(api, cript.API)

pass


def test_api_with_invalid_host() -> None:
"""
this mostly tests the _prepare_host() function to be sure it is working as expected
Expand All @@ -48,26 +35,32 @@ def test_api_context(cript_api: cript.API) -> None:
assert cript.api.api._get_global_cached_api() is not None


def test_api_cript_env_vars() -> None:
def test_create_api_with_none() -> None:
"""
tests that when the cript.API is given None for host, api_token, storage_token that it can correctly
retrieve things from the env variable
"""
host_value = "http://development.api.mycriptapp.org/"
api_token_value = "my cript API token value"
storage_token_value = "my cript storage token value"
retrieve things from the env variable.
assert that the values found from the environment are equal to what the SDK API class
correctly got for `_host`, `_api_token`, and `_storage_token`
Notes
-----
This test is dependent on the environment (local computer or CI), where it expects
`CRIPT_HOST`, `CRIPT_TOKEN` and `CRIPT_STORAGE_TOKEN` to be in the environment variables,
otherwise, it will not be able to find the needed environment variables and the test will fail
"""
# set env vars
os.environ["CRIPT_HOST"] = host_value
os.environ["CRIPT_TOKEN"] = api_token_value
os.environ["CRIPT_STORAGE_TOKEN"] = storage_token_value
# strip end slash to make all hosts uniform for comparison
# regardless of how it was entered in the env var
env_var_host = os.environ["CRIPT_HOST"].rstrip("/")

# create an API instance with `None`
api = cript.API(host=None, api_token=None, storage_token=None)

# assert SDK correctly got env vars to create cript.API with
# host/api/v1
assert api._host == f"{host_value}api/v1"
assert api._api_token == api_token_value
assert api._storage_token == storage_token_value
assert api._host == f"{env_var_host}/api/v1"
assert api._api_token == os.environ["CRIPT_TOKEN"]
assert api._storage_token == os.environ["CRIPT_STORAGE_TOKEN"]


def test_config_file() -> None:
Expand Down

0 comments on commit d72b40c

Please sign in to comment.