summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael P. Soulier <msoulier@digitaltorque.ca>2011-06-02 22:26:45 -0400
committerMichael P. Soulier <msoulier@digitaltorque.ca>2011-06-02 22:26:45 -0400
commitf6442eb4e40fe19ab7d210d068c8a63b025d12c9 (patch)
tree547df23d70ce8c6edfee88aa149fbcc6ef3cb7ca
parenta6cff4f0b23068218849e44718e7255b634a9872 (diff)
downloadtftpy-f6442eb4e40fe19ab7d210d068c8a63b025d12c9.tar.gz
Adding a server download state test to the unit tests.
-rw-r--r--t/100KBFILEbin0 -> 102400 bytes
-rw-r--r--t/test.py45
2 files changed, 44 insertions, 1 deletions
diff --git a/t/100KBFILE b/t/100KBFILE
new file mode 100644
index 0000000..77efc8d
--- /dev/null
+++ b/t/100KBFILE
Binary files differ
diff --git a/t/test.py b/t/test.py
index 14b784a..1052db1 100644
--- a/t/test.py
+++ b/t/test.py
@@ -3,10 +3,11 @@
import unittest
import logging
import tftpy
+import os
log = tftpy.log
-class TestTftpy(unittest.TestCase):
+class TestTftpyClasses(unittest.TestCase):
def setUp(self):
tftpy.setLogLevel(logging.DEBUG)
@@ -134,6 +135,48 @@ class TestTftpy(unittest.TestCase):
classes[opcode]),
"opcode %d returns the correct class" % opcode)
+class TestTftpyState(unittest.TestCase):
+
+ def setUp(self):
+ tftpy.setLogLevel(logging.DEBUG)
+
+ def testServerNoOptions(self):
+ """Test the server states."""
+ raddress = '127.0.0.2'
+ rport = 10000
+ timeout = 5
+ root = os.path.dirname(os.path.abspath(__file__))
+ # Testing without the dyn_func_file set.
+ serverstate = tftpy.TftpContextServer(raddress,
+ rport,
+ timeout,
+ root)
+
+ self.assertTrue( isinstance(serverstate,
+ tftpy.TftpContextServer) )
+
+ rrq = tftpy.TftpPacketRRQ()
+ rrq.filename = '100KBFILE'
+ rrq.mode = 'octet'
+ rrq.options = {}
+
+ # Start the download.
+ serverstate.start(rrq.encode().buffer)
+ # At a 512 byte blocksize, this should be 200 packets exactly.
+ for block in range(1, 201):
+ # Should be in expectack state.
+ self.assertTrue( isinstance(serverstate.state,
+ tftpy.TftpStateExpectACK) )
+ ack = tftpy.TftpPacketACK()
+ ack.blocknumber = block
+ serverstate.state = serverstate.state.handle(ack, raddress, rport)
+
+ # The last DAT packet should be empty, indicating a completed
+ # transfer.
+ ack = tftpy.TftpPacketACK()
+ ack.blocknumber = 201
+ finalstate = serverstate.state.handle(ack, raddress, rport)
+ self.assertTrue( finalstate is None )
if __name__ == '__main__':
unittest.main()