2017-11-05 13:10:14 +00:00
|
|
|
"""The tests for the Vultr component."""
|
2018-01-05 16:34:03 -08:00
|
|
|
from copy import deepcopy
|
|
|
|
import json
|
2017-11-05 13:10:14 +00:00
|
|
|
import unittest
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import patch
|
2018-01-05 16:34:03 -08:00
|
|
|
|
2017-11-05 13:10:14 +00:00
|
|
|
import requests_mock
|
|
|
|
|
|
|
|
from homeassistant import setup
|
2017-11-11 22:24:43 +02:00
|
|
|
import homeassistant.components.vultr as vultr
|
2017-11-05 13:10:14 +00:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
from tests.common import get_test_home_assistant, load_fixture
|
2017-11-05 13:10:14 +00:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
VALID_CONFIG = {"vultr": {"api_key": "ABCDEFG1234567"}}
|
2017-11-05 13:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestVultr(unittest.TestCase):
|
|
|
|
"""Tests the Vultr component."""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""Initialize values for this test case class."""
|
|
|
|
self.hass = get_test_home_assistant()
|
|
|
|
self.config = VALID_CONFIG
|
2020-06-08 12:26:40 -07:00
|
|
|
self.addCleanup(self.tear_down_cleanup)
|
2017-11-05 13:10:14 +00:00
|
|
|
|
2020-06-08 12:26:40 -07:00
|
|
|
def tear_down_cleanup(self):
|
2017-11-05 13:10:14 +00:00
|
|
|
"""Stop everything that we started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
@requests_mock.Mocker()
|
|
|
|
def test_setup(self, mock):
|
|
|
|
"""Test successful setup."""
|
2018-01-05 16:34:03 -08:00
|
|
|
with patch(
|
2019-07-31 12:25:30 -07:00
|
|
|
"vultr.Vultr.server_list",
|
2021-11-01 20:47:05 -07:00
|
|
|
return_value=json.loads(load_fixture("server_list.json", "vultr")),
|
2019-07-31 12:25:30 -07:00
|
|
|
):
|
2018-01-05 16:34:03 -08:00
|
|
|
response = vultr.setup(self.hass, self.config)
|
2018-10-24 12:10:05 +02:00
|
|
|
assert response
|
2017-11-05 13:10:14 +00:00
|
|
|
|
|
|
|
def test_setup_no_api_key(self):
|
|
|
|
"""Test failed setup with missing API Key."""
|
|
|
|
conf = deepcopy(self.config)
|
2019-07-31 12:25:30 -07:00
|
|
|
del conf["vultr"]["api_key"]
|
2017-11-05 13:10:14 +00:00
|
|
|
assert not setup.setup_component(self.hass, vultr.DOMAIN, conf)
|