Example #1
0
 def test_send_confirmation(self):
     device = Device('key', {'confirmation': 'tg'}, {'confirmations': {
         'tg': {'service': 'disabled'},
     }})
     with patch.object(DisabledConfirmation, 'send') as send_mock:
         device.execute()
         send_mock.assert_called_once()
Example #2
0
 def test_discovery_print(self, write_patch):
     mac = '11:22:33:44:55:66'
     with patch('click.echo') as echo:
         discovery_print(Device(mac))
         discovery_print(Device(mac))
         echo.assert_called_once()
     mac_id_list.remove(mac)
Example #3
0
 def test_discovery_print(self, write_patch):
     mac = '11:22:33:44:55:66'
     with patch('amazon_dash.discovery.pkt_text') as pkt_text_mock:
         discovery_print(Device(mac))
         discovery_print(Device(mac))
         pkt_text_mock.assert_called_once()
     mac_id_list.remove(mac)
Example #4
0
 def test_multiple_executes(self):
     data = {
         'cmd': 'ls',
         'url': 'http://domain.com',
     }
     with self.assertRaises(InvalidConfig):
         Device('key', data)
Example #5
0
 def test_execute_error(self):
     device = Device(
         'key', {
             'cmd': "command",
             'user': "******",
             'cwd': "/dir",
             'name': "Command Name",
         }, {'confirmations': {'tg': {'service': 'disabled'}}}
     )
     with patch.object(Device, 'send_confirmation') as send_confirmation_mock:
         self.execute_mock.stop()
         execute_mock = patch.object(ExecuteCmd, 'execute', side_effect=Exception())
         execute_mock.start()
         with self.assertRaises(Exception):
             device.execute()
         send_confirmation_mock.assert_called_once()
         execute_mock.stop()
         self.execute_mock.start()
Example #6
0
 def test_create(self):
     data = {
         'cmd': "command",
         'user': "******",
         'cwd': "/dir",
         'name': "Command Name",
     }
     device = Device('KeY', data)
     self.assertEqual(device.src, 'key')
     self.assertEqual(device.name, data['name'])
Example #7
0
 def test_no_execute(self):
     device = Device('key')
     with patch.object(logger, 'warning') as warning_mock:
         device.execute()
         warning_mock.assert_called_once()
     with patch.object(Device, 'send_confirmation') as send_confirmation_mock:
         device.execute()
         send_confirmation_mock.assert_called_once()
Example #8
0
 def test_name(self):
     device = Device('key')
     self.assertEqual(device.name, 'key')
Example #9
0
 def test_double_called(self):
     last_execution.clear()
     listener = Listener(self.file)
     listener.on_push(Device('0C:47:C9:98:4A:12'))
     listener.on_push(Device('0C:47:C9:98:4A:12'))
     self.execute_mock_req.assert_called_once()
Example #10
0
 def test_device_src(self):
     device = Device('key')
     device2 = Device(device)
     self.assertEqual(device.src, device2.src)
Example #11
0
 def test_banned_devices(self):
     banned = Device(BANNED_DEVICES[0])
     self.assertFalse(pkt_text(banned))
Example #12
0
 def test_device(self):
     device = Device('11:22:33:44:55:66')
     self.assertIn(device.src, pkt_text(device))
Example #13
0
 def test_amazon_device(self):
     device = Device(AMAZON_DEVICES[0] + ':00:00:00')
     self.assertIn('Amazon', pkt_text(device))