core/tests/components/vultr/test_init.py

49 lines
1.3 KiB
Python
Raw Normal View History

Add platform and sensors for Vultr VPS (#9928) * Initial commit of Vultr components Have a working Vultr hub and binary sensor which pulls down the following attributes of your VPS: - Date created - Subscription id (server id) - Cost per month (in US$) - Operating System installed - IPv4 address - label (human readable name) - region - number of vcpus - which storage package chosen - IPV6 address (if applicable) - RAM amount Working next on sensor and then testing / coverage. * Added Vultr sensor for pending charges and current bandwidth. Refactored binary_sensor and hub too * Corrected is_on bases * Added basic tests for Vultr binary & platform * Updated require files * Changing test fixture to highlight different cases * Written basic test for sensor.vultr * Resolved linting errors and broken test * Increase test coverage and corrected docs * Resolved hound issues * Revert back negative binary test * Another hound resolve * Refactoring and adding is switch, moving over to vultr branch * Made Vultr components more resiliant to invalid configs * Added negetive test for vultr binary sensor * Added better testing of vultr sensor * Resolved vultr platform test affecting subsequent vultr tests * Moving VULTR components to single use design * Added in sensor name config * Added missing sensors var * Resolved init data setting of sensors, added in name conf to switch * Made the Vultr component more resiliant to startup failure with better alerting * Various Vultr component changes - Refactored sensor, binary_sensor, and switch to reference one subscription - Renamed CURRENT_BANDWIDTH_GB monitored condition to CURRENT_BANDWIDTH_USED - Improved test coverage * Resolved local tox linting issue * Added more testing for Vultr switch * Improved test coverage for Vultr components * Made PR comment changes to vultr binary sensor * Made PR comment changes to Vultr sensor * resolved PR comments for Vultr Switch * Resolved vultr sensor name and improved tests * Improved Vultr switch testing (default name formatting) * Removed vultr hub failure checking
2017-11-05 13:10:14 +00:00
"""The tests for the Vultr component."""
2018-01-06 00:34:03 +00:00
from copy import deepcopy
import json
Add platform and sensors for Vultr VPS (#9928) * Initial commit of Vultr components Have a working Vultr hub and binary sensor which pulls down the following attributes of your VPS: - Date created - Subscription id (server id) - Cost per month (in US$) - Operating System installed - IPv4 address - label (human readable name) - region - number of vcpus - which storage package chosen - IPV6 address (if applicable) - RAM amount Working next on sensor and then testing / coverage. * Added Vultr sensor for pending charges and current bandwidth. Refactored binary_sensor and hub too * Corrected is_on bases * Added basic tests for Vultr binary & platform * Updated require files * Changing test fixture to highlight different cases * Written basic test for sensor.vultr * Resolved linting errors and broken test * Increase test coverage and corrected docs * Resolved hound issues * Revert back negative binary test * Another hound resolve * Refactoring and adding is switch, moving over to vultr branch * Made Vultr components more resiliant to invalid configs * Added negetive test for vultr binary sensor * Added better testing of vultr sensor * Resolved vultr platform test affecting subsequent vultr tests * Moving VULTR components to single use design * Added in sensor name config * Added missing sensors var * Resolved init data setting of sensors, added in name conf to switch * Made the Vultr component more resiliant to startup failure with better alerting * Various Vultr component changes - Refactored sensor, binary_sensor, and switch to reference one subscription - Renamed CURRENT_BANDWIDTH_GB monitored condition to CURRENT_BANDWIDTH_USED - Improved test coverage * Resolved local tox linting issue * Added more testing for Vultr switch * Improved test coverage for Vultr components * Made PR comment changes to vultr binary sensor * Made PR comment changes to Vultr sensor * resolved PR comments for Vultr Switch * Resolved vultr sensor name and improved tests * Improved Vultr switch testing (default name formatting) * Removed vultr hub failure checking
2017-11-05 13:10:14 +00:00
import unittest
2018-01-06 00:34:03 +00:00
from unittest.mock import patch
Add platform and sensors for Vultr VPS (#9928) * Initial commit of Vultr components Have a working Vultr hub and binary sensor which pulls down the following attributes of your VPS: - Date created - Subscription id (server id) - Cost per month (in US$) - Operating System installed - IPv4 address - label (human readable name) - region - number of vcpus - which storage package chosen - IPV6 address (if applicable) - RAM amount Working next on sensor and then testing / coverage. * Added Vultr sensor for pending charges and current bandwidth. Refactored binary_sensor and hub too * Corrected is_on bases * Added basic tests for Vultr binary & platform * Updated require files * Changing test fixture to highlight different cases * Written basic test for sensor.vultr * Resolved linting errors and broken test * Increase test coverage and corrected docs * Resolved hound issues * Revert back negative binary test * Another hound resolve * Refactoring and adding is switch, moving over to vultr branch * Made Vultr components more resiliant to invalid configs * Added negetive test for vultr binary sensor * Added better testing of vultr sensor * Resolved vultr platform test affecting subsequent vultr tests * Moving VULTR components to single use design * Added in sensor name config * Added missing sensors var * Resolved init data setting of sensors, added in name conf to switch * Made the Vultr component more resiliant to startup failure with better alerting * Various Vultr component changes - Refactored sensor, binary_sensor, and switch to reference one subscription - Renamed CURRENT_BANDWIDTH_GB monitored condition to CURRENT_BANDWIDTH_USED - Improved test coverage * Resolved local tox linting issue * Added more testing for Vultr switch * Improved test coverage for Vultr components * Made PR comment changes to vultr binary sensor * Made PR comment changes to Vultr sensor * resolved PR comments for Vultr Switch * Resolved vultr sensor name and improved tests * Improved Vultr switch testing (default name formatting) * Removed vultr hub failure checking
2017-11-05 13:10:14 +00:00
import requests_mock
from homeassistant import setup
2017-11-11 20:24:43 +00:00
import homeassistant.components.vultr as vultr
Add platform and sensors for Vultr VPS (#9928) * Initial commit of Vultr components Have a working Vultr hub and binary sensor which pulls down the following attributes of your VPS: - Date created - Subscription id (server id) - Cost per month (in US$) - Operating System installed - IPv4 address - label (human readable name) - region - number of vcpus - which storage package chosen - IPV6 address (if applicable) - RAM amount Working next on sensor and then testing / coverage. * Added Vultr sensor for pending charges and current bandwidth. Refactored binary_sensor and hub too * Corrected is_on bases * Added basic tests for Vultr binary & platform * Updated require files * Changing test fixture to highlight different cases * Written basic test for sensor.vultr * Resolved linting errors and broken test * Increase test coverage and corrected docs * Resolved hound issues * Revert back negative binary test * Another hound resolve * Refactoring and adding is switch, moving over to vultr branch * Made Vultr components more resiliant to invalid configs * Added negetive test for vultr binary sensor * Added better testing of vultr sensor * Resolved vultr platform test affecting subsequent vultr tests * Moving VULTR components to single use design * Added in sensor name config * Added missing sensors var * Resolved init data setting of sensors, added in name conf to switch * Made the Vultr component more resiliant to startup failure with better alerting * Various Vultr component changes - Refactored sensor, binary_sensor, and switch to reference one subscription - Renamed CURRENT_BANDWIDTH_GB monitored condition to CURRENT_BANDWIDTH_USED - Improved test coverage * Resolved local tox linting issue * Added more testing for Vultr switch * Improved test coverage for Vultr components * Made PR comment changes to vultr binary sensor * Made PR comment changes to Vultr sensor * resolved PR comments for Vultr Switch * Resolved vultr sensor name and improved tests * Improved Vultr switch testing (default name formatting) * Removed vultr hub failure checking
2017-11-05 13:10:14 +00:00
from tests.common import (
get_test_home_assistant, load_fixture)
VALID_CONFIG = {
'vultr': {
'api_key': 'ABCDEFG1234567'
}
}
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
def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that we started."""
self.hass.stop()
@requests_mock.Mocker()
def test_setup(self, mock):
"""Test successful setup."""
2018-01-06 00:34:03 +00:00
with patch(
'vultr.Vultr.server_list',
return_value=json.loads(
load_fixture('vultr_server_list.json'))):
response = vultr.setup(self.hass, self.config)
assert response
Add platform and sensors for Vultr VPS (#9928) * Initial commit of Vultr components Have a working Vultr hub and binary sensor which pulls down the following attributes of your VPS: - Date created - Subscription id (server id) - Cost per month (in US$) - Operating System installed - IPv4 address - label (human readable name) - region - number of vcpus - which storage package chosen - IPV6 address (if applicable) - RAM amount Working next on sensor and then testing / coverage. * Added Vultr sensor for pending charges and current bandwidth. Refactored binary_sensor and hub too * Corrected is_on bases * Added basic tests for Vultr binary & platform * Updated require files * Changing test fixture to highlight different cases * Written basic test for sensor.vultr * Resolved linting errors and broken test * Increase test coverage and corrected docs * Resolved hound issues * Revert back negative binary test * Another hound resolve * Refactoring and adding is switch, moving over to vultr branch * Made Vultr components more resiliant to invalid configs * Added negetive test for vultr binary sensor * Added better testing of vultr sensor * Resolved vultr platform test affecting subsequent vultr tests * Moving VULTR components to single use design * Added in sensor name config * Added missing sensors var * Resolved init data setting of sensors, added in name conf to switch * Made the Vultr component more resiliant to startup failure with better alerting * Various Vultr component changes - Refactored sensor, binary_sensor, and switch to reference one subscription - Renamed CURRENT_BANDWIDTH_GB monitored condition to CURRENT_BANDWIDTH_USED - Improved test coverage * Resolved local tox linting issue * Added more testing for Vultr switch * Improved test coverage for Vultr components * Made PR comment changes to vultr binary sensor * Made PR comment changes to Vultr sensor * resolved PR comments for Vultr Switch * Resolved vultr sensor name and improved tests * Improved Vultr switch testing (default name formatting) * Removed vultr hub failure checking
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)
del conf['vultr']['api_key']
assert not setup.setup_component(self.hass, vultr.DOMAIN, conf)