desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test that the limiter is a noop if no delay set.'
| def test_call_rate_delay_throttle_disabled(self):
| runs = []
limit = pilight.CallRateDelayThrottle(self.hass, 0.0)
action = limit.limited((lambda x: runs.append(x)))
for i in range(3):
action(i)
self.assertEqual(runs, [0, 1, 2])
|
'Test that throttling actually work.'
| def test_call_rate_delay_throttle_enabled(self):
| runs = []
delay = 5.0
limit = pilight.CallRateDelayThrottle(self.hass, delay)
action = limit.limited((lambda x: runs.append(x)))
for i in range(3):
action(i)
self.assertEqual(runs, [])
exp = []
now = dt_util.utcnow()
for i in range(3):
exp.append(i)
shifted_ti... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
|
'Test if platform validation was done.'
| def test_ensure_device_tracker_platform_validation(self):
| @asyncio.coroutine
def mock_setup_scanner(hass, config, see, discovery_info=None):
'Check that Qos was added by validation.'
self.assertTrue(('qos' in config))
with patch('homeassistant.components.device_tracker.mqtt.async_setup_scanner', autospec=True, side_effect=mock_set... |
'Test new message.'
| def test_new_message(self):
| dev_id = 'paulus'
enttiy_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
topic = '/location/paulus'
location = 'work'
self.hass.config.components = set(['mqtt', 'zone'])
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'mqtt', 'devices': {dev_i... |
'Setup things to be run when tests are started.'
| def setup_method(self, _):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'zone')
|
'Stop everything that was started.'
| def teardown_method(self, _):
| self.hass.stop()
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
|
'Test creating an AsusWRT scanner without a pass or pubkey.'
| def test_password_or_pub_key_required(self):
| with assert_setup_component(0, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'asuswrt', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user'}})
|
'Test creating an AsusWRT scanner with a password and no pubkey.'
| @mock.patch('homeassistant.components.device_tracker.asuswrt.AsusWrtDeviceScanner', return_value=mock.MagicMock())
def test_get_scanner_with_password_no_pubkey(self, asuswrt_mock):
| conf_dict = {DOMAIN: {CONF_PLATFORM: 'asuswrt', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user', CONF_PASSWORD: 'fake_pass', CONF_TRACK_NEW: True, CONF_CONSIDER_HOME: timedelta(seconds=180)}}
with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, conf_dict)
conf_dict[DO... |
'Test creating an AsusWRT scanner with a pubkey and no password.'
| @mock.patch('homeassistant.components.device_tracker.asuswrt.AsusWrtDeviceScanner', return_value=mock.MagicMock())
def test_get_scanner_with_pubkey_no_password(self, asuswrt_mock):
| conf_dict = {device_tracker.DOMAIN: {CONF_PLATFORM: 'asuswrt', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user', CONF_PUB_KEY: FAKEFILE, CONF_TRACK_NEW: True, CONF_CONSIDER_HOME: timedelta(seconds=180)}}
with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, conf_dict)
c... |
'Test that login is done with pub_key when configured to.'
| def test_ssh_login_with_pub_key(self):
| ssh = mock.MagicMock()
ssh_mock = mock.patch('pexpect.pxssh.pxssh', return_value=ssh)
ssh_mock.start()
self.addCleanup(ssh_mock.stop)
conf_dict = PLATFORM_SCHEMA({CONF_PLATFORM: 'asuswrt', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user', CONF_PUB_KEY: FAKEFILE})
update_mock = mock.patch('home... |
'Test that login is done with password when configured to.'
| def test_ssh_login_with_password(self):
| ssh = mock.MagicMock()
ssh_mock = mock.patch('pexpect.pxssh.pxssh', return_value=ssh)
ssh_mock.start()
self.addCleanup(ssh_mock.stop)
conf_dict = PLATFORM_SCHEMA({CONF_PLATFORM: 'asuswrt', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user', CONF_PASSWORD: 'fake_pass'})
update_mock = mock.patch('... |
'Test that login is not called without password or pub_key.'
| def test_ssh_login_without_password_or_pubkey(self):
| ssh = mock.MagicMock()
ssh_mock = mock.patch('pexpect.pxssh.pxssh', return_value=ssh)
ssh_mock.start()
self.addCleanup(ssh_mock.stop)
conf_dict = {CONF_PLATFORM: 'asuswrt', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user'}
with self.assertRaises(vol.Invalid):
conf_dict = PLATFORM_SCHEM... |
'Test that login is done with password when configured to.'
| def test_telnet_login_with_password(self):
| telnet = mock.MagicMock()
telnet_mock = mock.patch('telnetlib.Telnet', return_value=telnet)
telnet_mock.start()
self.addCleanup(telnet_mock.stop)
conf_dict = PLATFORM_SCHEMA({CONF_PLATFORM: 'asuswrt', CONF_PROTOCOL: 'telnet', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user', CONF_PASSWORD: 'fake_p... |
'Test that login is not called without password or pub_key.'
| def test_telnet_login_without_password(self):
| telnet = mock.MagicMock()
telnet_mock = mock.patch('telnetlib.Telnet', return_value=telnet)
telnet_mock.start()
self.addCleanup(telnet_mock.stop)
conf_dict = {CONF_PLATFORM: 'asuswrt', CONF_PROTOCOL: 'telnet', CONF_HOST: 'fake_host', CONF_USERNAME: 'fake_user'}
with self.assertRaises(vol.Invalid... |
'Test the setup with minimal configuration.'
| @patch('{}._get_homehub_data'.format(patch_file), new=_get_homehub_data)
def test_config_minimal(self):
| config = {'device_tracker': {CONF_HOST: 'foo'}}
result = bt_home_hub_5.get_scanner(None, config)
self.assertIsNotNone(result)
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
|
'Test if platform validation was done.'
| def test_ensure_device_tracker_platform_validation(self):
| @asyncio.coroutine
def mock_setup_scanner(hass, config, see, discovery_info=None):
'Check that Qos was added by validation.'
self.assertTrue(('qos' in config))
with patch('homeassistant.components.device_tracker.mqtt_json.async_setup_scanner', autospec=True, side_effect=moc... |
'Test json location message.'
| def test_json_message(self):
| dev_id = 'zanzito'
topic = 'location/zanzito'
location = json.dumps(LOCATION_MESSAGE)
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'mqtt_json', 'devices': {dev_id: topic}}})
fire_mqtt_message(self.hass, topic, location)
self.hass.block_till_don... |
'Test receiving a non JSON message.'
| def test_non_json_message(self):
| dev_id = 'zanzito'
topic = 'location/zanzito'
location = 'home'
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'mqtt_json', 'devices': {dev_id: topic}}})
with self.assertLogs(level='ERROR') as test_handle:
fire_mqtt_message(self.hass, topic, ... |
'Test receiving an incomplete message.'
| def test_incomplete_message(self):
| dev_id = 'zanzito'
topic = 'location/zanzito'
location = json.dumps(LOCATION_MESSAGE_INCOMPLETE)
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'mqtt_json', 'devices': {dev_id: topic}}})
with self.assertLogs(level='ERROR') as test_handle:
fir... |
'Mock out http calls to macvendor API for whole test suite.'
| def run(self, result=None):
| with mock_aiohttp_client() as aioclient_mock:
macvendor_re = re.compile('http://api.macvendors.com/.*')
aioclient_mock.get(macvendor_re, text='')
super().run(result)
|
'Setup things to be run when tests are started.'
| def setup_method(self, _):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'zone')
|
'Stop everything that was started.'
| def teardown_method(self, _):
| self.hass.stop()
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
|
'Create a Ddwrt scanner with wrong credentials.'
| @mock.patch('homeassistant.components.device_tracker.ddwrt._LOGGER.error')
def test_login_failed(self, mock_error):
| with requests_mock.Mocker() as mock_request:
mock_request.register_uri('GET', ('http://%s/Status_Wireless.live.asp' % TEST_HOST), status_code=401)
with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'ddwrt', CONF_HOST: TEST_HOST, CON... |
'Test error handling when response has an error status.'
| @mock.patch('homeassistant.components.device_tracker.ddwrt._LOGGER.error')
def test_invalid_response(self, mock_error):
| with requests_mock.Mocker() as mock_request:
mock_request.register_uri('GET', ('http://%s/Status_Wireless.live.asp' % TEST_HOST), status_code=444)
with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'ddwrt', CONF_HOST: TEST_HOST, CON... |
'Create a Ddwrt scanner with no response in init, should fail.'
| @mock.patch('homeassistant.components.device_tracker._LOGGER.error')
@mock.patch('homeassistant.components.device_tracker.ddwrt.DdWrtDeviceScanner.get_ddwrt_data', return_value=None)
def test_no_response(self, data_mock, error_mock):
| with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'ddwrt', CONF_HOST: TEST_HOST, CONF_USERNAME: 'fake_user', CONF_PASSWORD: '0'}})
self.assertTrue(('Error setting up platform' in str(error_mock.call_args_list[(-1)])))
|
'Test get Ddwrt data with request time out.'
| @mock.patch('homeassistant.components.device_tracker.ddwrt.requests.get', side_effect=requests.exceptions.Timeout)
@mock.patch('homeassistant.components.device_tracker.ddwrt._LOGGER.error')
def test_get_timeout(self, mock_error, mock_request):
| with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'ddwrt', CONF_HOST: TEST_HOST, CONF_USERNAME: 'fake_user', CONF_PASSWORD: '0'}})
self.assertTrue(('Connection to the router timed out' in str(mock_error.call_args_list[(-1)])))
|
'Test creating device info (MAC, name) from response.
The created known_devices.yaml device info is compared
to the DD-WRT Lan Status request response fixture.
This effectively checks the data parsing functions.'
| def test_scan_devices(self):
| with requests_mock.Mocker() as mock_request:
mock_request.register_uri('GET', ('http://%s/Status_Wireless.live.asp' % TEST_HOST), text=load_fixture('Ddwrt_Status_Wireless.txt'))
mock_request.register_uri('GET', ('http://%s/Status_Lan.live.asp' % TEST_HOST), text=load_fixture('Ddwrt_Status_Lan.txt'))... |
'Test creating device info (MAC only) when no response.'
| def test_device_name_no_data(self):
| with requests_mock.Mocker() as mock_request:
mock_request.register_uri('GET', ('http://%s/Status_Wireless.live.asp' % TEST_HOST), text=load_fixture('Ddwrt_Status_Wireless.txt'))
mock_request.register_uri('GET', ('http://%s/Status_Lan.live.asp' % TEST_HOST), text=None)
with assert_setup_compo... |
'Test creating device info (MAC) when missing dhcp response.'
| def test_device_name_no_dhcp(self):
| with requests_mock.Mocker() as mock_request:
mock_request.register_uri('GET', ('http://%s/Status_Wireless.live.asp' % TEST_HOST), text=load_fixture('Ddwrt_Status_Wireless.txt'))
mock_request.register_uri('GET', ('http://%s/Status_Lan.live.asp' % TEST_HOST), text=load_fixture('Ddwrt_Status_Lan.txt').... |
'Test error handling of no response when active devices checked.'
| def test_update_no_data(self):
| with requests_mock.Mocker() as mock_request:
mock_request.register_uri('GET', ('http://%s/Status_Wireless.live.asp' % TEST_HOST), [{'text': load_fixture('Ddwrt_Status_Wireless.txt')}, {'text': None}])
mock_request.register_uri('GET', ('http://%s/Status_Lan.live.asp' % TEST_HOST), text=load_fixture('... |
'Test error handling of bad response when active devices checked.'
| def test_update_wrong_data(self):
| with requests_mock.Mocker() as mock_request:
mock_request.register_uri('GET', ('http://%s/Status_Wireless.live.asp' % TEST_HOST), text=load_fixture('Ddwrt_Status_Wireless.txt').replace('active_wireless', 'missing'))
mock_request.register_uri('GET', ('http://%s/Status_Lan.live.asp' % TEST_HOST), text... |
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Testing minimal configuration.'
| @mock.patch('homeassistant.components.device_tracker.xiaomi.XiaomiDeviceScanner', return_value=mock.MagicMock())
def test_config(self, xiaomi_mock):
| config = {DOMAIN: xiaomi.PLATFORM_SCHEMA({CONF_PLATFORM: xiaomi.DOMAIN, CONF_HOST: '192.168.0.1', CONF_PASSWORD: 'passwordTest'})}
xiaomi.get_scanner(self.hass, config)
self.assertEqual(xiaomi_mock.call_count, 1)
self.assertEqual(xiaomi_mock.call_args, mock.call(config[DOMAIN]))
call_arg = xiaomi_mo... |
'Testing full configuration.'
| @mock.patch('homeassistant.components.device_tracker.xiaomi.XiaomiDeviceScanner', return_value=mock.MagicMock())
def test_config_full(self, xiaomi_mock):
| config = {DOMAIN: xiaomi.PLATFORM_SCHEMA({CONF_PLATFORM: xiaomi.DOMAIN, CONF_HOST: '192.168.0.1', CONF_USERNAME: 'alternativeAdminName', CONF_PASSWORD: 'passwordTest'})}
xiaomi.get_scanner(self.hass, config)
self.assertEqual(xiaomi_mock.call_count, 1)
self.assertEqual(xiaomi_mock.call_args, mock.call(co... |
'"Testing invalid credential handling.'
| @patch('requests.get', side_effect=mocked_requests)
@patch('requests.post', side_effect=mocked_requests)
def test_invalid_credential(self, mock_get, mock_post):
| config = {DOMAIN: xiaomi.PLATFORM_SCHEMA({CONF_PLATFORM: xiaomi.DOMAIN, CONF_HOST: '192.168.0.1', CONF_USERNAME: INVALID_USERNAME, CONF_PASSWORD: 'passwordTest'})}
self.assertIsNone(get_scanner(self.hass, config))
|
'"Testing valid refresh.'
| @patch('requests.get', side_effect=mocked_requests)
@patch('requests.post', side_effect=mocked_requests)
def test_valid_credential(self, mock_get, mock_post):
| config = {DOMAIN: xiaomi.PLATFORM_SCHEMA({CONF_PLATFORM: xiaomi.DOMAIN, CONF_HOST: '192.168.0.1', CONF_USERNAME: 'admin', CONF_PASSWORD: 'passwordTest'})}
scanner = get_scanner(self.hass, config)
self.assertIsNotNone(scanner)
self.assertEqual(2, len(scanner.scan_devices()))
self.assertEqual('Device1... |
'"Testing refresh with a timed out token.
New token is requested and list is downloaded a second time.'
| @patch('requests.get', side_effect=mocked_requests)
@patch('requests.post', side_effect=mocked_requests)
def test_token_timed_out(self, mock_get, mock_post):
| config = {DOMAIN: xiaomi.PLATFORM_SCHEMA({CONF_PLATFORM: xiaomi.DOMAIN, CONF_HOST: '192.168.0.1', CONF_USERNAME: TOKEN_TIMEOUT_USERNAME, CONF_PASSWORD: 'passwordTest'})}
scanner = get_scanner(self.hass, config)
self.assertIsNotNone(scanner)
self.assertEqual(2, len(scanner.scan_devices()))
self.asser... |
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'zone')
self.host = '127.0.0.1'
|
'Stop everything that was started.'
| def teardown_method(self):
| try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
self.hass.stop()
|
'Setup a platform.'
| @patch('homeassistant.components.device_tracker.upc_connect.UPCDeviceScanner.async_scan_devices', return_value=async_scan_devices_mock)
def test_setup_platform(self, scan_mock, aioclient_mock):
| aioclient_mock.get('http://{}/common_page/login.html'.format(self.host), cookies={'sessionToken': '654321'})
aioclient_mock.post('http://{}/xml/getter.xml'.format(self.host), content='successful')
with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFO... |
'Setup a platform with api timeout.'
| @patch('homeassistant.components.device_tracker._LOGGER.error')
def test_setup_platform_timeout_webservice(self, mock_error, aioclient_mock):
| aioclient_mock.get('http://{}/common_page/login.html'.format(self.host), cookies={'sessionToken': '654321'}, content='successful', exc=asyncio.TimeoutError())
with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'upc_connect', CONF_HOST: self.host}})... |
'Setup a platform with timeout on loginpage.'
| @patch('homeassistant.components.device_tracker._LOGGER.error')
def test_setup_platform_timeout_loginpage(self, mock_error, aioclient_mock):
| aioclient_mock.get('http://{}/common_page/login.html'.format(self.host), exc=asyncio.TimeoutError())
aioclient_mock.post('http://{}/xml/getter.xml'.format(self.host), content='successful')
with assert_setup_component(1, DOMAIN):
assert setup_component(self.hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: 'upc... |
'Setup a upc platform and scan device.'
| def test_scan_devices(self, aioclient_mock):
| aioclient_mock.get('http://{}/common_page/login.html'.format(self.host), cookies={'sessionToken': '654321'})
aioclient_mock.post('http://{}/xml/getter.xml'.format(self.host), content='successful', cookies={'sessionToken': '654321'})
scanner = run_coroutine_threadsafe(platform.async_get_scanner(self.hass, {D... |
'Setup a upc platform and scan device with no token.'
| def test_scan_devices_without_session(self, aioclient_mock):
| aioclient_mock.get('http://{}/common_page/login.html'.format(self.host), cookies={'sessionToken': '654321'})
aioclient_mock.post('http://{}/xml/getter.xml'.format(self.host), content='successful', cookies={'sessionToken': '654321'})
scanner = run_coroutine_threadsafe(platform.async_get_scanner(self.hass, {D... |
'Setup a upc platform and scan device with no token and wrong.'
| def test_scan_devices_without_session_wrong_re(self, aioclient_mock):
| aioclient_mock.get('http://{}/common_page/login.html'.format(self.host), cookies={'sessionToken': '654321'})
aioclient_mock.post('http://{}/xml/getter.xml'.format(self.host), content='successful', cookies={'sessionToken': '654321'})
scanner = run_coroutine_threadsafe(platform.async_get_scanner(self.hass, {D... |
'Setup a upc platform and scan device with parse error.'
| def test_scan_devices_parse_error(self, aioclient_mock):
| aioclient_mock.get('http://{}/common_page/login.html'.format(self.host), cookies={'sessionToken': '654321'})
aioclient_mock.post('http://{}/xml/getter.xml'.format(self.host), content='successful', cookies={'sessionToken': '654321'})
scanner = run_coroutine_threadsafe(platform.async_get_scanner(self.hass, {D... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
|
'Test grabbing the mac addresses from 2.4 and 5 GHz clients pages.'
| @requests_mock.mock()
def test_get_mac_addresses_from_both_bands(self, m):
| conf_dict = {CONF_PLATFORM: 'tplink', CONF_HOST: 'fake-host', CONF_USERNAME: 'fake_user', CONF_PASSWORD: 'fake_pass'}
FAKE_TOKEN = 'fake_token'
fake_auth_token_response = 'window.parent.location.href = "https://a/{}/userRpm/Index.htm";'.format(FAKE_TOKEN)
m.get('http://{}/userRpm/LoginRpm.htm?Save... |
'Test the sending of a message.'
| def send_message(self, topic, message, corrupt=False):
| str_message = json.dumps(message)
if corrupt:
mod_message = ((BAD_JSON_PREFIX + str_message) + BAD_JSON_SUFFIX)
else:
mod_message = str_message
fire_mqtt_message(self.hass, topic, mod_message)
self.hass.block_till_done()
|
'Test the assertion of a location state.'
| def assert_location_state(self, location):
| state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.state, location)
|
'Test the assertion of a location latitude.'
| def assert_location_latitude(self, latitude):
| state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.attributes.get('latitude'), latitude)
|
'Test the assertion of a location longitude.'
| def assert_location_longitude(self, longitude):
| state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.attributes.get('longitude'), longitude)
|
'Test the assertion of a location accuracy.'
| def assert_location_accuracy(self, accuracy):
| state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.attributes.get('gps_accuracy'), accuracy)
|
'Setup things to be run when tests are started.'
| def setup_method(self, _):
| self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks', CONF_MAX_GPS_ACCURACY: 200, CONF_WAYPOINT_IMPORT: True, CONF_WAYPO... |
'Stop everything that was started.'
| def teardown_method(self, _):
| self.hass.stop()
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
|
'Test the assertion of a tracker state.'
| def assert_tracker_state(self, location):
| state = self.hass.states.get(REGION_TRACKER_STATE)
self.assertEqual(state.state, location)
|
'Test the assertion of a tracker latitude.'
| def assert_tracker_latitude(self, latitude):
| state = self.hass.states.get(REGION_TRACKER_STATE)
self.assertEqual(state.attributes.get('latitude'), latitude)
|
'Test the assertion of a tracker accuracy.'
| def assert_tracker_accuracy(self, accuracy):
| state = self.hass.states.get(REGION_TRACKER_STATE)
self.assertEqual(state.attributes.get('gps_accuracy'), accuracy)
|
'Test the update of a location.'
| def test_location_invalid_devid(self):
| self.send_message('owntracks/paulus/nexus-5x', LOCATION_MESSAGE)
state = self.hass.states.get('device_tracker.paulus_nexus5x')
assert (state.state == 'outer')
|
'Test the update of a location.'
| def test_location_update(self):
| self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
self.assert_location_latitude(2.0)
self.assert_location_accuracy(60.0)
self.assert_location_state('outer')
|
'Test the location for inaccurate GPS information.'
| def test_location_inaccurate_gps(self):
| self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE_INACCURATE)
self.assert_location_latitude(2.0)
self.assert_location_longitude(1.0)
|
'Ignore the location for zero accuracy GPS information.'
| def test_location_zero_accuracy_gps(self):
| self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE_ZERO_ACCURACY)
self.assert_location_latitude(2.0)
self.assert_location_longitude(1.0)
|
'Test the entry event.'
| def test_event_entry_exit(self):
| self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_latitude(2.1)
self.assert_location_accuracy(10.0)
self.assert_location_state('inner')
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
self.assert_location_latitude(2.1)
self.assert_location_accuracy(10.0)
self.... |
'Test the entry event.'
| def test_event_with_spaces(self):
| message = REGION_ENTER_MESSAGE.copy()
message['desc'] = 'inner 2'
self.send_message(EVENT_TOPIC, message)
self.assert_location_state('inner 2')
message = REGION_LEAVE_MESSAGE.copy()
message['desc'] = 'inner 2'
self.send_message(EVENT_TOPIC, message)
self.assertFalse(owntracks.RE... |
'Test the event for inaccurate exit.'
| def test_event_entry_exit_inaccurate(self):
| self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_latitude(2.1)
self.assert_location_accuracy(10.0)
self.assert_location_state('inner')
self.send_message(EVENT_TOPIC, REGION_LEAVE_INACCURATE_MESSAGE)
self.assert_location_latitude(2.1)
self.assert_location_accuracy(10.... |
'Test entry/exit events with accuracy zero.'
| def test_event_entry_exit_zero_accuracy(self):
| self.send_message(EVENT_TOPIC, REGION_ENTER_ZERO_MESSAGE)
self.assert_location_latitude(2.1)
self.assert_location_accuracy(10.0)
self.assert_location_state('inner')
self.send_message(EVENT_TOPIC, REGION_LEAVE_ZERO_MESSAGE)
self.assert_location_latitude(2.1)
self.assert_location_accuracy(10.0... |
'Test the event for exit zone.'
| def test_event_exit_outside_zone_sets_away(self):
| self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_state('inner')
message = REGION_LEAVE_MESSAGE.copy()
message['lon'] = 90.1
message['lat'] = 90.1
self.send_message(EVENT_TOPIC, message)
self.assert_location_state(STATE_NOT_HOME)
|
'Test the event for ordering.'
| def test_event_entry_exit_right_order(self):
| self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_state('inner')
self.assert_location_latitude(2.1)
self.assert_location_accuracy(10.0)
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = 'inner_2'
self.send_message(EVENT_TOPIC, message)
self.assert_location_s... |
'Test the event for wrong order.'
| def test_event_entry_exit_wrong_order(self):
| self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_state('inner')
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = 'inner_2'
self.send_message(EVENT_TOPIC, message)
self.assert_location_state('inner_2')
self.send_message(EVENT_TOPIC, REGION_LEAVE_MESSAGE)
se... |
'Test the event for unknown zone.'
| def test_event_entry_unknown_zone(self):
| message = REGION_ENTER_MESSAGE.copy()
message['desc'] = 'unknown'
self.send_message(EVENT_TOPIC, message)
self.assert_location_latitude(2.0)
self.assert_location_state('outer')
|
'Test the event for unknown zone.'
| def test_event_exit_unknown_zone(self):
| message = REGION_LEAVE_MESSAGE.copy()
message['desc'] = 'unknown'
self.send_message(EVENT_TOPIC, message)
self.assert_location_latitude(2.0)
self.assert_location_state('outer')
|
'Test the event for zone landing.'
| def test_event_entry_zone_loading_dash(self):
| message = REGION_ENTER_MESSAGE.copy()
message['desc'] = '-inner'
self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_state('inner')
|
'Test the movement of a beacon.'
| def test_mobile_enter_move_beacon(self):
| message = REGION_ENTER_MESSAGE.copy()
message['desc'] = IBEACON_DEVICE
self.send_message(EVENT_TOPIC, message)
self.assert_tracker_latitude(2.0)
self.assert_tracker_state('outer')
message = LOCATION_MESSAGE.copy()
message['lat'] = '3.0'
self.send_message(LOCATION_TOPIC, message)
self... |
'Test the enter and the exit of a region beacon.'
| def test_mobile_enter_exit_region_beacon(self):
| message = REGION_ENTER_MESSAGE.copy()
message['desc'] = IBEACON_DEVICE
self.send_message(EVENT_TOPIC, message)
self.assert_tracker_latitude(2.0)
self.assert_tracker_state('outer')
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = 'inner_2'
self.send_message(EVENT_TOPIC, message)
... |
'Test the exit move of a beacon.'
| def test_mobile_exit_move_beacon(self):
| message = REGION_ENTER_MESSAGE.copy()
message['desc'] = IBEACON_DEVICE
self.send_message(EVENT_TOPIC, message)
self.assert_tracker_latitude(2.0)
self.assert_tracker_state('outer')
message = REGION_LEAVE_MESSAGE.copy()
message['desc'] = IBEACON_DEVICE
message['lat'] = '3.0'
self.send_... |
'Test the multiple entering.'
| def test_mobile_multiple_async_enter_exit(self):
| enter_message = REGION_ENTER_MESSAGE.copy()
enter_message['desc'] = IBEACON_DEVICE
exit_message = REGION_LEAVE_MESSAGE.copy()
exit_message['desc'] = IBEACON_DEVICE
for _ in range(0, 20):
fire_mqtt_message(self.hass, EVENT_TOPIC, json.dumps(enter_message))
fire_mqtt_message(self.hass,... |
'Test the multiple entering.'
| def test_mobile_multiple_enter_exit(self):
| enter_message = REGION_ENTER_MESSAGE.copy()
enter_message['desc'] = IBEACON_DEVICE
exit_message = REGION_LEAVE_MESSAGE.copy()
exit_message['desc'] = IBEACON_DEVICE
self.send_message(EVENT_TOPIC, enter_message)
self.send_message(EVENT_TOPIC, enter_message)
self.send_message(EVENT_TOPIC, exit_... |
'Test a simple import of list of waypoints.'
| def test_waypoint_import_simple(self):
| waypoints_message = WAYPOINTS_EXPORTED_MESSAGE.copy()
self.send_message(WAYPOINT_TOPIC, waypoints_message)
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
self.assertTrue((wayp is not None))
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[1])
self.assertTrue((wayp is not None))
|
'Test import of list of waypoints for blacklisted user.'
| def test_waypoint_import_blacklist(self):
| waypoints_message = WAYPOINTS_EXPORTED_MESSAGE.copy()
self.send_message(WAYPOINT_TOPIC_BLOCKED, waypoints_message)
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
self.assertTrue((wayp is None))
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
self.assertTrue((wayp is None))
|
'Test import of list of waypoints with no whitelist set.'
| def test_waypoint_import_no_whitelist(self):
| @asyncio.coroutine
def mock_see(**kwargs):
'Fake see method for owntracks.'
return
test_config = {CONF_PLATFORM: 'owntracks', CONF_MAX_GPS_ACCURACY: 200, CONF_WAYPOINT_IMPORT: True}
run_coroutine_threadsafe(owntracks.async_setup_scanner(self.hass, test_config, mock_see), self... |
'Test importing a bad JSON payload.'
| def test_waypoint_import_bad_json(self):
| waypoints_message = WAYPOINTS_EXPORTED_MESSAGE.copy()
self.send_message(WAYPOINT_TOPIC, waypoints_message, True)
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[2])
self.assertTrue((wayp is None))
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[3])
self.assertTrue((wayp is None))
|
'Test importing a zone that exists.'
| def test_waypoint_import_existing(self):
| waypoints_message = WAYPOINTS_EXPORTED_MESSAGE.copy()
self.send_message(WAYPOINT_TOPIC, waypoints_message)
wayp = self.hass.states.get(WAYPOINT_ENTITY_NAMES[0])
waypoints_message = WAYPOINTS_UPDATED_MESSAGE.copy()
self.send_message(WAYPOINT_TOPIC, waypoints_message)
new_wayp = self.hass.states.g... |
'Setup things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
|
'Tear down resources.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test encrypted payload.'
| @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher)
def test_encrypted_payload(self):
| with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks', CONF_SECRET: TEST_SECRET_KEY}})
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
self.assert_location_latitude(2.0)
|
'Test encrypted payload with a topic key.'
| @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher)
def test_encrypted_payload_topic_key(self):
| with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks', CONF_SECRET: {LOCATION_TOPIC: TEST_SECRET_KEY}}})
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
self.assert_locati... |
'Test encrypted payload with no key, .'
| @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher)
def test_encrypted_payload_no_key(self):
| with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks'}})
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
self.assert_location_latitude(None)
|
'Test encrypted payload with wrong key.'
| @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher)
def test_encrypted_payload_wrong_key(self):
| with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks', CONF_SECRET: 'wrong key'}})
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
self.assert_location_latitude(None)
|
'Test encrypted payload with wrong topic key.'
| @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher)
def test_encrypted_payload_wrong_topic_key(self):
| with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks', CONF_SECRET: {LOCATION_TOPIC: 'wrong key'}}})
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
self.assert_locatio... |
'Test encrypted payload with no topic key.'
| @patch('homeassistant.components.device_tracker.owntracks.get_cipher', mock_cipher)
def test_encrypted_payload_no_topic_key(self):
| with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks', CONF_SECRET: {'owntracks/{}/{}'.format(USER, 'otherdevice'): 'foobar'}}})
self.send_message(LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE... |
'Test sending encrypted message payload.'
| @unittest.skipUnless(libnacl, 'libnacl/libsodium is not installed')
def test_encrypted_payload_libsodium(self):
| with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {device_tracker.DOMAIN: {CONF_PLATFORM: 'owntracks', CONF_SECRET: TEST_SECRET_KEY}})
self.send_message(LOCATION_TOPIC, ENCRYPTED_LOCATION_MESSAGE)
self.assert_location_latitude(2.0)
|
'Setup things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
mock_http_component(self.hass, 'super_secret')
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.