summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Derrin <philip@cog.systems>2014-06-13 16:29:33 +1000
committerPhilip Derrin <philip@cog.systems>2014-06-13 16:29:33 +1000
commit0ec8265bc1304245e19a3e95f3b0bdf7044eb6bb (patch)
tree95c6e0dccaa55917abd9469f54de54cebe47d950
parent29f9a407151cca11bd71cb8eb76b2a5219594470 (diff)
downloadtftpy-0ec8265bc1304245e19a3e95f3b0bdf7044eb6bb.tar.gz
Test case for dynamic server listenport
-rw-r--r--t/test.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/t/test.py b/t/test.py
index 13cdbfa..844aa5c 100644
--- a/t/test.py
+++ b/t/test.py
@@ -5,6 +5,7 @@ import logging
import tftpy
import os
import time
+import threading
log = tftpy.log
@@ -118,7 +119,7 @@ class TestTftpyClasses(unittest.TestCase):
self.assertEqual(oack.options['blksize'],
'4096',
"OACK blksize option is correct")
-
+
def testTftpPacketFactory(self):
log.debug("===> Running testcase testTftpPacketFactory")
# Make sure that the correct class is created for the correct opcode.
@@ -411,5 +412,25 @@ class TestTftpyState(unittest.TestCase):
except Exception, err:
self.assertTrue( False, "Server should not exit early" )
+ def testServerDownloadWithDynamicPort(self, output='/tmp/out'):
+ log.debug("===> Running testcase testServerDownloadWithDynamicPort")
+ root = os.path.dirname(os.path.abspath(__file__))
+
+ server = tftpy.TftpServer(root)
+ server_thread = threading.Thread(target=server.listen,
+ kwargs={'listenip': 'localhost',
+ 'listenport': 0})
+ server_thread.start()
+
+ try:
+ server.is_running.wait()
+ client = tftpy.TftpClient('localhost', server.listenport, {})
+ time.sleep(1)
+ client.download('640KBFILE',
+ output)
+ finally:
+ server.stop(now=False)
+ server_thread.join()
+
if __name__ == '__main__':
unittest.main()