コード例 #1
0
    def test_continue_writing(self):
        packet = packets.DataPacket(2, "X" * 512)
        conversation = TFTPConversation(self.client_host, self.client_port,
                                        StubResponseRouterTwo())
        conversation.state = tftp_conversation.WRITING
        conversation.write_buffer = StubWriteBufferTwo()
        conversation.current_block_num = 1
        response_packet = conversation.handle_packet(packet)

        self.assertEqual(conversation.state, tftp_conversation.WRITING)
        self.assertEqual(conversation.current_block_num, 2)
        self.assertEqual(conversation.write_buffer.data, "X" * 512)
        self.assertEqual(conversation.cached_packet, response_packet)
        self.assertEqual(response_packet.__class__, packets.AcknowledgementPacket)
        self.assertEqual(response_packet.block_num, 2)
コード例 #2
0
    def test_finish_writing(self):
        packet = packets.DataPacket(3, "O" * 511)
        conversation = TFTPConversation(self.client_host, self.client_port,
                                        StubResponseRouterTwo())
        conversation.state = tftp_conversation.WRITING
        conversation.write_buffer = WriteBuffer()
        conversation.write_buffer.data = "X" * 512
        conversation.filename = "stub_filename"
        conversation.current_block_num = 2
        write_action_wrapper = StubWriteActionWrapper()
        conversation.write_action = write_action_wrapper.stub_action
        response_packet = conversation.handle_packet(packet)

        self.assertEqual(conversation.state, tftp_conversation.COMPLETED)
        self.assertEqual(conversation.current_block_num, 3)
        self.assertEqual(conversation.cached_packet, response_packet)
        self.assertEqual(response_packet.__class__, packets.AcknowledgementPacket)
        self.assertEqual(response_packet.block_num, 3)
        # action should get invoked, saving this state in the wrapper class
        self.assertEqual(write_action_wrapper.received_state,
            ("10.26.0.3", 12345, "stub_filename", "X" * 512 + "O" * 511))