def test_execute_with_access(self): with requests_mock.mock() as m: m.post(self.url, text='success', request_headers={'x-ha-access': 'password'}) assis = ExecuteHomeAssistant( 'key', self.default_data(extra_data={'access': 'password'})) assis.execute() self.assertTrue(m.called_once)
def test_execute_with_access_token(self): with requests_mock.mock() as m: m.post(self.url, text='success', request_headers={'Authorization': 'Bearer abcde12345'}) assis = ExecuteHomeAssistant( 'key', self.default_data(extra_data={'access_token': 'abcde12345'})) assis.execute() self.assertTrue(m.called_once)
def test_execute(self): with requests_mock.mock() as m: m.post(self.url, text='success') assis = ExecuteHomeAssistant('key', self.default_data()) assis.execute() self.assertTrue(m.called_once)
def test_full_address(self): assis = ExecuteHomeAssistant( 'key', self.default_data('https://localhost:7123')) self.assertIn('url', assis.data) self.assertEqual(assis.data['url'], 'https://localhost:7123' + self.path)
def test_include_address_protocol(self): assis = ExecuteHomeAssistant('key', self.default_data('https://localhost')) self.assertIn('url', assis.data) self.assertEqual(assis.data['url'], 'https://localhost:8123' + self.path)
def test_only_address(self): assis = ExecuteHomeAssistant('key', self.default_data()) self.assertIn('url', assis.data) self.assertEqual(assis.data['url'], self.url)
def test_no_event(self): with self.assertRaises(InvalidConfig): ExecuteHomeAssistant('key', self.default_data(event=''))