-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
test.py
48 lines (35 loc) · 1.34 KB
/
test.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
import os
import pytest
from haaska import HomeAssistant, Configuration
@pytest.fixture
def configuration():
return Configuration(opts_dict={
"url": "http://localhost:8123",
"bearer_token": "",
"debug": False,
"ssl_verify": True,
"ssl_client": []
})
@pytest.fixture
def home_assistant(configuration):
return HomeAssistant(configuration)
def test_ha_build_url(home_assistant):
url = home_assistant.build_url("test")
assert url == "http://localhost:8123/api/test"
def test_get_user_agent(home_assistant):
os.environ["AWS_DEFAULT_REGION"] = "test"
user_agent = home_assistant.get_user_agent()
assert user_agent.startswith("Home Assistant Alexa Smart Home Skill - test - python-requests/")
def test_config_get(configuration):
assert configuration.get(["debug"]) is False
assert configuration.get(["test"]) is None
assert configuration.get(["test"], default="default") == "default"
def test_config_get_url(configuration):
test_urls = [
"http://hass.example.com:8123",
"http://hass.example.app"
]
for expected_url in test_urls:
assert configuration.get_url(expected_url + "/") == expected_url
assert configuration.get_url(expected_url + "/api") == expected_url
assert configuration.get_url(expected_url + "/api/") == expected_url