Skip to content

Commit

Permalink
tests for read_txt_api_key and read_json_api_key
Browse files Browse the repository at this point in the history
  • Loading branch information
KariSt1 committed Aug 30, 2023
1 parent e2473aa commit 7ec98ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tests/files/dummy_json_api_key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": 123456789
}
34 changes: 31 additions & 3 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ def get_modules(*path: str):
QUERIES_UTIL_DIR.relative_to(GREYNIR_ROOT_DIR)
) == get_modules("queries", "util")

# TODO: Test read_api_key
# from util import read_api_key

assert cap_first("yolo") == "Yolo"
assert cap_first("YOLO") == "YOLO"
assert cap_first("yoLo") == "YoLo"
Expand All @@ -128,3 +125,34 @@ def get_modules(*path: str):

assert icequote("sæll") == "„sæll“"
assert icequote(" Góðan daginn ") == "„Góðan daginn“"


def test_read_json_api_key():
"""Test reading API keys from JSON files."""

from utility import read_json_api_key, GREYNIR_ROOT_DIR

# Test reading a non-existent key
assert read_json_api_key("nonexistent") == {}

# Test reading a key from a JSON file
assert read_json_api_key(
"dummy_json_api_key", folder=GREYNIR_ROOT_DIR / "tests/files"
) == {"key": 123456789}


def test_read_txt_api_key():
"""Test reading API keys from .txt files."""

from utility import read_txt_api_key, GREYNIR_ROOT_DIR

# Test reading a non-existent key
assert read_txt_api_key("nonexistent") == ""

# Test reading a key from a .txt file
assert (
read_txt_api_key(
"dummy_greynir_api_key", folder=GREYNIR_ROOT_DIR / "tests/files"
)
== "123456789"
)

0 comments on commit 7ec98ae

Please sign in to comment.