← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-browser-contents-native-strings into launchpad:master.

Commit message:
Test Browser.contents using native strings

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/397921

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.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-browser-contents-native-strings into launchpad:master.
diff --git a/lib/lp/answers/stories/question-obfuscation.txt b/lib/lp/answers/stories/question-obfuscation.txt
index 1930df2..51f8028 100644
--- a/lib/lp/answers/stories/question-obfuscation.txt
+++ b/lib/lp/answers/stories/question-obfuscation.txt
@@ -93,7 +93,7 @@ Anonymous cannot see the email address anywhere on the Answers front
 page.
 
     >>> anon_browser.open('http://answers.launchpad.test/')
-    >>> b'user@xxxxxxxxxx' in anon_browser.contents
+    >>> six.ensure_str('user@xxxxxxxxxx') in anon_browser.contents
     False
 
     >>> question_portlet = find_tag_by_id(
@@ -129,7 +129,7 @@ They cannot see the address reading the question either.
     link ...
 
     >>> anon_browser.getLink('mailto: problem in webpage').click()
-    >>> b'user@xxxxxxxxxx' in anon_browser.contents
+    >>> six.ensure_str('user@xxxxxxxxxx') in anon_browser.contents
     False
 
     >>> description = find_main_content(anon_browser.contents).p
diff --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
index 7867390..293dc89 100644
--- 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
@@ -703,7 +703,7 @@ confirmation.
       mailto:dark-master-o-bugs@xxxxxxxxxxxxxxxx
 
     >>> user_browser.contents.count(
-    ...     b'mailto:dark-master-o-bugs@xxxxxxxxxxxxxxxx')
+    ...     six.ensure_str('mailto:dark-master-o-bugs@xxxxxxxxxxxxxxxx'))
     3
 
 To evade harvesting, the email address above is obfuscated if you're not
@@ -719,5 +719,5 @@ logged in.
       auto-dark-master-o-bugs
 
     >>> anon_browser.contents.count(
-    ...     b'mailto:dark-master-o-bugs@xxxxxxxxxxxxxxxx')
+    ...     six.ensure_str('mailto:dark-master-o-bugs@xxxxxxxxxxxxxxxx'))
     0
diff --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
index c5329a0..3ea9322 100644
--- a/lib/lp/bugs/stories/bug-also-affects/xx-bugtracker-information.txt
+++ b/lib/lp/bugs/stories/bug-also-affects/xx-bugtracker-information.txt
@@ -8,7 +8,7 @@ task.
     ...    'http://launchpad.test/firefox/+bug/1/+choose-affected-product')
     >>> user_browser.getControl('Project').value = 'gnome-terminal'
     >>> user_browser.getControl('Continue').click()
-    >>> print(user_browser.contents.decode('ascii', 'ignore'))
+    >>> print(user_browser.contents)
     <...GNOME Terminal uses
     <a href="http://bugzilla.gnome.org/bugs";>GnomeGBug GTracker</a>
     to track its bugs...
@@ -30,7 +30,7 @@ its bugs and prompt for a URL or an email address.
     ...    'http://launchpad.test/firefox/+bug/1/+choose-affected-product')
     >>> user_browser.getControl('Project').value = 'thunderbird'
     >>> user_browser.getControl('Continue').click()
-    >>> print(user_browser.contents.decode('ascii', 'ignore'))
+    >>> print(user_browser.contents)
     <...Mozilla Thunderbird doesn't use Launchpad to track its bugs...
 
     >>> print_upstream_linking_form(user_browser)
diff --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
index dc4ae96..918cf50 100644
--- 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
@@ -34,11 +34,11 @@ Let's specify two valid tags.
 
 Now the tags will be displayed on the bug page:
 
-    >>> b'Tags:' in user_browser.contents
+    >>> six.ensure_str('Tags:') in user_browser.contents
     True
-    >>> b'foo' in user_browser.contents
+    >>> six.ensure_str('foo') in user_browser.contents
     True
-    >>> b'bar' in user_browser.contents
+    >>> six.ensure_str('bar') in user_browser.contents
     True
 
 Simply changing the ordering of the bug tags won't cause anything to
diff --git a/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt b/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
index 687fce5..404810e 100644
--- a/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
+++ b/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
@@ -44,14 +44,14 @@ We can check that the attachment is there
   >>> link.url
   'http://bugs.launchpad.test/firefox/+bug/1/+attachment/.../+files/foo.txt'
 
