aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/test.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-07 11:23:23 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-07 11:23:23 +1200
commit14b2a69d2119d8b9d0260aa31190fc7869b45e05 (patch)
treec60d2ccfe7ca32a73b4c3847bff937ba89c1c001 /libpathod/test.py
parentb5a74a26ee6548b493cdece5a05f4fcba71c0012 (diff)
downloadmitmproxy-14b2a69d2119d8b9d0260aa31190fc7869b45e05.tar.gz
mitmproxy-14b2a69d2119d8b9d0260aa31190fc7869b45e05.tar.bz2
mitmproxy-14b2a69d2119d8b9d0260aa31190fc7869b45e05.zip
Start building a Pathod unit testing truss.
- Add test.py, which will house the testing API. - Extend API with a shutdown method, used to terminate the test daemon. - Refactor to allow clean shutdown.
Diffstat (limited to 'libpathod/test.py')
-rw-r--r--libpathod/test.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/libpathod/test.py b/libpathod/test.py
new file mode 100644
index 00000000..6728b60c
--- /dev/null
+++ b/libpathod/test.py
@@ -0,0 +1,31 @@
+import threading
+import requests
+import Queue
+import pathod
+
+class PaThread(threading.Thread):
+ def __init__(self, q, app):
+ threading.Thread.__init__(self)
+ self.q = q
+ self.app = app
+ self.port = None
+
+ def run(self):
+ self.server, self.port = pathod.make_server(self.app, 0, "127.0.0.1", None)
+ self.q.put(self.port)
+ pathod.run(self.server)
+
+
+class Daemon:
+ def __init__(self, staticdir=None, anchors=()):
+ self.app = pathod.make_app(staticdir=staticdir, anchors=anchors)
+ self.q = Queue.Queue()
+ self.thread = PaThread(self.q, self.app)
+ self.thread.start()
+ self.port = self.q.get(True, 5)
+
+ def clear(self):
+ pass
+
+ def shutdown(self):
+ requests.post("http://localhost:%s/api/shutdown"%self.port)