[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Add unittests for the HTTP test template.



commit e04bdd9bc27c5c19e55cce98d2876403d9c7397d
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Thu Jan 30 18:41:37 2014 +0100

    Add unittests for the HTTP test template.
---
 ooni/tests/test_templates.py |   43 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/ooni/tests/test_templates.py b/ooni/tests/test_templates.py
new file mode 100644
index 0000000..987c7fa
--- /dev/null
+++ b/ooni/tests/test_templates.py
@@ -0,0 +1,43 @@
+from ooni.settings import config
+
+from ooni.templates import httpt
+
+from twisted.internet.error import DNSLookupError
+from twisted.internet import reactor, defer
+from twisted.trial import unittest
+
+config.logging = False
+
+class TestHTTPT(unittest.TestCase):
+    def setUp(self):
+        from twisted.web.resource import Resource
+        from twisted.web.server import Site
+        class DummyResource(Resource):
+            isLeaf = True
+            def render_GET(self, request):
+                return "%s" % request.method
+        r = DummyResource()
+        factory = Site(r)
+        self.port = reactor.listenTCP(8880, factory)
+    
+    def tearDown(self):
+        self.port.stopListening()
+
+    @defer.inlineCallbacks
+    def test_do_request(self):
+        http_test = httpt.HTTPTest()
+        http_test.localOptions['socksproxy'] = None
+        http_test._setUp()
+        response = yield http_test.doRequest('http://localhost:8880/')
+        assert response.body == "GET"
+        assert len(http_test.report['requests']) == 1
+        assert 'request' in http_test.report['requests'][0]
+        assert 'response' in http_test.report['requests'][0]
+
+    @defer.inlineCallbacks
+    def test_do_failing_request(self):
+        http_test = httpt.HTTPTest()
+        http_test.localOptions['socksproxy'] = None
+        http_test._setUp()
+        yield self.assertFailure(http_test.doRequest('http://invaliddomain/'), DNSLookupError)
+        assert http_test.report['requests'][0]['failure'] == 'dns_lookup_error'



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits