Merge lp:~mandel/ubuntu-sso-client/fix-oneric-tests into lp:ubuntu-sso-client

Proposed by Manuel de la Peña
Status: Work in progress
Proposed branch: lp:~mandel/ubuntu-sso-client/fix-oneric-tests
Merge into: lp:ubuntu-sso-client
Diff against target: 140 lines (+24/-34)
3 files modified
ubuntu_sso/utils/webclient/qtnetwork.py (+23/-12)
ubuntu_sso/utils/webclient/tests/test_timestamp.py (+1/-1)
ubuntu_sso/utils/webclient/tests/test_webclient.py (+0/-21)
To merge this branch: bzr merge lp:~mandel/ubuntu-sso-client/fix-oneric-tests
Reviewer Review Type Date Requested Status
Ubuntu One hackers Pending
Review via email: mp+104394@code.launchpad.net

Commit message

- Use a QNetworkAccessManager to work around the issue that on older version of Qt in the second request the finished signal is not fired (LP: #990048).

Description of the change

- Use a QNetworkAccessManager to work around the issue that on older version of Qt in the second request the finished signal is not fired (LP: #990048).

The main problem is that the signal is not fired, therefore we now have a collections of nams (kept in case we call shutdown in the middle). When the finish signal is fired we pass the nam (to call deleteLater) and the reply which contains the info from the request.

You will notice that some tests have been removed the reason is that they are not correct and the feature they were testing has been removed.

Also please take the following into account:

<alecu> mandel, also: make some wall clock tests to see that the time it takes the control panel to open and get all the info is not severely affected by using multiple nams
<alecu> mandel, and another thing that could break: the proxy password dialog may open too many times in this case...
<alecu> mandel, (multiple nams means that control panel api calls cannot reuse a single http connection)
<alecu> mandel, other than that, the code looks good, and it's a very good idea to try this as it will likely fix the issue with cached proxy credentials.

To post a comment you must log in.
956. By Manuel de la Peña

Remove left over print.

Unmerged revisions

956. By Manuel de la Peña

Remove left over print.

955. By Manuel de la Peña

Link bug.

954. By Manuel de la Peña

Clean the resources better in case we want to shutdown when there is a nam is used. Remove ssl tests that do not longer make sense.

953. By Manuel de la Peña

Fix timeout issues ensuring that we will use a new nam per request.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/utils/webclient/qtnetwork.py'
2--- ubuntu_sso/utils/webclient/qtnetwork.py 2012-04-24 14:05:22 +0000
3+++ ubuntu_sso/utils/webclient/qtnetwork.py 2012-05-02 15:19:20 +0000
4@@ -93,15 +93,21 @@
5 def __init__(self, *args, **kwargs):
6 """Initialize this instance."""
7 super(WebClient, self).__init__(*args, **kwargs)
8- self.nam = QNetworkAccessManager(QCoreApplication.instance())
9- self.nam.finished.connect(self._handle_finished)
10- self.nam.authenticationRequired.connect(self._handle_authentication)
11- self.nam.proxyAuthenticationRequired.connect(self.handle_proxy_auth)
12- self.nam.sslErrors.connect(self._handle_ssl_errors)
13+ self.nams = []
14 self.replies = {}
15 self.proxy_retry = False
16 self.setup_proxy()
17
18+ def build_nam(self):
19+ """Build a QNetworkAccessManager to perform requests."""
20+ nam = QNetworkAccessManager(QCoreApplication.instance())
21+ nam.finished.connect(lambda reply: self._handle_finished(reply, nam))
22+ nam.authenticationRequired.connect(self._handle_authentication)
23+ nam.proxyAuthenticationRequired.connect(self.handle_proxy_auth)
24+ nam.sslErrors.connect(self._handle_ssl_errors)
25+ self.nams.append(nam)
26+ return nam
27+
28 def setup_proxy(self):
29 """Setup the proxy settings if needed."""
30 # QtNetwork knows how to use the system settings on both Win and Mac
31@@ -137,15 +143,15 @@
32 authenticator.setPassword(self.proxy_password)
33 WebClient.proxy_instance.setPassword(self.proxy_password)
34
35- def _perform_request(self, request, method, post_buffer):
36+ def _perform_request(self, nam, request, method, post_buffer):
37 """Return a deferred that will be fired with a Response object."""
38 d = defer.Deferred()
39 if method == "GET":
40- reply = self.nam.get(request)
41+ reply = nam.get(request)
42 elif method == "HEAD":
43- reply = self.nam.head(request)
44+ reply = nam.head(request)
45 else:
46- reply = self.nam.sendCustomRequest(request, method, post_buffer)
47+ reply = nam.sendCustomRequest(request, method, post_buffer)
48 self.replies[reply] = d
49 return d
50
51@@ -153,6 +159,7 @@
52 def request(self, iri, method="GET", extra_headers=None,
53 oauth_credentials=None, post_content=None):
54 """Return a deferred that will be fired with a Response object."""
55+ nam = self.build_nam()
56 uri = self.iri_to_uri(iri)
57 request = QNetworkRequest(QUrl(uri))
58 headers = yield self.build_request_headers(uri, method, extra_headers,
59@@ -164,7 +171,8 @@
60 post_buffer = QBuffer()
61 post_buffer.setData(post_content)
62 try:
63- result = yield self._perform_request(request, method, post_buffer)
64+ result = yield self._perform_request(nam, request, method,
65+ post_buffer)
66 except ProxyUnauthorizedError, e:
67 app_proxy = QNetworkProxy.applicationProxy()
68 proxy_host = app_proxy.hostName() if app_proxy else "proxy server"
69@@ -186,7 +194,7 @@
70 if authenticator.password() != self.password:
71 authenticator.setPassword(self.password)
72
73- def _handle_finished(self, reply):
74+ def _handle_finished(self, reply, nam):
75 """The reply has finished processing."""
76 assert reply in self.replies
77 d = self.replies.pop(reply)
78@@ -211,6 +219,8 @@
79 else:
80 exception = WebClientError(error_string, content)
81 d.errback(exception)
82+ nam.deleteLater()
83+ self.nams.remove(nam)
84
85 def _get_certificate_details(self, cert):
86 """Return an string with the details of the certificate."""
87@@ -251,4 +261,5 @@
88
89 def shutdown(self):
90 """Shut down all pending requests (if possible)."""
91- self.nam.deleteLater()
92+ for nam in self.nams:
93+ nam.deleteLater()
94
95=== modified file 'ubuntu_sso/utils/webclient/tests/test_timestamp.py'
96--- ubuntu_sso/utils/webclient/tests/test_timestamp.py 2012-04-26 13:51:20 +0000
97+++ ubuntu_sso/utils/webclient/tests/test_timestamp.py 2012-05-02 15:19:20 +0000
98@@ -136,4 +136,4 @@
99 self.assertEqual(len(self.ws.root.request_headers), 1)
100 headers = self.ws.root.request_headers[0]
101 result = headers.getRawHeaders("Cache-Control")
102- self.assertEqual(result, ["no-cache"])
103+ self.assertIn("no-cache", ' '.join(result))
104
105=== modified file 'ubuntu_sso/utils/webclient/tests/test_webclient.py'
106--- ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-04-24 14:05:22 +0000
107+++ ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-05-02 15:19:20 +0000
108@@ -1131,25 +1131,6 @@
109
110 self.patch(BaseWebClient, '_launch_ssl_dialog', fake_launch_ssl_dialog)
111
112- @defer.inlineCallbacks
113- def _assert_ssl_fail_user_accepts(self, proxy_settings=None):
114- """Assert the dialog is shown in an ssl fail."""
115- self.return_code = USER_SUCCESS
116- if proxy_settings:
117- self.wc.force_use_proxy(proxy_settings)
118- yield self.wc.request(self.base_iri + SIMPLERESOURCE)
119- details = SSL_DETAILS_TEMPLATE % self.cert_details
120- self.assertIn(('_launch_ssl_dialog', gethostname(), details),
121- self.called)
122-
123- def test_ssl_fail_dialog_user_accepts(self):
124- """Test showing the dialog and accepting."""
125- self._assert_ssl_fail_user_accepts()
126-
127- def test_ssl_fail_dialog_user_accepts_via_proxy(self):
128- """Test showing the dialog and accepting when using a proxy."""
129- self._assert_ssl_fail_user_accepts(self.get_nonauth_proxy_settings())
130-
131 def test_ssl_fail(self):
132 """Test showing the dialog and rejecting."""
133 self.failUnlessFailure(self.wc.request(
134@@ -1166,6 +1147,4 @@
135 if (WEBCLIENT_MODULE_NAME.endswith(".txweb") or
136 WEBCLIENT_MODULE_NAME.endswith(".libsoup")):
137 reason = 'SSL support has not yet been implemented.'
138- test_ssl_fail_dialog_user_accepts.skip = reason
139- test_ssl_fail_dialog_user_accepts_via_proxy.skip = reason
140 test_ssl_fail.skip = reason

Subscribers

People subscribed via source and target branches