-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenv_test.py
More file actions
105 lines (75 loc) · 2.99 KB
/
env_test.py
File metadata and controls
105 lines (75 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import pytest
from seam import Seam
from seam.options import SeamInvalidOptionsError
# Cleanup environment variables before and after each test
def cleanup_env():
os.environ.pop("SEAM_API_KEY", None)
os.environ.pop("SEAM_ENDPOINT", None)
os.environ.pop("SEAM_API_URL", None)
@pytest.fixture(autouse=True)
def run_around_tests():
cleanup_env()
yield
cleanup_env()
def test_seam_client_constructor_uses_seam_api_key_env_variable(server):
endpoint, seed = server
os.environ["SEAM_API_KEY"] = seed["seam_apikey1_token"]
seam = Seam(endpoint=endpoint)
devices = seam.devices.list()
assert len(devices) > 0
def test_seam_client_api_key_option_overrides_env_variables(server):
endpoint, seed = server
os.environ["SEAM_API_KEY"] = "some-invalid-api-key-1"
seam = Seam(api_key=seed["seam_apikey1_token"], endpoint=endpoint)
devices = seam.devices.list()
assert len(devices) > 0
def test_seam_client_api_key_option_as_first_argument_overrides_env_variables():
os.environ["SEAM_API_KEY"] = "some-invalid-api-key-2"
seam = Seam("seam_apikey_token")
assert seam is not None
def test_seam_client_constructor_requires_seam_api_key_when_passed_no_argument():
with pytest.raises(SeamInvalidOptionsError, match=r"api_key"):
Seam()
def test_seam_client_seam_endpoint_env_variable_is_used_first(server):
endpoint, seed = server
os.environ["SEAM_API_URL"] = "https://example.com"
os.environ["SEAM_ENDPOINT"] = endpoint
seam = Seam(api_key=seed["seam_apikey1_token"])
devices = seam.devices.list()
assert len(devices) > 0
def test_seam_client_seam_api_url_env_variable_is_used_as_fallback(server):
endpoint, seed = server
os.environ["SEAM_API_URL"] = endpoint
seam = Seam(api_key=seed["seam_apikey1_token"])
devices = seam.devices.list()
assert len(devices) > 0
def test_seam_client_endpoint_option_overrides_env_variables(server):
endpoint, seed = server
os.environ["SEAM_API_URL"] = "https://example.com"
os.environ["SEAM_ENDPOINT"] = "https://example.com"
seam = Seam(api_key=seed["seam_apikey1_token"], endpoint=endpoint)
devices = seam.devices.list()
assert len(devices) > 0
def test_seam_client_seam_endpoint_env_variable_is_used_with_from_api_key(
server,
):
endpoint, seed = server
os.environ["SEAM_API_URL"] = "https://example.com"
os.environ["SEAM_ENDPOINT"] = endpoint
seam = Seam.from_api_key(seed["seam_apikey1_token"])
devices = seam.devices.list()
assert len(devices) > 0
@pytest.mark.xfail(reason="Fake does not support personal access token.")
def test_seam_client_seam_api_key_env_variable_is_ignored_with_personal_access_token(
server,
):
endpoint, seed = server
os.environ["SEAM_API_KEY"] = seed["seam_apikey1_token"]
seam = Seam.from_personal_access_token(
seed["seam_at1_token"],
seed["seed_workspace_1"],
endpoint=endpoint,
)
devices = seam.devices.list()
assert len(devices) > 0