-  >>> b'Added some information' in user_browser.contents
+  >>> six.ensure_str('Added some information') in user_browser.contents
   True
 
 And that we stripped the leading and trailing whitespace correctly
 
-  >>> b'   Some information   ' in user_browser.contents
+  >>> six.ensure_str('   Some information   ') in user_browser.contents
   False
-  >>> b'Some information' in user_browser.contents
+  >>> six.ensure_str('Some information') in user_browser.contents
   True
 
 If no description is given it gets set to the attachment filename. It's
@@ -265,7 +265,7 @@ We can also edit the attachment details, let's navigate to that page.
     >>> user_browser.url
     'http://bugs.launchpad.test/firefox/+bug/1/+attachment/...'
 
-    >>> b'Edit attachment' in user_browser.contents
+    >>> six.ensure_str('Edit attachment') in user_browser.contents
     True
 
 There's also an option to cancel, which takes you back to the bug
@@ -286,7 +286,7 @@ whitespace to test that's correctly stripped)...
     >>> user_browser.url
     'http://bugs.launchpad.test/firefox/+bug/1'
 
-    >>> b'Another title' in user_browser.contents
+    >>> six.ensure_str('Another title') in user_browser.contents
     True
 
 We can edit the attachment to be a patch.
diff --git a/lib/lp/bugs/stories/bugs/xx-bug-edit.txt b/lib/lp/bugs/stories/bugs/xx-bug-edit.txt
index b8ec7b0..9e9af89 100644
--- a/lib/lp/bugs/stories/bugs/xx-bug-edit.txt
+++ b/lib/lp/bugs/stories/bugs/xx-bug-edit.txt
@@ -73,9 +73,9 @@ Now we are back at the bug page, and the tag has been added.
 
     >>> user_browser.url
     'http://bugs.launchpad.test/firefox/+bug/1'
-    >>> b'layout-test' in user_browser.contents
+    >>> six.ensure_str('layout-test') in user_browser.contents
     True
-    >>> b'new-tag' in user_browser.contents
+    >>> six.ensure_str('new-tag') in user_browser.contents
     False
 
 Now, let's add 'new-tag' again, and confirm it this time.
diff --git a/lib/lp/bugs/stories/bugs/xx-bug-index.txt b/lib/lp/bugs/stories/bugs/xx-bug-index.txt
index 3a5df86..62b2b75 100644
--- a/lib/lp/bugs/stories/bugs/xx-bug-index.txt
+++ b/lib/lp/bugs/stories/bugs/xx-bug-index.txt
@@ -42,7 +42,7 @@ highlighted.
     ...<tr>
     ...mozilla-firefox (Ubuntu)...
     ...
