Updated testcases
git-svn-id: https://tftpy.svn.sourceforge.net/svnroot/tftpy/trunk@25 63283fd4-ec1e-0410-9879-cb7f675518damaster
parent
837344caf2
commit
f2b7d5d811
10
lib/tftpy.py
10
lib/tftpy.py
|
@ -125,6 +125,14 @@ class TftpPacketInitial(TftpPacket):
|
|||
"""Encode the packet's buffer from the instance variables."""
|
||||
tftpassert(self.filename, "filename required in initial packet")
|
||||
tftpassert(self.mode, "mode required in initial packet")
|
||||
|
||||
ptype = None
|
||||
if self.opcode == 1: ptype = "RRQ"
|
||||
else: ptype = "WRQ"
|
||||
logger.debug("Encoding %s packet, filename = %s, mode = %s"
|
||||
% (ptype, self.filename, self.mode))
|
||||
for key in self.options:
|
||||
logger.debug(" Option %s = %s" % (key, self.options[key]))
|
||||
|
||||
format = "!H"
|
||||
format += "%dsx" % len(self.filename)
|
||||
|
@ -239,7 +247,7 @@ DATA | 03 | Block # | Data |
|
|||
# We know the first 2 bytes are the opcode. The second two are the
|
||||
# block number.
|
||||
(self.blocknumber,) = struct.unpack("!H", self.buffer[2:4])
|
||||
logger.info("decoding DAT packet, block number %d" % self.blocknumber)
|
||||
logger.debug("decoding DAT packet, block number %d" % self.blocknumber)
|
||||
logger.debug("should be %d bytes in the packet total"
|
||||
% len(self.buffer))
|
||||
# Everything else is data.
|
||||
|
|
28
t/test.py
28
t/test.py
|
@ -31,9 +31,37 @@ class TestTftpy(unittest.TestCase):
|
|||
wrq.encode()
|
||||
self.assert_(wrq.buffer != None, "Buffer populated")
|
||||
wrq.decode()
|
||||
self.assertEqual(wrq.opcode, 2, "Opcode correct")
|
||||
self.assertEqual(wrq.filename, "myfilename", "Filename correct")
|
||||
self.assertEqual(wrq.mode, "octet", "Mode correct")
|
||||
self.assertEqual(wrq.options, options, "Options correct")
|
||||
|
||||
def testTftpPacketDAT(self):
|
||||
dat = tftpy.TftpPacketDAT()
|
||||
dat.blocknumber = 5
|
||||
data = "this is some data"
|
||||
dat.data = data
|
||||
dat.encode()
|
||||
self.assert_(dat.buffer != None, "Buffer populated")
|
||||
dat.decode()
|
||||
self.assertEqual(dat.opcode, 3, "DAT opcode is correct")
|
||||
self.assertEqual(dat.blocknumber, 5, "Block number is correct")
|
||||
self.assertEqual(dat.data, data, "DAT data is correct")
|
||||
|
||||
def testTftpPacketACK(self):
|
||||
ack = tftpy.TftpPacketACK()
|
||||
ack.blocknumber = 6
|
||||
ack.encode()
|
||||
self.assert_(ack.buffer != None, "Buffer populated")
|
||||
ack.decode()
|
||||
self.assertEqual(ack.opcode, 4, "ACK opcode is correct")
|
||||
self.assertEqual(ack.blocknumber, 6, "ACK blocknumber correct")
|
||||
|
||||
def testTftpPacketERR(self):
|
||||
pass
|
||||
|
||||
def testTftpPacketOACK(self):
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Reference in New Issue