← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/revert-change-to-httplib2-in-apiclient into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/revert-change-to-httplib2-in-apiclient into lp:maas.

Commit message:
Revert r1234 and go back to urllib2 in apiclient for now.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/revert-change-to-httplib2-in-apiclient/+merge/128726
-- 
https://code.launchpad.net/~allenap/maas/revert-change-to-httplib2-in-apiclient/+merge/128726
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/revert-change-to-httplib2-in-apiclient into lp:maas.
=== modified file 'src/apiclient/maas_client.py'
--- src/apiclient/maas_client.py	2012-10-09 11:23:56 +0000
+++ src/apiclient/maas_client.py	2012-10-09 14:21:31 +0000
@@ -16,10 +16,11 @@
     'MAASOAuth',
     ]
 
+import urllib2
+
 from apiclient.encode_json import encode_json_data
 from apiclient.multipart import encode_multipart_data
 from apiclient.utils import urlencode
-import httplib2
 import oauth.oauth as oauth
 
 
@@ -68,11 +69,6 @@
     provider in Juju for the code this would require.
     """
 
-    def __init__(self, insecure=False):
-        super(MAASDispatcher, self).__init__()
-        self.http = httplib2.Http(
-            disable_ssl_certificate_validation=insecure)
-
     def dispatch_query(self, request_url, headers, method="GET", data=None):
         """Synchronously dispatch an OAuth-signed request to L{request_url}.
 
@@ -86,8 +82,8 @@
 
         :return: A open file-like object that contains the response.
         """
-        return self.http.request(
-            request_url, method, body=data, headers=headers)
+        req = urllib2.Request(request_url, data, headers)
+        return urllib2.urlopen(req)
 
 
 class MAASClient:

=== modified file 'src/apiclient/tests/test_maas_client.py'
--- src/apiclient/tests/test_maas_client.py	2012-10-09 11:23:56 +0000
+++ src/apiclient/tests/test_maas_client.py	2012-10-09 14:21:31 +0000
@@ -13,7 +13,6 @@
 __all__ = []
 
 import json
-from os.path import relpath
 from random import randint
 from urlparse import (
     parse_qs,
@@ -31,10 +30,7 @@
     parse_headers_and_body_with_mimer,
     )
 from maastesting.factory import factory
-from maastesting.fixtures import ProxiesDisabledFixture
-from maastesting.httpd import HTTPServerFixture
 from maastesting.testcase import TestCase
-from mock import sentinel
 from testtools.matchers import (
     AfterPreprocessing,
     Equals,
@@ -53,38 +49,11 @@
 
 class TestMAASDispatcher(TestCase):
 
-    def setUp(self):
-        super(TestMAASDispatcher, self).setUp()
-        self.useFixture(ProxiesDisabledFixture())
-
     def test_dispatch_query_makes_direct_call(self):
-        dispatch_query = MAASDispatcher().dispatch_query
-        filename = relpath(__file__)
-        with HTTPServerFixture() as httpd:
-            url = urljoin(httpd.url, filename)
-            response = dispatch_query(url, headers={})
-            headers_from_dispatcher, body_from_dispatcher = response
-        with open(filename, "rb") as file_in:
-            body_from_file = file_in.read()
-        self.assertEqual(
-            body_from_file, body_from_dispatcher,
-            "The content of %s differs from %s." % (url, filename))
-
-    def test_insecure_argument_passed_to_httplib2(self):
-        dispatcher = MAASDispatcher(sentinel.insecure)
-        self.assertEqual(
-            sentinel.insecure,
-            dispatcher.http.disable_ssl_certificate_validation)
-
-    def test_dispatch_query_passes_args_to_httplib2(self):
-        dispatcher = MAASDispatcher()
-        request = self.patch(dispatcher.http, "request")
-        dispatcher.dispatch_query(
-            request_url=sentinel.request_url, headers=sentinel.headers,
-            method=sentinel.method, data=sentinel.data)
-        request.assert_called_once_with(
-            sentinel.request_url, sentinel.method, headers=sentinel.headers,
-            body=sentinel.data)
+        contents = factory.getRandomString()
+        url = "file://%s" % self.make_file(contents=contents)
+        self.assertEqual(
+            contents, MAASDispatcher().dispatch_query(url, {}).read())
 
 
 def make_url():