/
check_setup.py
89 lines (68 loc) · 2.63 KB
/
check_setup.py
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
import os
import requests
from vortexasdk.endpoints.endpoints import API_FQDN
all_tests_pass = True
def check_api_key_present():
global all_tests_pass
api_key = os.getenv("VORTEXA_API_KEY")
if api_key is None:
print("Environment variable VORTEXA_API_KEY is not set.")
print(
" Please set this environment variable, this is the recommended way to authenticate with the SDK."
"\n You may need to restart your python interpreter / bash terminal for the API Key to be ingested."
"\n Note: The SDK will work without an environment variable, you'll be prompted to interactively enter your password."
)
else:
print("Environment variable VORTEXA_API_KEY is set correctly.")
def check_can_connect_to_vortexa_api():
global all_tests_pass
url = f"{API_FQDN}/health-check"
try:
response = requests.get(url)
reason, status_code = response.reason, response.status_code
except Exception:
reason, status_code = None, None
if status_code == 200:
print(f"Python successfully connected to {url}")
else:
all_tests_pass = False
print(f"Python unable to connect to {url}")
print(f" status code: {status_code}")
print(f" reason: {reason}")
print(f" Check your internet connectivity / VPN settings.")
def check_can_import_vortexasdk():
global all_tests_pass
try:
import vortexasdk # noqa: F401
print("Python successfully imported vortexasdk")
except ImportError:
all_tests_pass = False
print("Python unable to import vortexasdk")
def check_can_retrieve_geographies():
global all_tests_pass
# noinspection PyBroadException
try:
from vortexasdk import Geographies
europe = (
"f39d455f5d38907394d6da3a91da4e391f9a34bd6a17e826d6042761067e88f4"
)
geography = Geographies().reference(europe)
assert geography["id"] == europe
print("Python successfully retrieved a sample piece of reference data")
except Exception as e:
all_tests_pass = False
print(e)
print("Python unable to retrieve a sample piece of reference data")
def run_all_checks():
print("Running Vortexa SDK setup check")
check_api_key_present()
check_can_connect_to_vortexa_api()
check_can_import_vortexasdk()
check_can_retrieve_geographies()
if all_tests_pass:
print("All tests passed, the SDK is correctly setup!")
else:
print("One or more tests have failed.")
print()
if __name__ == "__main__":
run_all_checks()