Merge ~cjwatson/launchpad:py3-browser-contents-native-strings into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: bb74d02c0c207b35ce1f69c44693d9b9174af642
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-browser-contents-native-strings
Merge into: launchpad:master
Diff against target: 388 lines (+47/-42)
14 files modified
lib/lp/answers/stories/question-obfuscation.txt (+2/-2)
lib/lp/bugs/stories/bug-also-affects/xx-bug-also-affects.txt (+2/-2)
lib/lp/bugs/stories/bug-also-affects/xx-bugtracker-information.txt (+2/-2)
lib/lp/bugs/stories/bug-tags/xx-tags-on-bug-page.txt (+3/-3)
lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt (+5/-5)
lib/lp/bugs/stories/bugs/xx-bug-edit.txt (+2/-2)
lib/lp/bugs/stories/bugs/xx-bug-index.txt (+2/-2)
lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt (+1/-1)
lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt (+2/-2)
lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt (+3/-2)
lib/lp/code/browser/tests/test_codereviewcomment.py (+4/-3)
lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt (+2/-1)
lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt (+6/-5)
lib/lp/translations/stories/translations/xx-translations.txt (+11/-10)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+397921@code.launchpad.net

Commit message

Test Browser.contents using native strings

Description of the change

zope.testbrowser.browser.Browser.contents normally returns a native string, but in some previous unicode_literals conversions I assumed that it returned bytes. Correct several tests for this.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/answers/stories/question-obfuscation.txt b/lib/lp/answers/stories/question-obfuscation.txt
2index 1930df2..51f8028 100644
3--- a/lib/lp/answers/stories/question-obfuscation.txt
4+++ b/lib/lp/answers/stories/question-obfuscation.txt
5@@ -93,7 +93,7 @@ Anonymous cannot see the email address anywhere on the Answers front
6 page.
7
8 >>> anon_browser.open('http://answers.launchpad.test/')
9- >>> b'user@domain.com' in anon_browser.contents
10+ >>> six.ensure_str('user@domain.com') in anon_browser.contents
11 False
12
13 >>> question_portlet = find_tag_by_id(
14@@ -129,7 +129,7 @@ They cannot see the address reading the question either.
15 link ...
16
17 >>> anon_browser.getLink('mailto: problem in webpage').click()
18- >>> b'user@domain.com' in anon_browser.contents
19+ >>> six.ensure_str('user@domain.com') in anon_browser.contents
20 False
21
22 >>> description = find_main_content(anon_browser.contents).p
23diff --git a/lib/lp/bugs/stories/bug-also-affects/xx-bug-also-affects.txt b/lib/lp/bugs/stories/bug-also-affects/xx-bug-also-affects.txt
24index 7867390..293dc89 100644
25--- a/lib/lp/bugs/stories/bug-also-affects/xx-bug-also-affects.txt
26+++ b/lib/lp/bugs/stories/bug-also-affects/xx-bug-also-affects.txt
27@@ -703,7 +703,7 @@ confirmation.
28 mailto:dark-master-o-bugs@mylittlepony.com
29
30 >>> user_browser.contents.count(
31- ... b'mailto:dark-master-o-bugs@mylittlepony.com')
32+ ... six.ensure_str('mailto:dark-master-o-bugs@mylittlepony.com'))
33 3
34
35 To evade harvesting, the email address above is obfuscated if you're not
36@@ -719,5 +719,5 @@ logged in.
37 auto-dark-master-o-bugs
38
39 >>> anon_browser.contents.count(
40- ... b'mailto:dark-master-o-bugs@mylittlepony.com')
41+ ... six.ensure_str('mailto:dark-master-o-bugs@mylittlepony.com'))
42 0
43diff --git a/lib/lp/bugs/stories/bug-also-affects/xx-bugtracker-information.txt b/lib/lp/bugs/stories/bug-also-affects/xx-bugtracker-information.txt
44index c5329a0..3ea9322 100644
45--- a/lib/lp/bugs/stories/bug-also-affects/xx-bugtracker-information.txt
46+++ b/lib/lp/bugs/stories/bug-also-affects/xx-bugtracker-information.txt
47@@ -8,7 +8,7 @@ task.
48 ... 'http://launchpad.test/firefox/+bug/1/+choose-affected-product')
49 >>> user_browser.getControl('Project').value = 'gnome-terminal'
50 >>> user_browser.getControl('Continue').click()
51- >>> print(user_browser.contents.decode('ascii', 'ignore'))
52+ >>> print(user_browser.contents)
53 <...GNOME Terminal uses
54 <a href="http://bugzilla.gnome.org/bugs">GnomeGBug GTracker</a>
55 to track its bugs...
56@@ -30,7 +30,7 @@ its bugs and prompt for a URL or an email address.
57 ... 'http://launchpad.test/firefox/+bug/1/+choose-affected-product')
58 >>> user_browser.getControl('Project').value = 'thunderbird'
59 >>> user_browser.getControl('Continue').click()
60- >>> print(user_browser.contents.decode('ascii', 'ignore'))
61+ >>> print(user_browser.contents)
62 <...Mozilla Thunderbird doesn't use Launchpad to track its bugs...
63
64 >>> print_upstream_linking_form(user_browser)
65diff --git a/lib/lp/bugs/stories/bug-tags/xx-tags-on-bug-page.txt b/lib/lp/bugs/stories/bug-tags/xx-tags-on-bug-page.txt
66index dc4ae96..918cf50 100644
67--- a/lib/lp/bugs/stories/bug-tags/xx-tags-on-bug-page.txt
68+++ b/lib/lp/bugs/stories/bug-tags/xx-tags-on-bug-page.txt
69@@ -34,11 +34,11 @@ Let's specify two valid tags.
70
71 Now the tags will be displayed on the bug page:
72
73- >>> b'Tags:' in user_browser.contents
74+ >>> six.ensure_str('Tags:') in user_browser.contents
75 True
76- >>> b'foo' in user_browser.contents
77+ >>> six.ensure_str('foo') in user_browser.contents
78 True
79- >>> b'bar' in user_browser.contents
80+ >>> six.ensure_str('bar') in user_browser.contents
81 True
82
83 Simply changing the ordering of the bug tags won't cause anything to
84diff --git a/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt b/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
85index 687fce5..404810e 100644
86--- a/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
87+++ b/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
88@@ -44,14 +44,14 @@ We can check that the attachment is there
89 >>> link.url
90 'http://bugs.launchpad.test/firefox/+bug/1/+attachment/.../+files/foo.txt'
91
92- >>> b'Added some information' in user_browser.contents
93+ >>> six.ensure_str('Added some information') in user_browser.contents
94 True
95
96 And that we stripped the leading and trailing whitespace correctly
97
98- >>> b' Some information ' in user_browser.contents
99+ >>> six.ensure_str(' Some information ') in user_browser.contents
100 False
101- >>> b'Some information' in user_browser.contents
102+ >>> six.ensure_str('Some information') in user_browser.contents
103 True
104
105 If no description is given it gets set to the attachment filename. It's
106@@ -265,7 +265,7 @@ We can also edit the attachment details, let's navigate to that page.
107 >>> user_browser.url
108 'http://bugs.launchpad.test/firefox/+bug/1/+attachment/...'
109
110- >>> b'Edit attachment' in user_browser.contents
111+ >>> six.ensure_str('Edit attachment') in user_browser.contents
112 True
113
114 There's also an option to cancel, which takes you back to the bug
115@@ -286,7 +286,7 @@ whitespace to test that's correctly stripped)...
116 >>> user_browser.url
117 'http://bugs.launchpad.test/firefox/+bug/1'
118
119- >>> b'Another title' in user_browser.contents
120+ >>> six.ensure_str('Another title') in user_browser.contents
121 True
122
123 We can edit the attachment to be a patch.
124diff --git a/lib/lp/bugs/stories/bugs/xx-bug-edit.txt b/lib/lp/bugs/stories/bugs/xx-bug-edit.txt
125index b8ec7b0..9e9af89 100644
126--- a/lib/lp/bugs/stories/bugs/xx-bug-edit.txt
127+++ b/lib/lp/bugs/stories/bugs/xx-bug-edit.txt
128@@ -73,9 +73,9 @@ Now we are back at the bug page, and the tag has been added.
129
130 >>> user_browser.url
131 'http://bugs.launchpad.test/firefox/+bug/1'
132- >>> b'layout-test' in user_browser.contents
133+ >>> six.ensure_str('layout-test') in user_browser.contents
134 True
135- >>> b'new-tag' in user_browser.contents
136+ >>> six.ensure_str('new-tag') in user_browser.contents
137 False
138
139 Now, let's add 'new-tag' again, and confirm it this time.
140diff --git a/lib/lp/bugs/stories/bugs/xx-bug-index.txt b/lib/lp/bugs/stories/bugs/xx-bug-index.txt
141index 3a5df86..62b2b75 100644
142--- a/lib/lp/bugs/stories/bugs/xx-bug-index.txt
143+++ b/lib/lp/bugs/stories/bugs/xx-bug-index.txt
144@@ -42,7 +42,7 @@ highlighted.
145 ...<tr>
146 ...mozilla-firefox (Ubuntu)...
147 ...
148- >>> anon_browser.contents.count(b'<tr class="highlight"')
149+ >>> anon_browser.contents.count(six.ensure_str('<tr class="highlight"'))
150 1
151
152 >>> anon_browser.open(
153@@ -59,7 +59,7 @@ highlighted.
154 ...<tr>
155 ...mozilla-firefox (Ubuntu)...
156 ...
157- >>> anon_browser.contents.count(b'<tr class="highlight"')
158+ >>> anon_browser.contents.count(six.ensure_str('<tr class="highlight"'))
159 1
160
161 If the context is a distribution package, the package name has a
162diff --git a/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt b/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt
163index c0f4af0..a7dc948 100644
164--- a/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt
165+++ b/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt
166@@ -29,7 +29,7 @@ An anonymous cannot see the email address anywhere in the page.
167 >>> print(anon_browser.title)
168 Bug #3 ...
169
170- >>> b'user@domain.org' in anon_browser.contents
171+ >>> six.ensure_str('user@domain.org') in anon_browser.contents
172 False
173
174 >>> description = find_tag_by_id(
175diff --git a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
176index a8b0cb3..6d16ca2 100644
177--- a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
178+++ b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
179@@ -61,7 +61,7 @@ For example, users can view a textual description of bug 1:
180 The textual description contains basic information about that bug, along with
181 all tasks related to that bug, presented in an easy-to-digest format:
182
183- >>> text_bug = anon_browser.contents.decode('UTF-8')
184+ >>> text_bug = six.ensure_text(anon_browser.contents)
185 >>> print(text_bug)
186 bug: 1
187 title: Firefox does not support SVG
188@@ -175,7 +175,7 @@ description of bug 1 directly from the Mozilla Firefox-specific text page:
189 The textual report contains the same information as the report provided by the
190 parent bug context:
191
192- >>> text_bug_task = anon_browser.contents.decode('UTF-8')
193+ >>> text_bug_task = six.ensure_text(anon_browser.contents)
194 >>> print(text_bug_task)
195 bug: 1
196 title: Firefox does not support SVG
197diff --git a/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt b/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt
198index 9cd635b..2488478 100644
199--- a/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt
200+++ b/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt
201@@ -10,8 +10,9 @@ After a bug watch is recorded, it is possible to go back and change it.
202 >>> admin_browser.getControl('Change').click()
203 >>> admin_browser.url
204 'http://bugs.launchpad.test/firefox/+bug/1'
205- >>> b'https://bugzilla.mozilla.org/show_bug.cgi?id=1000' in (
206- ... admin_browser.contents)
207+ >>> six.ensure_str(
208+ ... 'https://bugzilla.mozilla.org/show_bug.cgi?id=1000') in (
209+ ... admin_browser.contents)
210 True
211
212 The URL supplied must be a valid bug tracker URL and must point to a
213diff --git a/lib/lp/code/browser/tests/test_codereviewcomment.py b/lib/lp/code/browser/tests/test_codereviewcomment.py
214index 0d73a46..799312b 100644
215--- a/lib/lp/code/browser/tests/test_codereviewcomment.py
216+++ b/lib/lp/code/browser/tests/test_codereviewcomment.py
217@@ -9,6 +9,7 @@ __metaclass__ = type
218
219 import re
220
221+import six
222 from soupmatchers import (
223 HTMLContains,
224 Tag,
225@@ -196,7 +197,7 @@ class TestCodeReviewCommentHtmlMixin:
226 comment = self.makeCodeReviewComment(body='\u1234')
227 browser = self.getViewBrowser(comment, view_name='+download')
228 contents = '\u1234'.encode('utf-8')
229- self.assertEqual(contents, browser.contents)
230+ self.assertEqual(contents, six.ensure_binary(browser.contents))
231 self.assertEqual(
232 'text/plain;charset=utf-8', browser.headers['Content-type'])
233 self.assertEqual(
234@@ -206,10 +207,10 @@ class TestCodeReviewCommentHtmlMixin:
235
236 def test_parent_comment_in_reply(self):
237 """The reply view has the expected contents from the parent comment."""
238- contents = 'test-comment'.encode('utf-8')
239+ contents = 'test-comment'
240 comment = self.makeCodeReviewComment(body=contents)
241 browser = self.getViewBrowser(comment, view_name='+reply')
242- self.assertIn(contents, browser.contents)
243+ self.assertIn(six.ensure_str(contents), browser.contents)
244
245 def test_footer_for_mergeable_and_admin(self):
246 """An admin sees Hide/Reply links for a comment on a mergeable MP."""
247diff --git a/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt b/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt
248index 1743ee0..8f86dc6 100644
249--- a/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt
250+++ b/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt
251@@ -19,7 +19,8 @@ according to the selected buildstate, by default All.
252 ... by state and "mismatch" if the page, erroneously, provide only
253 ... part of the required arguments to enable filter by name.
254 ... """
255- ... assert b'<input type="submit" value="Filter" />' in contents
256+ ... assert six.ensure_str(
257+ ... '<input type="submit" value="Filter" />') in contents
258 ...
259 ... field_state = find_tag_by_id(contents, 'build_state') is not None
260 ... field_name = find_tag_by_id(contents, 'build_text') is not None
261diff --git a/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt b/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt
262index ada2593..ef3da1c 100644
263--- a/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt
264+++ b/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt
265@@ -329,7 +329,7 @@ Now, we will check suggestions in this form.
266
267 Check that suggestions come in from other contexts:
268
269- >>> b"Suggested in" in browser.contents
270+ >>> six.ensure_str("Suggested in") in browser.contents
271 True
272
273 >>> find_tag_by_id(browser.contents, 'msgset_143_es_suggestion_697_0')
274@@ -338,15 +338,16 @@ Check that suggestions come in from other contexts:
275 Check that no other suggestions are presented (since no others are
276 relevant for this message):
277
278- >>> b"Suggested by" in browser.contents
279+ >>> six.ensure_str("Suggested by") in browser.contents
280 False
281
282- >>> b"Used in" in browser.contents
283+ >>> six.ensure_str("Used in") in browser.contents
284 False
285
286 Check for the translator note:
287
288- >>> note = b"This is an example of commenttext for a multiline"
289+ >>> note = six.ensure_str(
290+ ... "This is an example of commenttext for a multiline")
291 >>> note in browser.contents
292 True
293
294@@ -408,7 +409,7 @@ And submit it.
295 Now, we check that the translation we are going to add is not yet in the
296 form, so we can check later that it's added as a suggestion:
297
298- >>> b'foo!!' in fast_submission.contents
299+ >>> six.ensure_str('foo!!') in fast_submission.contents
300 False
301
302 Now, we update the translation in slow_submission.
303diff --git a/lib/lp/translations/stories/translations/xx-translations.txt b/lib/lp/translations/stories/translations/xx-translations.txt
304index 37ba257..7c88570 100644
305--- a/lib/lp/translations/stories/translations/xx-translations.txt
306+++ b/lib/lp/translations/stories/translations/xx-translations.txt
307@@ -93,7 +93,7 @@ page, and that it has all the data we are expecting, in terms of languages.
308 >>> from lp.testing.pages import extract_url_parameter
309 >>> browser.open('http://translations.launchpad.test/ubuntu/hoary/'
310 ... '+translations')
311- >>> b'Translation status by language' in browser.contents
312+ >>> six.ensure_str('Translation status by language') in browser.contents
313 True
314 >>> print(browser.getLink('Catalan').url)
315 http://translations.launchpad.test/ubuntu/hoary/+lang/ca
316@@ -113,7 +113,7 @@ put Afrihili into the list of "preferred languages".
317 >>> browser.addHeader('Accept-Language', 'en-us,en;q=0.7,afh;q=0.3')
318 >>> browser.open('http://translations.launchpad.test/ubuntu/hoary/'
319 ... '+translations')
320- >>> b'Translation status by language' in browser.contents
321+ >>> six.ensure_str('Translation status by language') in browser.contents
322 True
323 >>> print(browser.getLink('Catalan').url)
324 http://translations.launchpad.test/ubuntu/hoary/+lang/ca
325@@ -129,9 +129,9 @@ pofile) for evolution-2.2
326
327 >>> browser.open(
328 ... 'http://translations.launchpad.test/ubuntu/hoary/+lang/hr?batch=2')
329- >>> b'Croatian' in browser.contents
330+ >>> six.ensure_str('Croatian') in browser.contents
331 True
332- >>> b'Translatable templates' in browser.contents
333+ >>> six.ensure_str('Translatable templates') in browser.contents
334 True
335 >>> print(browser.getLink('evolution-2.2').url)
336 http://translations.launchpad.test/ubuntu/hoary/+source/evolution/+pots/evolution-2.2/hr/+translate
337@@ -173,7 +173,7 @@ And finally, we will get pmount.
338
339 With its latest translator.
340
341- >>> b'Edgar Bursic' in browser.contents
342+ >>> six.ensure_str('Edgar Bursic') in browser.contents
343 True
344
345 == Last translator ==
346@@ -210,7 +210,7 @@ file):
347 batch=10
348 >>> print(extract_url_parameter(browser.url, 'show'))
349 show=untranslated
350- >>> b'10.' in browser.contents
351+ >>> six.ensure_str('10.') in browser.contents
352 True
353
354 If everything works out ok, that means that DummyPOFile has actually
355@@ -222,7 +222,8 @@ Finally, lets also check that translated entries show up as well.
356 >>> browser.getControl('Change').click()
357 >>> print(extract_url_parameter(browser.url, 'show'))
358 show=translated
359- >>> b"There are no messages that match this filtering." in browser.contents
360+ >>> six.ensure_str("There are no messages that match this filtering.") in (
361+ ... browser.contents)
362 True
363
364 == Links to filtered pages ==
365@@ -378,20 +379,20 @@ should see Catalan in the list.
366 >>> browser.open(
367 ... 'http://translations.launchpad.test/ubuntu/hoary/+source/'
368 ... 'evolution/+translations')
369- >>> b'Catalan' in browser.contents
370+ >>> six.ensure_str('Catalan') in browser.contents
371 True
372
373 But also, he doesn't want to see other languages in the list. So, he
374 shouldn't see eg. Japanese.
375
376- >>> b'Japanese' in browser.contents
377+ >>> six.ensure_str('Japanese') in browser.contents
378 False
379
380 Next, if he chooses to view all the languages, he should see Japanese
381 among the languages on the page.
382
383 >>> browser.getLink('View template & all languages...').click()
384- >>> b'Japanese' in browser.contents
385+ >>> six.ensure_str('Japanese') in browser.contents
386 True
387
388 So, everything is fine, and Carlos can sleep calmly.

Subscribers

People subscribed via source and target branches

to status/vote changes: