Skip to content

Commit 65b8524

Browse files
committed
tests: credentials: added
Add tests for the `credentials` tool. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent e5eb7ce commit 65b8524

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

tests/test_credentials.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import subprocess
5+
6+
import pytest
7+
8+
import infuse_iot.credentials as cred
9+
10+
assert "TOXTEMPDIR" in os.environ, "you must run these tests using tox"
11+
12+
13+
def test_credentials():
14+
# Validate the credentials API
15+
16+
try:
17+
cred.delete_api_key()
18+
except Exception as _:
19+
pass
20+
21+
with pytest.raises(FileNotFoundError):
22+
cred.get_api_key()
23+
24+
test_api_key = "ABCDEFGHIJKLMNOP"
25+
test_api_key_2 = "ABCDEFGHIJKLMNOP123456"
26+
27+
output = subprocess.check_output(["infuse", "credentials", "--api-key-print"]).decode()
28+
assert "API Key: N/A" in output
29+
30+
subprocess.check_output(["infuse", "credentials", "--api-key", test_api_key]).decode()
31+
assert test_api_key == cred.get_api_key()
32+
33+
output = subprocess.check_output(["infuse", "credentials", "--api-key-print"]).decode()
34+
assert test_api_key in output
35+
36+
cred.set_api_key(test_api_key_2)
37+
38+
output = subprocess.check_output(["infuse", "credentials", "--api-key-print"]).decode()
39+
assert test_api_key_2 in output
40+
41+
cred.delete_api_key()
42+
43+
output = subprocess.check_output(["infuse", "credentials", "--api-key-print"]).decode()
44+
assert "API Key: N/A" in output

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ deps =
1616
types-PyYAML
1717
pandas-stubs
1818
types-tabulate
19+
keyrings-alt
1920
mypy
2021
ruff
2122
setenv =

0 commit comments

Comments
 (0)