Merge lp:~allenap/maas/revert-change-to-httplib2-in-apiclient into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 1239
Proposed branch: lp:~allenap/maas/revert-change-to-httplib2-in-apiclient
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 105 lines (+8/-43)
2 files modified
src/apiclient/maas_client.py (+4/-8)
src/apiclient/tests/test_maas_client.py (+4/-35)
To merge this branch: bzr merge lp:~allenap/maas/revert-change-to-httplib2-in-apiclient
Reviewer Review Type Date Requested Status
John A Meinel (community) Approve
Review via email: mp+128726@code.launchpad.net

Commit message

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

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
16 'MAASOAuth',16 'MAASOAuth',
17 ]17 ]
1818
19import urllib2
20
19from apiclient.encode_json import encode_json_data21from apiclient.encode_json import encode_json_data
20from apiclient.multipart import encode_multipart_data22from apiclient.multipart import encode_multipart_data
21from apiclient.utils import urlencode23from apiclient.utils import urlencode
22import httplib2
23import oauth.oauth as oauth24import oauth.oauth as oauth
2425
2526
@@ -68,11 +69,6 @@
68 provider in Juju for the code this would require.69 provider in Juju for the code this would require.
69 """70 """
7071
71 def __init__(self, insecure=False):
72 super(MAASDispatcher, self).__init__()
73 self.http = httplib2.Http(
74 disable_ssl_certificate_validation=insecure)
75
76 def dispatch_query(self, request_url, headers, method="GET", data=None):72 def dispatch_query(self, request_url, headers, method="GET", data=None):
77 """Synchronously dispatch an OAuth-signed request to L{request_url}.73 """Synchronously dispatch an OAuth-signed request to L{request_url}.
7874
@@ -86,8 +82,8 @@
8682
87 :return: A open file-like object that contains the response.83 :return: A open file-like object that contains the response.
88 """84 """
89 return self.http.request(85 req = urllib2.Request(request_url, data, headers)
90 request_url, method, body=data, headers=headers)86 return urllib2.urlopen(req)
9187
9288
93class MAASClient:89class MAASClient:
9490
=== 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 @@
13__all__ = []13__all__ = []
1414
15import json15import json
16from os.path import relpath
17from random import randint16from random import randint
18from urlparse import (17from urlparse import (
19 parse_qs,18 parse_qs,
@@ -31,10 +30,7 @@
31 parse_headers_and_body_with_mimer,30 parse_headers_and_body_with_mimer,
32 )31 )
33from maastesting.factory import factory32from maastesting.factory import factory
34from maastesting.fixtures import ProxiesDisabledFixture
35from maastesting.httpd import HTTPServerFixture
36from maastesting.testcase import TestCase33from maastesting.testcase import TestCase
37from mock import sentinel
38from testtools.matchers import (34from testtools.matchers import (
39 AfterPreprocessing,35 AfterPreprocessing,
40 Equals,36 Equals,
@@ -53,38 +49,11 @@
5349
54class TestMAASDispatcher(TestCase):50class TestMAASDispatcher(TestCase):
5551
56 def setUp(self):
57 super(TestMAASDispatcher, self).setUp()
58 self.useFixture(ProxiesDisabledFixture())
59
60 def test_dispatch_query_makes_direct_call(self):52 def test_dispatch_query_makes_direct_call(self):
61 dispatch_query = MAASDispatcher().dispatch_query53 contents = factory.getRandomString()
62 filename = relpath(__file__)54 url = "file://%s" % self.make_file(contents=contents)
63 with HTTPServerFixture() as httpd:55 self.assertEqual(
64 url = urljoin(httpd.url, filename)56 contents, MAASDispatcher().dispatch_query(url, {}).read())
65 response = dispatch_query(url, headers={})
66 headers_from_dispatcher, body_from_dispatcher = response
67 with open(filename, "rb") as file_in:
68 body_from_file = file_in.read()
69 self.assertEqual(
70 body_from_file, body_from_dispatcher,
71 "The content of %s differs from %s." % (url, filename))
72
73 def test_insecure_argument_passed_to_httplib2(self):
74 dispatcher = MAASDispatcher(sentinel.insecure)
75 self.assertEqual(
76 sentinel.insecure,
77 dispatcher.http.disable_ssl_certificate_validation)
78
79 def test_dispatch_query_passes_args_to_httplib2(self):
80 dispatcher = MAASDispatcher()
81 request = self.patch(dispatcher.http, "request")
82 dispatcher.dispatch_query(
83 request_url=sentinel.request_url, headers=sentinel.headers,
84 method=sentinel.method, data=sentinel.data)
85 request.assert_called_once_with(
86 sentinel.request_url, sentinel.method, headers=sentinel.headers,
87 body=sentinel.data)
8857
8958
90def make_url():59def make_url():