Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_login(self):
recorder = betamax.Betamax(self.session)
with recorder.use_cassette('basic'):
c = SomeComfort(self.username, self.password)
self.assertIn(self.location, c.locations_by_id)
self.assertIn(self.device,
c.locations_by_id[self.location].devices_by_id)
device = self._get_device(c)
self.assertEqual('THERMOSTAT', device.name)
def _test_device_set_attribute(self, attr, value):
# Thanks windows :(
attr = str(attr).replace(':', '')
value = str(value).replace(':', '')
recorder = betamax.Betamax(self.session)
with recorder.use_cassette('set-attr-%s-%s' % (attr, value)):
c = SomeComfort(self.username, self.password)
device = self._get_device(c)
setattr(device, attr, value)
self.assertEqual(value, getattr(device, attr))
def test_device_attributes(self):
recorder = betamax.Betamax(self.session)
with recorder.use_cassette('basic'):
c = SomeComfort(self.username, self.password)
device = self._get_device(c)
self.assertEqual('THERMOSTAT', device.name)
self.assertEqual(self.device, device.deviceid)
self.assertFalse(device.fan_running)
self.assertTrue(device.is_alive)
self.assertEqual(77.0, device.setpoint_cool)
self.assertEqual(58.0, device.setpoint_heat)
self.assertEqual(58.0, device.current_temperature)
self.assertEqual('F', device.temperature_unit)
self.assertEqual('heat', device.system_mode)
self.assertEqual('circulate', device.fan_mode)
self.assertEqual(True, device.hold_heat)
def test_setup_us_failures(self, mock_sc):
"""Test the US setup."""
hass = mock.MagicMock()
add_entities = mock.MagicMock()
config = {
CONF_USERNAME: "user",
CONF_PASSWORD: "pass",
honeywell.CONF_REGION: "us",
}
mock_sc.side_effect = somecomfort.AuthError
result = honeywell.setup_platform(hass, config, add_entities)
assert not result
assert not add_entities.called
mock_sc.side_effect = somecomfort.SomeComfortError
result = honeywell.setup_platform(hass, config, add_entities)
assert not result
assert not add_entities.called
def test_set_temp_fail(self):
"""Test if setting the temperature fails."""
self.device.setpoint_heat = mock.MagicMock(
side_effect=somecomfort.SomeComfortError
)
self.honeywell.set_temperature(temperature=123)
def test_setup_us_failures(self, mock_sc):
"""Test the US setup."""
hass = mock.MagicMock()
add_devices = mock.MagicMock()
config = {
CONF_USERNAME: 'user',
CONF_PASSWORD: 'pass',
'region': 'us',
}
mock_sc.side_effect = somecomfort.AuthError
result = honeywell.setup_platform(hass, config, add_devices)
self.assertFalse(result)
self.assertFalse(add_devices.called)
mock_sc.side_effect = somecomfort.SomeComfortError
result = honeywell.setup_platform(hass, config, add_devices)
self.assertFalse(result)
self.assertFalse(add_devices.called)
def test_set_temp_fail(self):
"""Test if setting the temperature fails."""
self.device.setpoint_heat = mock.MagicMock(
side_effect=somecomfort.SomeComfortError)
self.honeywell.set_temperature(123)
def test_login_failed(self):
recorder = betamax.Betamax(self.session)
with recorder.use_cassette('badlogin'):
self.assertRaises(somecomfort.AuthError,
SomeComfort, 'nosuchuser',
'definitelynotapassword')
def test_setup_us_failures(self, mock_sc):
"""Test the US setup."""
hass = mock.MagicMock()
add_devices = mock.MagicMock()
config = {
CONF_USERNAME: 'user',
CONF_PASSWORD: 'pass',
'region': 'us',
}
mock_sc.side_effect = somecomfort.AuthError
result = honeywell.setup_platform(hass, config, add_devices)
self.assertFalse(result)
self.assertFalse(add_devices.called)
mock_sc.side_effect = somecomfort.SomeComfortError
result = honeywell.setup_platform(hass, config, add_devices)
self.assertFalse(result)
self.assertFalse(add_devices.called)
def test_setup_us_failures(self, mock_sc):
"""Test the US setup."""
hass = mock.MagicMock()
add_entities = mock.MagicMock()
config = {
CONF_USERNAME: "user",
CONF_PASSWORD: "pass",
honeywell.CONF_REGION: "us",
}
mock_sc.side_effect = somecomfort.AuthError
result = honeywell.setup_platform(hass, config, add_entities)
assert not result
assert not add_entities.called
mock_sc.side_effect = somecomfort.SomeComfortError
result = honeywell.setup_platform(hass, config, add_entities)
assert not result
assert not add_entities.called