def test_prepare_creates_a_usb_communicator_and_sends_enter_bootloader(self, mock_UsbPacketCommunicator):
        mock_updater = MagicMock()
        mock_usb_packet_communicator = mock_UsbPacketCommunicator.return_value

        fw_update = FirmwareUpdate('afile', mock_updater)
        fw_update.prepare()

        mock_usb_packet_communicator.start.assert_called_with()
        mock_usb_packet_communicator.send.assert_called_with(EnterBootloaderMessage())
        mock_usb_packet_communicator.close.assert_called_with()
    def test_prepare_creates_a_usb_communicator_and_sends_enter_bootloader(
            self, mock_UsbPacketCommunicator):
        mock_updater = MagicMock()
        mock_usb_packet_communicator = mock_UsbPacketCommunicator.return_value

        fw_update = FirmwareUpdate('afile', mock_updater)
        fw_update.prepare()

        mock_usb_packet_communicator.start.assert_called_with()
        mock_usb_packet_communicator.send.assert_called_with(
            EnterBootloaderMessage())
        mock_usb_packet_communicator.close.assert_called_with()
    def test_start_should_call_firmware_updater_and_then_call_back_with_false(self):
        mock_updater = MagicMock()
        mock_updater.update.return_value = False
        call_back = MagicMock()
        expected_file = "A bin file"

        firmware_update = FirmwareUpdate(expected_file, mock_updater)
        firmware_update.start(call_back)

        time.sleep(self.wait_time)

        mock_updater.update.assert_called_with(expected_file)
        call_back.assert_called_with(False)
    def test_start_should_call_firmware_updater_and_then_call_back_with_false(
            self):
        mock_updater = MagicMock()
        mock_updater.update.return_value = False
        call_back = MagicMock()
        expected_file = "A bin file"

        firmware_update = FirmwareUpdate(expected_file, mock_updater)
        firmware_update.start(call_back)

        time.sleep(self.wait_time)

        mock_updater.update.assert_called_with(expected_file)
        call_back.assert_called_with(False)