-    >>> anon_browser.contents.count(b'<tr class="highlight"')
+    >>> anon_browser.contents.count(six.ensure_str('<tr class="highlight"'))
     1
 
     >>> anon_browser.open(
@@ -59,7 +59,7 @@ highlighted.
     ...<tr>
     ...mozilla-firefox (Ubuntu)...
     ...
-    >>> anon_browser.contents.count(b'<tr class="highlight"')
+    >>> anon_browser.contents.count(six.ensure_str('<tr class="highlight"'))
     1
 
 If the context is a distribution package, the package name has a
diff --git a/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt b/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt
index c0f4af0..a7dc948 100644
--- a/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt
+++ b/lib/lp/bugs/stories/bugs/xx-bug-obfuscation.txt
@@ -29,7 +29,7 @@ An anonymous cannot see the email address anywhere in the page.
     >>> print(anon_browser.title)
     Bug #3 ...
 
-    >>> b'user@xxxxxxxxxx' in anon_browser.contents
+    >>> six.ensure_str('user@xxxxxxxxxx') in anon_browser.contents
     False
 
     >>> description = find_tag_by_id(
diff --git a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
index a8b0cb3..6d16ca2 100644
--- a/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
+++ b/lib/lp/bugs/stories/bugs/xx-bug-text-pages.txt
@@ -61,7 +61,7 @@ For example, users can view a textual description of bug 1:
 The textual description contains basic information about that bug, along with
 all tasks related to that bug, presented in an easy-to-digest format:
 
-    >>> text_bug = anon_browser.contents.decode('UTF-8')
+    >>> text_bug = six.ensure_text(anon_browser.contents)
     >>> print(text_bug)
     bug: 1
     title: Firefox does not support SVG
@@ -175,7 +175,7 @@ description of bug 1 directly from the Mozilla Firefox-specific text page:
 The textual report contains the same information as the report provided by the
 parent bug context:
 
-    >>> text_bug_task = anon_browser.contents.decode('UTF-8')
+    >>> text_bug_task = six.ensure_text(anon_browser.contents)
     >>> print(text_bug_task)
     bug: 1
     title: Firefox does not support SVG
diff --git a/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt b/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt
index 9cd635b..2488478 100644
--- a/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt
+++ b/lib/lp/bugs/stories/bugwatches/xx-edit-bugwatch.txt
@@ -10,8 +10,9 @@ After a bug watch is recorded, it is possible to go back and change it.
     >>> admin_browser.getControl('Change').click()
     >>> admin_browser.url
     'http://bugs.launchpad.test/firefox/+bug/1'
-    >>> b'https://bugzilla.mozilla.org/show_bug.cgi?id=1000' in (
-    ...     admin_browser.contents)
+    >>> six.ensure_str(
+    ...     'https://bugzilla.mozilla.org/show_bug.cgi?id=1000') in (
+    ...         admin_browser.contents)
     True
 
 The URL supplied must be a valid bug tracker URL and must point to a
diff --git a/lib/lp/code/browser/tests/test_codereviewcomment.py b/lib/lp/code/browser/tests/test_codereviewcomment.py
index 0d73a46..799312b 100644
--- a/lib/lp/code/browser/tests/test_codereviewcomment.py
+++ b/lib/lp/code/browser/tests/test_codereviewcomment.py
@@ -9,6 +9,7 @@ __metaclass__ = type
 
 import re
 
+import six
 from soupmatchers import (
     HTMLContains,
     Tag,
@@ -196,7 +197,7 @@ class TestCodeReviewCommentHtmlMixin:
         comment = self.makeCodeReviewComment(body='\u1234')
         browser = self.getViewBrowser(comment, view_name='+download')
         contents = '\u1234'.encode('utf-8')
-        self.assertEqual(contents, browser.contents)
+        self.assertEqual(contents, six.ensure_binary(browser.contents))
         self.assertEqual(
             'text/plain;charset=utf-8', browser.headers['Content-type'])
         self.assertEqual(
@@ -206,10 +207,10 @@ class TestCodeReviewCommentHtmlMixin:
 
     def test_parent_comment_in_reply(self):
         """The reply view has the expected contents from the parent comment."""
-        contents = 'test-comment'.encode('utf-8')
+        contents = 'test-comment'
         comment = self.makeCodeReviewComment(body=contents)
         browser = self.getViewBrowser(comment, view_name='+reply')
-        self.assertIn(contents, browser.contents)
+        self.assertIn(six.ensure_str(contents), browser.contents)
 
     def test_footer_for_mergeable_and_admin(self):
         """An admin sees Hide/Reply links for a comment on a mergeable MP."""
diff --git a/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt b/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt
index 1743ee0..8f86dc6 100644
--- a/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt
+++ b/lib/lp/soyuz/stories/soyuz/xx-builds-pages.txt
@@ -19,7 +19,8 @@ according to the selected buildstate, by default All.
     ...     by state and "mismatch" if the page, erroneously,  provide only
     ...     part of the required arguments to enable filter by name.
     ...     """
-    ...     assert b'<input type="submit" value="Filter" />' in contents
+    ...     assert six.ensure_str(
+    ...         '<input type="submit" value="Filter" />') in contents
     ...
     ...     field_state = find_tag_by_id(contents, 'build_state') is not None
     ...     field_name = find_tag_by_id(contents, 'build_text') is not None
diff --git a/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt b/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt
index ada2593..ef3da1c 100644
--- a/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt
+++ b/lib/lp/translations/stories/standalone/xx-translationmessage-translate.txt
@@ -329,7 +329,7 @@ Now, we will check suggestions in this form.
 
 Check that suggestions come in from other contexts:
 
-    >>> b"Suggested in" in browser.contents
+    >>> six.ensure_str("Suggested in") in browser.contents
     True
 
     >>> find_tag_by_id(browser.contents, 'msgset_143_es_suggestion_697_0')
@@ -338,15 +338,16 @@ Check that suggestions come in from other contexts:
 Check that no other suggestions are presented (since no others are
 relevant for this message):
 
-    >>> b"Suggested by" in browser.contents
+    >>> six.ensure_str("Suggested by") in browser.contents
     False
 
-    >>> b"Used in" in browser.contents
+    >>> six.ensure_str("Used in") in browser.contents
     False
 
 Check for the translator note:
 
-    >>> note = b"This is an example of commenttext for a multiline"
+    >>> note = six.ensure_str(
+    ...     "This is an example of commenttext for a multiline")
     >>> note in browser.contents
     True
 
@@ -408,7 +409,7 @@ And submit it.
 Now, we check that the translation we are going to add is not yet in the
 form, so we can check later that it's added as a suggestion:
 
-    >>> b'foo!!' in fast_submission.contents
+    >>> six.ensure_str('foo!!') in fast_submission.contents
     False
 
 Now, we update the translation in slow_submission.
diff --git a/lib/lp/translations/stories/translations/xx-translations.txt b/lib/lp/translations/stories/translations/xx-translations.txt
index 37ba257..7c88570 100644
--- a/lib/lp/translations/stories/translations/xx-translations.txt
+++ b/lib/lp/translations/stories/translations/xx-translations.txt
@@ -93,7 +93,7 @@ page, and that it has all the data we are expecting, in terms of languages.
   >>> from lp.testing.pages import extract_url_parameter
   >>> browser.open('http://translations.launchpad.test/ubuntu/hoary/'
   ...     '+translations')
-  >>> b'Translation status by language' in browser.contents
+  >>> six.ensure_str('Translation status by language') in browser.contents
   True
   >>> print(browser.getLink('Catalan').url)
   http://translations.launchpad.test/ubuntu/hoary/+lang/ca
@@ -113,7 +113,7 @@ put Afrihili into the list of "preferred languages".
   >>> browser.addHeader('Accept-Language', 'en-us,en;q=0.7,afh;q=0.3')
   >>> browser.open('http://translations.launchpad.test/ubuntu/hoary/'
   ...     '+translations')
-  >>> b'Translation status by language' in browser.contents
+  >>> six.ensure_str('Translation status by language') in browser.contents
   True
   >>> print(browser.getLink('Catalan').url)
   http://translations.launchpad.test/ubuntu/hoary/+lang/ca
@@ -129,9 +129,9 @@ pofile) for evolution-2.2
 
   >>> browser.open(
   ...     'http://translations.launchpad.test/ubuntu/hoary/+lang/hr?batch=2')
-  >>> b'Croatian' in browser.contents
+  >>> six.ensure_str('Croatian') in browser.contents
   True
-  >>> b'Translatable templates' in browser.contents
+  >>> six.ensure_str('Translatable templates') in browser.contents
   True
   >>> print(browser.getLink('evolution-2.2').url)
   http://translations.launchpad.test/ubuntu/hoary/+source/evolution/+pots/evolution-2.2/hr/+translate
@@ -173,7 +173,7 @@ And finally, we will get pmount.
 
 With its latest translator.
 
-  >>> b'Edgar Bursic' in browser.contents
+  >>> six.ensure_str('Edgar Bursic') in browser.contents
   True
 
 == Last translator ==
@@ -210,7 +210,7 @@ file):
   batch=10
   >>> print(extract_url_parameter(browser.url, 'show'))
   show=untranslated
-  >>> b'10.' in browser.contents
+  >>> six.ensure_str('10.') in browser.contents
   True
 
 If everything works out ok, that means that DummyPOFile has actually
@@ -222,7 +222,8 @@ Finally, lets also check that translated entries show up as well.
   >>> browser.getControl('Change').click()
   >>> print(extract_url_parameter(browser.url, 'show'))
   show=translated
-  >>> b"There are no messages that match this filtering." in browser.contents
+  >>> six.ensure_str("There are no messages that match this filtering.") in (
+  ...     browser.contents)
   True
 
 == Links to filtered pages ==
@@ -378,20 +379,20 @@ should see Catalan in the list.
     >>> browser.open(
     ...     'http://translations.launchpad.test/ubuntu/hoary/+source/'
     ...     'evolution/+translations')
-    >>> b'Catalan' in browser.contents
+    >>> six.ensure_str('Catalan') in browser.contents
     True
 
 But also, he doesn't want to see other languages in the list.  So, he
 shouldn't see eg. Japanese.
 
-    >>> b'Japanese' in browser.contents
+    >>> six.ensure_str('Japanese') in browser.contents
     False
 
 Next, if he chooses to view all the languages, he should see Japanese
 among the languages on the page.
 
     >>> browser.getLink('View template & all languages...').click()
-    >>> b'Japanese' in browser.contents
+    >>> six.ensure_str('Japanese') in browser.contents
     True
 
 So, everything is fine, and Carlos can sleep calmly.