コード例 #1
0
    def test_returns_dest_file(self, mocker):
        dest_file = mocker.Mock()
        self.receiver.handle_offer.return_value = dest_file
        transit = TransitProtocolPair(None, None, None)
        transit.handle_transit("transit")

        result = transit.handle_offer("offer")

        assert_that(result, is_(dest_file))
コード例 #2
0
    def test_only_handles_transit_the_first_time_when_receiving(self):
        transit = TransitProtocolPair(None, None, None)
        transit.handle_transit("transit")
        transit.handle_offer("offer")
        transit.receive_file(13, "test_file")
        on_receive_finished = self.receiver.receive_file.call_args[0][1]
        on_receive_finished()

        transit.handle_transit("transit")

        self.receiver.handle_transit.assert_called_once_with("transit")
コード例 #3
0
    def test_skips_transit_handshake_if_already_complete(self):
        transit = TransitProtocolPair(None, None, None)
        transit.send_file(13, "test_file")
        transit.handle_transit("transit")
        transit.handle_file_ack()
        on_send_finished = self.sender.send_file.call_args[0][1]
        on_send_finished()

        transit.send_file(13, "test_file")

        self.sender.send_transit.assert_called_once()
        assert_that(self.sender.send_offer.call_count, is_(2))
        self.sender.send_offer.assert_called_with(self.source_file)
コード例 #4
0
    def test_is_true_while_receiving(self):
        transit = TransitProtocolPair(None, None, None)
        transit.handle_transit("transit")
        transit.handle_offer("offer")
        transit.receive_file(13, "test_file")

        assert_that(transit.is_receiving_file, is_(True))
コード例 #5
0
    def test_sends_file(self, mocker):
        transit = TransitProtocolPair(None, None, None)
        transit.send_file(13, "test_file")
        transit.handle_transit("transit")

        transit.handle_file_ack()

        self.sender.send_file.assert_called_once_with(self.source_file,
                                                      mocker.ANY)
コード例 #6
0
    def test_is_false_after_receiving(self):
        transit = TransitProtocolPair(None, None, None)
        transit.handle_transit("transit")
        transit.handle_offer("offer")
        transit.receive_file(13, "test_file")

        on_receive_finished = self.receiver.receive_file.call_args[0][1]
        on_receive_finished()

        assert_that(transit.is_receiving_file, is_(False))
コード例 #7
0
    def test_is_false_after_sending(self):
        transit = TransitProtocolPair(None, None, None)
        transit.send_file(13, "test_file")
        transit.handle_transit("transit")
        transit.handle_file_ack()
        assert_that(transit.is_sending_file, is_(True))

        on_send_finished = self.sender.send_file.call_args[0][1]
        on_send_finished()

        assert_that(transit.is_sending_file, is_(False))
コード例 #8
0
    def test_file_is_received(self, mocker):
        dest_file = mocker.Mock()
        self.receiver.handle_offer.return_value = dest_file
        transit = TransitProtocolPair(None, None, None)
        transit.handle_transit("transit")
        transit.handle_offer("offer")

        transit.receive_file(13, "test_file")

        self.receiver.receive_file.assert_called_once_with(
            dest_file, mocker.ANY)
コード例 #9
0
    def test_sends_offer_when_sending(self):
        transit = TransitProtocolPair(None, None, None)
        transit.send_file(13, "test_file")

        transit.handle_transit("transit")

        self.sender.send_offer.assert_called_once_with(self.source_file)
コード例 #10
0
    def test_handles_offer(self):
        transit = TransitProtocolPair(None, None, None)
        transit.handle_transit("transit")

        transit.handle_offer("offer")

        self.receiver.handle_offer.assert_called_once_with("offer")
コード例 #11
0
    def test_sends_transit_when_receiving(self):
        transit = TransitProtocolPair(None, None, None)

        transit.handle_transit("transit")

        self.receiver.send_transit.assert_called_once()
コード例 #12
0
    def test_only_handles_transit_the_first_time_when_sending(self):
        transit = TransitProtocolPair(None, None, None)
        transit.send_file(13, "test_file")
        transit.handle_transit("transit")
        transit.handle_file_ack()
        on_send_finished = self.sender.send_file.call_args[0][1]
        on_send_finished()

        transit.send_file(13, "test_file")
        transit.handle_transit("transit")

        self.sender.handle_transit.assert_called_once_with("transit")
コード例 #13
0
    def test_opens_source_file(self):
        transit = TransitProtocolPair(None, None, None)

        transit.send_file(13, "test_file")

        self.source_file.open.assert_called_once()
コード例 #14
0
    def test_sends_transit(self):
        transit = TransitProtocolPair(None, None, None)

        transit.send_file(13, "test_file")

        self.sender.send_transit.assert_called_once()
コード例 #15
0
    def test_is_false_before_receiving(self):
        transit = TransitProtocolPair(None, None, None)

        assert_that(transit.is_receiving_file, is_(False))
コード例 #16
0
    def test_is_true_while_sending(self):
        transit = TransitProtocolPair(None, None, None)
        transit.send_file(13, "test_file")

        assert_that(transit.is_sending_file, is_(True))