mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix vultr tests (#11477)
This commit is contained in:
parent
c714658384
commit
ff9688bb7a
@ -1,5 +1,8 @@
|
|||||||
"""Test the Vultr binary sensor platform."""
|
"""Test the Vultr binary sensor platform."""
|
||||||
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import requests_mock
|
import requests_mock
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -50,10 +53,6 @@ class TestVultrBinarySensorSetup(unittest.TestCase):
|
|||||||
"""Stop our started services."""
|
"""Stop our started services."""
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_failed_hub(self):
|
|
||||||
"""Test a hub setup failure."""
|
|
||||||
base_vultr.setup(self.hass, VALID_CONFIG)
|
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_binary_sensor(self, mock):
|
def test_binary_sensor(self, mock):
|
||||||
"""Test successful instance."""
|
"""Test successful instance."""
|
||||||
@ -61,10 +60,10 @@ class TestVultrBinarySensorSetup(unittest.TestCase):
|
|||||||
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
||||||
text=load_fixture('vultr_account_info.json'))
|
text=load_fixture('vultr_account_info.json'))
|
||||||
|
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(
|
||||||
|
load_fixture('vultr_server_list.json'))):
|
||||||
# Setup hub
|
# Setup hub
|
||||||
base_vultr.setup(self.hass, VALID_CONFIG)
|
base_vultr.setup(self.hass, VALID_CONFIG)
|
||||||
|
|
||||||
@ -137,10 +136,11 @@ class TestVultrBinarySensorSetup(unittest.TestCase):
|
|||||||
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
||||||
text=load_fixture('vultr_account_info.json'))
|
text=load_fixture('vultr_account_info.json'))
|
||||||
|
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(
|
||||||
|
load_fixture('vultr_server_list.json'))):
|
||||||
|
# Setup hub
|
||||||
base_vultr.setup(self.hass, VALID_CONFIG)
|
base_vultr.setup(self.hass, VALID_CONFIG)
|
||||||
|
|
||||||
bad_conf = {} # No subscription
|
bad_conf = {} # No subscription
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
"""The tests for the Vultr sensor platform."""
|
"""The tests for the Vultr sensor platform."""
|
||||||
import pytest
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
import requests_mock
|
import requests_mock
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -59,10 +62,11 @@ class TestVultrSensorSetup(unittest.TestCase):
|
|||||||
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
||||||
text=load_fixture('vultr_account_info.json'))
|
text=load_fixture('vultr_account_info.json'))
|
||||||
|
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(
|
||||||
|
load_fixture('vultr_server_list.json'))):
|
||||||
|
# Setup hub
|
||||||
base_vultr.setup(self.hass, VALID_CONFIG)
|
base_vultr.setup(self.hass, VALID_CONFIG)
|
||||||
|
|
||||||
for config in self.configs:
|
for config in self.configs:
|
||||||
@ -146,10 +150,11 @@ class TestVultrSensorSetup(unittest.TestCase):
|
|||||||
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
||||||
text=load_fixture('vultr_account_info.json'))
|
text=load_fixture('vultr_account_info.json'))
|
||||||
|
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(
|
||||||
|
load_fixture('vultr_server_list.json'))):
|
||||||
|
# Setup hub
|
||||||
base_vultr.setup(self.hass, VALID_CONFIG)
|
base_vultr.setup(self.hass, VALID_CONFIG)
|
||||||
|
|
||||||
bad_conf = {
|
bad_conf = {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
"""Test the Vultr switch platform."""
|
"""Test the Vultr switch platform."""
|
||||||
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import requests_mock
|
import requests_mock
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -57,10 +60,10 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
|||||||
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
||||||
text=load_fixture('vultr_account_info.json'))
|
text=load_fixture('vultr_account_info.json'))
|
||||||
|
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(
|
||||||
|
load_fixture('vultr_server_list.json'))):
|
||||||
# Setup hub
|
# Setup hub
|
||||||
base_vultr.setup(self.hass, VALID_CONFIG)
|
base_vultr.setup(self.hass, VALID_CONFIG)
|
||||||
|
|
||||||
@ -128,36 +131,30 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
|||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_turn_on(self, mock):
|
def test_turn_on(self, mock):
|
||||||
"""Test turning a subscription on."""
|
"""Test turning a subscription on."""
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(load_fixture('vultr_server_list.json'))), \
|
||||||
|
patch('vultr.Vultr.server_start') as mock_start:
|
||||||
mock.post(
|
|
||||||
'https://api.vultr.com/v1/server/start?api_key=ABCDEFG1234567')
|
|
||||||
|
|
||||||
for device in self.DEVICES:
|
for device in self.DEVICES:
|
||||||
if device.name == 'Failed Server':
|
if device.name == 'Failed Server':
|
||||||
device.turn_on()
|
device.turn_on()
|
||||||
|
|
||||||
# Turn on, force date update
|
# Turn on
|
||||||
self.assertEqual(2, mock.call_count)
|
self.assertEqual(1, mock_start.call_count)
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_turn_off(self, mock):
|
def test_turn_off(self, mock):
|
||||||
"""Test turning a subscription off."""
|
"""Test turning a subscription off."""
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(load_fixture('vultr_server_list.json'))), \
|
||||||
|
patch('vultr.Vultr.server_halt') as mock_halt:
|
||||||
mock.post(
|
|
||||||
'https://api.vultr.com/v1/server/halt?api_key=ABCDEFG1234567')
|
|
||||||
|
|
||||||
for device in self.DEVICES:
|
for device in self.DEVICES:
|
||||||
if device.name == 'A Server':
|
if device.name == 'A Server':
|
||||||
device.turn_off()
|
device.turn_off()
|
||||||
|
|
||||||
# Turn off, force update
|
# Turn off
|
||||||
self.assertEqual(2, mock.call_count)
|
self.assertEqual(1, mock_halt.call_count)
|
||||||
|
|
||||||
def test_invalid_switch_config(self):
|
def test_invalid_switch_config(self):
|
||||||
"""Test config type failures."""
|
"""Test config type failures."""
|
||||||
@ -173,10 +170,11 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
|||||||
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
||||||
text=load_fixture('vultr_account_info.json'))
|
text=load_fixture('vultr_account_info.json'))
|
||||||
|
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_server_list.json'))
|
return_value=json.loads(
|
||||||
|
load_fixture('vultr_server_list.json'))):
|
||||||
|
# Setup hub
|
||||||
base_vultr.setup(self.hass, VALID_CONFIG)
|
base_vultr.setup(self.hass, VALID_CONFIG)
|
||||||
|
|
||||||
bad_conf = {} # No subscription
|
bad_conf = {} # No subscription
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
"""The tests for the Vultr component."""
|
"""The tests for the Vultr component."""
|
||||||
|
from copy import deepcopy
|
||||||
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import requests_mock
|
import requests_mock
|
||||||
|
|
||||||
from copy import deepcopy
|
|
||||||
from homeassistant import setup
|
from homeassistant import setup
|
||||||
import homeassistant.components.vultr as vultr
|
import homeassistant.components.vultr as vultr
|
||||||
|
|
||||||
@ -31,13 +34,10 @@ class TestVultr(unittest.TestCase):
|
|||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup(self, mock):
|
def test_setup(self, mock):
|
||||||
"""Test successful setup."""
|
"""Test successful setup."""
|
||||||
mock.get(
|
with patch(
|
||||||
'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
|
'vultr.Vultr.server_list',
|
||||||
text=load_fixture('vultr_account_info.json'))
|
return_value=json.loads(
|
||||||
mock.get(
|
load_fixture('vultr_server_list.json'))):
|
||||||
'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
|
|
||||||
text=load_fixture('vultr_server_list.json'))
|
|
||||||
|
|
||||||
response = vultr.setup(self.hass, self.config)
|
response = vultr.setup(self.hass, self.config)
|
||||||
self.assertTrue(response)
|
self.assertTrue(response)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user