def test_notification_no_answer(self, time_mock, popen_mock): """Test notification when no result is returned.""" _configure_popenmock(popen_mock, "") backend = GatttoolBackend() backend.connect(TEST_MAC) with self.assertRaises(BluetoothBackendException): backend.wait_for_notification(0xFF, self, 10)
def test_notification_wrong_handle(self, time_mock, popen_mock): """Test notification when wrong handle""" _configure_popenmock( popen_mock, "Characteristic Write Request failed: Attribute can't be written") backend = GatttoolBackend() backend.connect(TEST_MAC) with self.assertRaises(BluetoothBackendException): backend.wait_for_notification(0xFF, self, 10)
def test_notification_timeout(self, time_mock, popen_mock, os_mock): """Test notification when timeout""" _configure_popenmock_timeout(popen_mock, ( "Characteristic value was written successfully\n" "Notification handle = 0x000e value: 54 3d 32 37 2e 33 20 48 3d 32 37 2e 30 00\n" "Notification handle = 0x000e value: 54 3d 32 37 2e 32 20 48 3d 32 37 2e 32 00\n" "Notification handle = 0x000e value: 54 3d 32 37 2e 31 20 48 3d 32 37 2e 34 00" )) backend = GatttoolBackend() backend.connect(TEST_MAC) self.handle_notification_called = False self.assertTrue(backend.wait_for_notification(0xFF, self, 10)) self.assertTrue(self.handle_notification_called)
def test_notification_not_connected(self): """Test writing data when not connected.""" backend = GatttoolBackend() with self.assertRaises(BluetoothBackendException): backend.wait_for_notification(0xFF, self, 10)