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

Proposed by Gavin Panella on 2012-10-09
Status: Merged
Approved by: Gavin Panella on 2012-10-09
Approved revision: 1239
Merged at revision: 1239
Proposed branch: lp:~allenap/maas/revert-change-to-httplib2-in-apiclient
Merge into: lp: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 2012-10-09 Approve on 2012-10-09
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.
John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/apiclient/maas_client.py'
2--- src/apiclient/maas_client.py 2012-10-09 11:23:56 +0000
3+++ src/apiclient/maas_client.py 2012-10-09 14:21:31 +0000
4@@ -16,10 +16,11 @@
5 'MAASOAuth',
6 ]
7
8+import urllib2
9+
10 from apiclient.encode_json import encode_json_data
11 from apiclient.multipart import encode_multipart_data
12 from apiclient.utils import urlencode
13-import httplib2
14 import oauth.oauth as oauth
15
16
17@@ -68,11 +69,6 @@
18 provider in Juju for the code this would require.
19 """
20
21- def __init__(self, insecure=False):
22- super(MAASDispatcher, self).__init__()
23- self.http = httplib2.Http(
24- disable_ssl_certificate_validation=insecure)
25-
26 def dispatch_query(self, request_url, headers, method="GET", data=None):
27 """Synchronously dispatch an OAuth-signed request to L{request_url}.
28
29@@ -86,8 +82,8 @@
30
31 :return: A open file-like object that contains the response.
32 """
33- return self.http.request(
34- request_url, method, body=data, headers=headers)
35+ req = urllib2.Request(request_url, data, headers)
36+ return urllib2.urlopen(req)
37
38
39 class MAASClient:
40
41=== modified file 'src/apiclient/tests/test_maas_client.py'
42--- src/apiclient/tests/test_maas_client.py 2012-10-09 11:23:56 +0000
43+++ src/apiclient/tests/test_maas_client.py 2012-10-09 14:21:31 +0000
44@@ -13,7 +13,6 @@
45 __all__ = []
46
47 import json
48-from os.path import relpath
49 from random import randint
50 from urlparse import (
51 parse_qs,
52@@ -31,10 +30,7 @@
53 parse_headers_and_body_with_mimer,
54 )
55 from maastesting.factory import factory
56-from maastesting.fixtures import ProxiesDisabledFixture
57-from maastesting.httpd import HTTPServerFixture
58 from maastesting.testcase import TestCase
59-from mock import sentinel
60 from testtools.matchers import (
61 AfterPreprocessing,
62 Equals,
63@@ -53,38 +49,11 @@
64
65 class TestMAASDispatcher(TestCase):
66
67- def setUp(self):
68- super(TestMAASDispatcher, self).setUp()
69- self.useFixture(ProxiesDisabledFixture())
70-
71 def test_dispatch_query_makes_direct_call(self):
72- dispatch_query = MAASDispatcher().dispatch_query
73- filename = relpath(__file__)
74- with HTTPServerFixture() as httpd:
75- url = urljoin(httpd.url, filename)
76- response = dispatch_query(url, headers={})
77- headers_from_dispatcher, body_from_dispatcher = response
78- with open(filename, "rb") as file_in:
79- body_from_file = file_in.read()
80- self.assertEqual(
81- body_from_file, body_from_dispatcher,
82- "The content of %s differs from %s." % (url, filename))
83-
84- def test_insecure_argument_passed_to_httplib2(self):
85- dispatcher = MAASDispatcher(sentinel.insecure)
86- self.assertEqual(
87- sentinel.insecure,
88- dispatcher.http.disable_ssl_certificate_validation)
89-
90- def test_dispatch_query_passes_args_to_httplib2(self):
91- dispatcher = MAASDispatcher()
92- request = self.patch(dispatcher.http, "request")
93- dispatcher.dispatch_query(
94- request_url=sentinel.request_url, headers=sentinel.headers,
95- method=sentinel.method, data=sentinel.data)
96- request.assert_called_once_with(
97- sentinel.request_url, sentinel.method, headers=sentinel.headers,
98- body=sentinel.data)
99+ contents = factory.getRandomString()
100+ url = "file://%s" % self.make_file(contents=contents)
101+ self.assertEqual(
102+ contents, MAASDispatcher().dispatch_query(url, {}).read())
103
104
105 def make_url():