2019-05-19 14:20:32 +00:00
|
|
|
import os
|
2019-10-13 21:15:36 +00:00
|
|
|
import time
|
2019-05-19 14:20:32 +00:00
|
|
|
|
|
|
|
import testinfra.utils.ansible_runner
|
|
|
|
|
2019-10-13 21:15:36 +00:00
|
|
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
|
|
|
2019-05-19 14:20:32 +00:00
|
|
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
2021-06-07 20:29:00 +00:00
|
|
|
os.environ["MOLECULE_INVENTORY_FILE"]
|
|
|
|
).get_hosts("all")
|
2019-05-19 14:20:32 +00:00
|
|
|
|
|
|
|
|
2021-03-14 16:46:46 +00:00
|
|
|
def test_homeassistant_running(host):
|
|
|
|
homeassistant = host.docker("homeassistant")
|
2019-10-13 21:15:36 +00:00
|
|
|
|
2021-03-14 16:46:46 +00:00
|
|
|
assert homeassistant.is_running
|
2019-10-13 21:15:36 +00:00
|
|
|
|
2021-03-14 16:46:46 +00:00
|
|
|
|
|
|
|
def test_homeassistant_socket(host):
|
2019-10-13 21:15:36 +00:00
|
|
|
# Verify the socket is listening for HTTP traffic
|
|
|
|
for _ in range(30):
|
2021-03-14 16:46:46 +00:00
|
|
|
if host.socket("tcp://127.0.0.1:8123").is_listening:
|
2019-10-13 21:15:36 +00:00
|
|
|
break
|
|
|
|
time.sleep(1)
|
2019-05-19 14:20:32 +00:00
|
|
|
|
2021-03-14 16:46:46 +00:00
|
|
|
assert host.socket("tcp://127.0.0.1:8123").is_listening
|
|
|
|
|
|
|
|
|
|
|
|
def test_homeassistant_conn_error(host):
|
|
|
|
code = int(host.run("curl -sL -w '%{http_code}' http://127.0.0.1:8123/ -o /dev/null").stdout)
|
|
|
|
body = host.run("curl -sLX GET http://127.0.0.1:8123/").stdout
|
|
|
|
|
|
|
|
assert code == 200
|
|
|
|
assert "Home Assistant" in body
|