def test_invalid_switches(self, mock): """Test the VultrSwitch fails.""" mock.get( 'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567', text=load_fixture('vultr_account_info.json')) with patch('vultr.Vultr.server_list', return_value=json.loads( load_fixture('vultr_server_list.json'))): # Setup hub base_vultr.setup(self.hass, VALID_CONFIG) bad_conf = {} # No subscription no_subs_setup = vultr.setup_platform(self.hass, bad_conf, self.add_entities, None) self.assertIsNotNone(no_subs_setup) bad_conf = { CONF_NAME: "Missing Server", CONF_SUBSCRIPTION: '665544' } # Sub not associated with API key (not in server_list) wrong_subs_setup = vultr.setup_platform(self.hass, bad_conf, self.add_entities, None) self.assertIsNotNone(wrong_subs_setup)
def test_invalid_switches(self, mock): """Test the VultrSwitch fails.""" mock.get( 'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567', text=load_fixture('vultr_account_info.json')) mock.get( 'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567', text=load_fixture('vultr_server_list.json')) base_vultr.setup(self.hass, VALID_CONFIG) bad_conf = {} # No subscription no_subs_setup = vultr.setup_platform(self.hass, bad_conf, self.add_devices, None) self.assertIsNotNone(no_subs_setup) bad_conf = { CONF_NAME: "Missing Server", CONF_SUBSCRIPTION: '665544' } # Sub not associated with API key (not in server_list) wrong_subs_setup = vultr.setup_platform(self.hass, bad_conf, self.add_devices, None) self.assertIsNotNone(wrong_subs_setup)
def test_invalid_switches(self, mock): """Test the VultrSwitch fails.""" mock.get( 'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567', text=load_fixture('vultr_account_info.json')) with patch( 'vultr.Vultr.server_list', return_value=json.loads( load_fixture('vultr_server_list.json'))): # Setup hub base_vultr.setup(self.hass, VALID_CONFIG) bad_conf = {} # No subscription no_subs_setup = vultr.setup_platform(self.hass, bad_conf, self.add_entities, None) assert no_subs_setup is not None bad_conf = { CONF_NAME: "Missing Server", CONF_SUBSCRIPTION: '665544' } # Sub not associated with API key (not in server_list) wrong_subs_setup = vultr.setup_platform(self.hass, bad_conf, self.add_entities, None) assert wrong_subs_setup is not None
def test_switch(self, mock): """Test successful instance.""" mock.get( 'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567', text=load_fixture('vultr_account_info.json')) with patch('vultr.Vultr.server_list', return_value=json.loads( load_fixture('vultr_server_list.json'))): # Setup hub base_vultr.setup(self.hass, VALID_CONFIG) # Setup each of our test configs for config in self.configs: vultr.setup_platform(self.hass, config, self.add_entities, None) self.assertEqual(len(self.DEVICES), 3) tested = 0 for device in self.DEVICES: if device.subscription == '555555': self.assertEqual('Vultr {}', device.name) tested += 1 device.update() device_attrs = device.device_state_attributes if device.subscription == '555555': self.assertEqual('Vultr Another Server', device.name) tested += 1 if device.name == 'A Server': self.assertEqual(True, device.is_on) self.assertEqual('on', device.state) self.assertEqual('mdi:server', device.icon) self.assertEqual('1000', device_attrs[ATTR_ALLOWED_BANDWIDTH]) self.assertEqual('yes', device_attrs[ATTR_AUTO_BACKUPS]) self.assertEqual('123.123.123.123', device_attrs[ATTR_IPV4_ADDRESS]) self.assertEqual('10.05', device_attrs[ATTR_COST_PER_MONTH]) self.assertEqual('2013-12-19 14:45:41', device_attrs[ATTR_CREATED_AT]) self.assertEqual('576965', device_attrs[ATTR_SUBSCRIPTION_ID]) tested += 1 elif device.name == 'Failed Server': self.assertEqual(False, device.is_on) self.assertEqual('off', device.state) self.assertEqual('mdi:server-off', device.icon) self.assertEqual('1000', device_attrs[ATTR_ALLOWED_BANDWIDTH]) self.assertEqual('no', device_attrs[ATTR_AUTO_BACKUPS]) self.assertEqual('192.168.100.50', device_attrs[ATTR_IPV4_ADDRESS]) self.assertEqual('73.25', device_attrs[ATTR_COST_PER_MONTH]) self.assertEqual('2014-10-13 14:45:41', device_attrs[ATTR_CREATED_AT]) self.assertEqual('123456', device_attrs[ATTR_SUBSCRIPTION_ID]) tested += 1 self.assertEqual(4, tested)
def test_switch(self, mock): """Test successful instance.""" mock.get( 'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567', text=load_fixture('vultr_account_info.json')) mock.get( 'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567', text=load_fixture('vultr_server_list.json')) # Setup hub base_vultr.setup(self.hass, VALID_CONFIG) # Setup each of our test configs for config in self.configs: vultr.setup_platform(self.hass, config, self.add_devices, None) self.assertEqual(len(self.DEVICES), 3) tested = 0 for device in self.DEVICES: if device.subscription == '555555': self.assertEqual('Vultr {}', device.name) tested += 1 device.update() device_attrs = device.device_state_attributes if device.subscription == '555555': self.assertEqual('Vultr Another Server', device.name) tested += 1 if device.name == 'A Server': self.assertEqual(True, device.is_on) self.assertEqual('on', device.state) self.assertEqual('mdi:server', device.icon) self.assertEqual('1000', device_attrs[ATTR_ALLOWED_BANDWIDTH]) self.assertEqual('yes', device_attrs[ATTR_AUTO_BACKUPS]) self.assertEqual('123.123.123.123', device_attrs[ATTR_IPV4_ADDRESS]) self.assertEqual('10.05', device_attrs[ATTR_COST_PER_MONTH]) self.assertEqual('2013-12-19 14:45:41', device_attrs[ATTR_CREATED_AT]) self.assertEqual('576965', device_attrs[ATTR_SUBSCRIPTION_ID]) tested += 1 elif device.name == 'Failed Server': self.assertEqual(False, device.is_on) self.assertEqual('off', device.state) self.assertEqual('mdi:server-off', device.icon) self.assertEqual('1000', device_attrs[ATTR_ALLOWED_BANDWIDTH]) self.assertEqual('no', device_attrs[ATTR_AUTO_BACKUPS]) self.assertEqual('192.168.100.50', device_attrs[ATTR_IPV4_ADDRESS]) self.assertEqual('73.25', device_attrs[ATTR_COST_PER_MONTH]) self.assertEqual('2014-10-13 14:45:41', device_attrs[ATTR_CREATED_AT]) self.assertEqual('123456', device_attrs[ATTR_SUBSCRIPTION_ID]) tested += 1 self.assertEqual(4, tested)
def test_switch(self, mock): """Test successful instance.""" mock.get( 'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567', text=load_fixture('vultr_account_info.json')) with patch( 'vultr.Vultr.server_list', return_value=json.loads( load_fixture('vultr_server_list.json'))): # Setup hub base_vultr.setup(self.hass, VALID_CONFIG) # Setup each of our test configs for config in self.configs: vultr.setup_platform(self.hass, config, self.add_entities, None) assert len(self.DEVICES) == 3 tested = 0 for device in self.DEVICES: if device.subscription == '555555': assert 'Vultr {}' == device.name tested += 1 device.update() device_attrs = device.device_state_attributes if device.subscription == '555555': assert 'Vultr Another Server' == device.name tested += 1 if device.name == 'A Server': assert device.is_on is True assert 'on' == device.state assert 'mdi:server' == device.icon assert '1000' == \ device_attrs[ATTR_ALLOWED_BANDWIDTH] assert 'yes' == \ device_attrs[ATTR_AUTO_BACKUPS] assert '123.123.123.123' == \ device_attrs[ATTR_IPV4_ADDRESS] assert '10.05' == \ device_attrs[ATTR_COST_PER_MONTH] assert '2013-12-19 14:45:41' == \ device_attrs[ATTR_CREATED_AT] assert '576965' == \ device_attrs[ATTR_SUBSCRIPTION_ID] tested += 1 elif device.name == 'Failed Server': assert device.is_on is False assert 'off' == device.state assert 'mdi:server-off' == device.icon assert '1000' == \ device_attrs[ATTR_ALLOWED_BANDWIDTH] assert 'no' == \ device_attrs[ATTR_AUTO_BACKUPS] assert '192.168.100.50' == \ device_attrs[ATTR_IPV4_ADDRESS] assert '73.25' == \ device_attrs[ATTR_COST_PER_MONTH] assert '2014-10-13 14:45:41' == \ device_attrs[ATTR_CREATED_AT] assert '123456' == \ device_attrs[ATTR_SUBSCRIPTION_ID] tested += 1 assert 4 == tested