]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Add a unittest to the HTTPDownloader.
authorCameron Dale <camrdale@gmail.com>
Tue, 11 Dec 2007 07:27:18 +0000 (23:27 -0800)
committerCameron Dale <camrdale@gmail.com>
Tue, 11 Dec 2007 07:27:18 +0000 (23:27 -0800)
HTTPDownloader.py

index 7d9644419700933d732273619cefefed1f6ea9fd..e894c8d1219ab51af4e4a4546b8ab386ef41bf3b 100644 (file)
@@ -1,8 +1,13 @@
 
+import unittest
+
 from twisted.web2.client import http
 from twisted.internet.defer import Deferred
+from twisted.internet.protocol import ClientFactory
+from twisted.web2.client.interfaces import IHTTPClientManager
+from zope.interface import implements
 
-class HTTPClientManager(object):
+class HTTPClientManager(ClientFactory):
     """A manager for all HTTP requests to a site.
     
     
@@ -10,6 +15,8 @@ class HTTPClientManager(object):
 
     implements(IHTTPClientManager)
     
+    protocol = HTTPClientProtocol
+    
     def __init__(self, host, port):
         self.host = host
         self.port = port
@@ -20,7 +27,7 @@ class HTTPClientManager(object):
         self.pending_requests = []
         
     def get(self, path):
-        uri = 'http://' + self.host + ':' + self.port + path
+        uri = 'http://' + self.host + ':' + str(self.port) + path
         request = http.ClientRequest('GET', uri, {}, None)
         request.responseDefer = Deferred()
         self.pending_requests.append(request)
@@ -57,3 +64,17 @@ class HTTPClientManager(object):
         del self.client
         if self.pending_requests:
             self._submitRequest()
+
+class TestDownloader(unittest.TestCase):
+    
+    def test_download(self):
+        h = HTTPClientManager('www.google.ca', 80)
+        def print_resutls(result):
+            print result
+            
+        d = h.get('/index.html')
+        d.addCallback(print_results)
+        reactor.run()
+    
+if __name__ == '__main__':
+    unittest.main()