def test_can_close_the_wormhole_and_transit(self):
        ftp = FileTransferProtocol(self.reactor, self.signals)

        ftp.open(None)
        ftp.shutdown()

        self.wormhole.close.assert_called()
        self.transit.close.assert_called()
    def test_emits_signal_once_wormhole_is_closed(self):
        ftp = FileTransferProtocol(self.reactor, self.signals)

        ftp.open(None)
        ftp.shutdown()
        ftp._wormhole_delegate.wormhole_closed(result="ok")

        self.signals.wormhole_shutdown.emit.assert_called()
    def test_doesnt_send_message_if_peer_connect_mode_not_supported(self):
        ftp = FileTransferProtocol(self.reactor, self.signals)
        wormhole_open = self.connect(self.signals.wormhole_open)

        ftp.open(None)
        wormhole_open()
        ftp.shutdown()

        self.wormhole.send_message.assert_not_called()
    def test_doesnt_send_message_if_not_connected(self):
        ftp = FileTransferProtocol(self.reactor, self.signals)
        versions_received = self.connect(self.signals.versions_received)

        ftp.open(None)
        versions_received({"v0": {"mode": "connect"}})
        ftp.shutdown()

        self.wormhole.send_message.assert_not_called()
    def test_sends_message_if_connected_and_connect_mode_supported(self):
        ftp = FileTransferProtocol(self.reactor, self.signals)
        wormhole_open = self.connect(self.signals.wormhole_open)
        versions_received = self.connect(self.signals.versions_received)

        ftp.open(None)
        wormhole_open()
        versions_received({"v0": {"mode": "connect"}})
        ftp.shutdown()

        self.wormhole.send_message.assert_called_with(
            b'{"command": "shutdown"}')
    def test_still_emits_signal_if_wormhole_is_not_open(self):
        ftp = FileTransferProtocol(self.reactor, self.signals)

        ftp.shutdown()

        self.signals.wormhole_shutdown.emit.assert_called()