launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24106
[Merge] ~cjwatson/launchpad:binary-file-attachments into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:binary-file-attachments into launchpad:master.
Commit message:
Use binary files for test HTTP file uploads
Recent versions of zope.testbrowser are strict about requiring HTTP file
uploads to be bytes rather than text. Adjust tests to comply with this.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/375384
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:binary-file-attachments into launchpad:master.
diff --git a/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt b/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
index 3354e8d..e4dd3cf 100644
--- a/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
+++ b/lib/lp/bugs/stories/bugattachments/xx-bugattachments.txt
@@ -13,13 +13,13 @@ When we're logged in we can access the page.
Let's add an attachment. First create a file-like object.
- >>> from cStringIO import StringIO
- >>> foo_file = StringIO('Traceback...')
+ >>> from io import BytesIO
+ >>> foo_file = BytesIO(b'Traceback...')
Leading and trailing whitespace are stripped from the description of the
attachment.
- >>> foo_file.seek(0)
+ >>> _ = foo_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo.txt')
>>> user_browser.getControl('Description').value = ' Some information '
@@ -58,7 +58,7 @@ also not necessary to enter a comment in order to add an attachment.
>>> user_browser.open(
... 'http://bugs.launchpad.test/firefox/+bug/1/+addcomment')
- >>> bar_file = StringIO('Traceback...')
+ >>> bar_file = BytesIO(b'Traceback...')
>>> user_browser.getControl('Attachment').add_file(
... bar_file, 'text/plain', 'bar.txt')
>>> user_browser.getControl('Description').value = ''
@@ -81,7 +81,7 @@ We can also declare an attachment to be a patch.
Leading and trailing whitespace are stripped from the description of the
attachment.
- >>> foo_file.seek(0)
+ >>> _ = foo_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo.diff')
>>> user_browser.getControl('Description').value = 'A fix for this bug.'
@@ -99,7 +99,7 @@ the flag "this attachment is a patch"...
>>> user_browser.open(
... 'http://bugs.launchpad.test/firefox/+bug/1/+addcomment')
- >>> foo_file.seek(0)
+ >>> _ = foo_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo2.diff')
>>> user_browser.getControl('Description').value = 'More data'
@@ -156,7 +156,7 @@ if we set the "patch" flag for this attachment...
>>> user_browser.open(
... 'http://bugs.launchpad.test/firefox/+bug/1/+addcomment')
- >>> foo_file.seek(0)
+ >>> _ = foo_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo.png')
>>> user_browser.getControl('Description').value = 'A better icon for foo'
@@ -213,7 +213,7 @@ when we tell it that plain text files whose names end in ".diff",
>>> user_browser.open(
... 'http://bugs.launchpad.test/firefox/+bug/1/+addcomment')
- >>> foo_file.seek(0)
+ >>> _ = foo_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo3.diff')
>>> user_browser.getControl('Description').value = 'the foo3 patch'
@@ -228,7 +228,7 @@ when we tell it that plain text files whose names end in ".diff",
>>> user_browser.open(
... 'http://bugs.launchpad.test/firefox/+bug/1/+addcomment')
- >>> foo_file.seek(0)
+ >>> _ = foo_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo4.debdiff')
>>> user_browser.getControl('Description').value = 'the foo4 patch'
@@ -243,7 +243,7 @@ when we tell it that plain text files whose names end in ".diff",
>>> user_browser.open(
... 'http://bugs.launchpad.test/firefox/+bug/1/+addcomment')
- >>> foo_file.seek(0)
+ >>> _ = foo_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo5.patch')
>>> user_browser.getControl('Description').value = 'the foo5 patch'
@@ -360,13 +360,11 @@ enabled.
Let's add a normal text file...
- >>> from StringIO import StringIO
-
>>> user_browser.open(
... "http://bugs.launchpad.test/firefox/+bug/1/+addcomment")
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO("Traceback..."), "text/plain", "foo.txt")
+ ... BytesIO(b"Traceback..."), "text/plain", "foo.txt")
>>> user_browser.getControl("Description").value = "Some information."
>>> user_browser.getControl(
... name="field.comment").value = "Added some information."
@@ -379,7 +377,7 @@ And a patch...
... "/+bug/2/+addcomment")
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO("Patch..."), "text/plain", "foo.patch")
+ ... BytesIO(b"Patch..."), "text/plain", "foo.patch")
>>> user_browser.getControl("patch").selected = True
>>> user_browser.getControl("Description").value = "A patch."
>>> user_browser.getControl(
@@ -392,7 +390,7 @@ And another patch...
... "http://bugs.launchpad.test/firefox/+bug/4/+addcomment")
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO("Patch..."), "text/plain", "foo.patch")
+ ... BytesIO(b"Patch..."), "text/plain", "foo.patch")
>>> user_browser.getControl("patch").selected = True
>>> user_browser.getControl("Description").value = "A patch."
>>> user_browser.getControl(
diff --git a/lib/lp/bugs/stories/bugattachments/xx-delete-bug-attachment.txt b/lib/lp/bugs/stories/bugattachments/xx-delete-bug-attachment.txt
index 2db3262..03901c1 100644
--- a/lib/lp/bugs/stories/bugattachments/xx-delete-bug-attachment.txt
+++ b/lib/lp/bugs/stories/bugattachments/xx-delete-bug-attachment.txt
@@ -3,10 +3,10 @@
If some attachment gets added which isn't relevant to the bug, it can be
deleted again from the bug attachment edit page.
- >>> from cStringIO import StringIO
+ >>> from io import BytesIO
>>> user_browser.open('http://launchpad.test/bugs/2')
>>> user_browser.open(user_browser.url + '/+addcomment')
- >>> foo_file = StringIO('V1agra.')
+ >>> foo_file = BytesIO(b'V1agra.')
>>> user_browser.getControl('Attachment').add_file(
... foo_file, 'text/plain', 'foo.txt')
>>> user_browser.getControl('Description').value = 'Great deal'
diff --git a/lib/lp/bugs/stories/bugattachments/xx-display-filesize-attachment.txt b/lib/lp/bugs/stories/bugattachments/xx-display-filesize-attachment.txt
index 08d5101..83571e0 100644
--- a/lib/lp/bugs/stories/bugattachments/xx-display-filesize-attachment.txt
+++ b/lib/lp/bugs/stories/bugattachments/xx-display-filesize-attachment.txt
@@ -2,9 +2,8 @@
File size and mime type are displayed for each attachment
- >>> from cStringIO import StringIO
- >>> filecontent = '123456789' * 30
- >>> foo_file = StringIO(filecontent)
+ >>> from io import BytesIO
+ >>> foo_file = BytesIO(b'123456789' * 30)
>>> user_browser.open(
... "http://bugs.launchpad.test/firefox/+bug/1/+addcomment")
@@ -34,8 +33,7 @@ A filesize of 2700 byte is displayed in 'KiB'
... """
>>> config.push('max_size_data', max_size_data)
- >>> filecontent = '123456789' * 300
- >>> foo_file = StringIO(filecontent)
+ >>> foo_file = BytesIO(b'123456789' * 300)
>>> user_browser.open(
... "http://bugs.launchpad.test/firefox/+bug/1/+addcomment")
diff --git a/lib/lp/bugs/stories/bugs/xx-bug-comment-attach-file.txt b/lib/lp/bugs/stories/bugs/xx-bug-comment-attach-file.txt
index c7927bf..75d4429 100644
--- a/lib/lp/bugs/stories/bugs/xx-bug-comment-attach-file.txt
+++ b/lib/lp/bugs/stories/bugs/xx-bug-comment-attach-file.txt
@@ -25,12 +25,12 @@ So let's login and add a comment.
When an attachment is submitted, the comment and description are optional.
- >>> from StringIO import StringIO
+ >>> from io import BytesIO
>>> user_browser.open(
... "http://bugs.launchpad.test/firefox/+bug/1/+addcomment-form")
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO("a test file"), "text/plain", "foo.txt")
+ ... BytesIO(b"a test file"), "text/plain", "foo.txt")
>>> user_browser.getControl("Post Comment").click()
>>> print_feedback_messages(user_browser.contents)
@@ -43,7 +43,7 @@ A comment and attachment can be submitted in one request.
>>> user_browser.getControl(
... name='field.comment').value = "this is a comment"
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO("some file"), "text/plain", "bar.txt")
+ ... BytesIO(b"some file"), "text/plain", "bar.txt")
>>> user_browser.getControl("Description").value = "some file"
>>> user_browser.getControl("Post Comment").click()
@@ -59,7 +59,7 @@ You cannot upload an empty attachment.
>>> user_browser.open(
... "http://bugs.launchpad.test/firefox/+bug/1/+addcomment-form")
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO(""), "text/plain", "foo.txt")
+ ... BytesIO(b""), "text/plain", "foo.txt")
>>> user_browser.getControl("Post Comment").click()
>>> print(user_browser.url)
@@ -80,7 +80,7 @@ option in launchpad.conf. In our example, the size is limited to 1024.
>>> user_browser.open(
... "http://bugs.launchpad.test/firefox/+bug/1/+addcomment-form")
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO("x"*1025), "text/plain", "foo.txt")
+ ... BytesIO(b"x" * 1025), "text/plain", "foo.txt")
>>> user_browser.getControl("Post Comment").click()
>>> print_feedback_messages(user_browser.contents)
@@ -92,7 +92,7 @@ The comment/attach file form is available from a link on the bug page.
>>> user_browser.open(
... "http://bugs.launchpad.test/firefox/+bug/1/+addcomment")
>>> user_browser.getControl("Attachment").add_file(
- ... StringIO("a test file"), "text/plain", "foo.txt")
+ ... BytesIO(b"a test file"), "text/plain", "foo.txt")
>>> user_browser.getControl("Description").value = "some file"
>>> user_browser.getControl("Post Comment").click()
diff --git a/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.txt b/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.txt
index eb676cb..6d3d2a1 100644
--- a/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.txt
+++ b/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.txt
@@ -16,7 +16,7 @@ comment.
>>> from lp.services.config import config
>>> testfiles = os.path.join(config.root, 'lib/lp/bugs/tests/testfiles')
>>> extra_filebug_data = open(
- ... os.path.join(testfiles, 'extra_filebug_data.msg'))
+ ... os.path.join(testfiles, 'extra_filebug_data.msg'), 'rb')
NOTE: The form names are used instead of their labels here, because
external tools depend on them.
@@ -157,7 +157,7 @@ If the uploaded message contains a Subject field in the initial headers,
that will be used to automatically fill in a suggested title.
>>> extra_filebug_data_with_subject = open(
- ... os.path.join(testfiles, 'extra_filebug_data_subject.msg'))
+ ... os.path.join(testfiles, 'extra_filebug_data_subject.msg'), 'rb')
>>> anon_browser.open('http://launchpad.test/+storeblob')
>>> anon_browser.getControl(name='field.blob').add_file( # Don't change!
... extra_filebug_data_with_subject, 'not/important', 'not.important')
@@ -186,7 +186,7 @@ If the uploaded message contains a Tags field, the tags widget will be
initialized with that value.
>>> extra_filebug_data_with_subject = open(
- ... os.path.join(testfiles, 'extra_filebug_data_tags.msg'))
+ ... os.path.join(testfiles, 'extra_filebug_data_tags.msg'), 'rb')
>>> anon_browser.open('http://launchpad.test/+storeblob')
>>> anon_browser.getControl(name='field.blob').add_file( # Don't change!
... extra_filebug_data_with_subject, 'not/important', 'not.important')
@@ -249,8 +249,11 @@ Our test data contains such a header, mentioning two HWDB submision key.
The database knows only the first key.
>>> extra_filebug_data_with_hwdb_submission = open(
- ... os.path.join(testfiles, 'extra_filebug_data_hwdb_submission.msg'))
- >>> print(extra_filebug_data_with_hwdb_submission.read().split('\n')[2])
+ ... os.path.join(testfiles, 'extra_filebug_data_hwdb_submission.msg'),
+ ... 'rb')
+ >>> print(
+ ... extra_filebug_data_with_hwdb_submission.read()
+ ... .decode('UTF-8').split('\n')[2])
HWDB-Submission: sample-submission, non-existing-submission-key
Once we submit the bug report...
diff --git a/lib/lp/bugs/stories/guided-filebug/xx-filebug-attachments.txt b/lib/lp/bugs/stories/guided-filebug/xx-filebug-attachments.txt
index 191c3e1..5214136 100644
--- a/lib/lp/bugs/stories/guided-filebug/xx-filebug-attachments.txt
+++ b/lib/lp/bugs/stories/guided-filebug/xx-filebug-attachments.txt
@@ -20,9 +20,9 @@ guided filebug form.
No Privileges Person chooses to add an attachment to the bug. We create
a file-like object to demonstrate this.
- >>> from cStringIO import StringIO
- >>> example_file = StringIO('Traceback...')
- >>> example_file.seek(0)
+ >>> from io import BytesIO
+ >>> example_file = BytesIO(b'Traceback...')
+ >>> _ = example_file.seek(0)
>>> user_browser.getControl('Attachment').add_file(
... example_file, 'text/plain', 'example.txt')
diff --git a/lib/lp/bugs/stories/guided-filebug/xx-ubuntu-filebug.txt b/lib/lp/bugs/stories/guided-filebug/xx-ubuntu-filebug.txt
index 88d45b5..f614ab7 100644
--- a/lib/lp/bugs/stories/guided-filebug/xx-ubuntu-filebug.txt
+++ b/lib/lp/bugs/stories/guided-filebug/xx-ubuntu-filebug.txt
@@ -65,7 +65,7 @@ Filing bugs with Apport also allows us to get to the bug filing interface.
>>> import os.path
>>> testfiles = os.path.join(config.root, 'lib/lp/bugs/tests/testfiles')
>>> extra_filebug_data = open(
- ... os.path.join(testfiles, 'extra_filebug_data.msg'))
+ ... os.path.join(testfiles, 'extra_filebug_data.msg'), 'rb')
>>> anon_browser.open('http://launchpad.test/+storeblob')
>>> anon_browser.getControl(name='field.blob').add_file(
... extra_filebug_data, 'not/important', 'not.important')
diff --git a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
index e571664..988534b 100644
--- a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
+++ b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
@@ -6,7 +6,7 @@ Submissions to the hardware database are done at the following URL:
All form fields must be filled with valid values.
- >>> from StringIO import StringIO
+ >>> from io import BytesIO
>>> submit_data = {
... 'Date Created:': '2007-01-01',
... 'Format Version:': ['VERSION_1'],
@@ -21,7 +21,7 @@ All form fields must be filled with valid values.
... 'Private Submission': False,
... 'Contactable': False,
... }
- >>> submit_file = StringIO('some data')
+ >>> submit_file = BytesIO(b'some data')
>>> def fill_form(
... browser, submit_data, submit_data_checkboxes, filedata, filename):
... for label in submit_data.keys():
@@ -263,7 +263,6 @@ Submissions that are marked as private are only displayed to the
submitter themselves.
>>> browser.open('http://launchpad.test/+hwdb/+submit')
- >>> from StringIO import StringIO
>>> submit_data = {
... 'Date Created:': '2007-01-01',
... 'Format Version:': ['VERSION_1'],
@@ -278,19 +277,6 @@ submitter themselves.
... 'Private Submission': True,
... 'Contactable': False,
... }
- >>> submit_file = StringIO('some data')
- >>> def fill_form(
- ... browser, submit_data, submit_data_checkboxes, filedata, filename):
- ... for label in submit_data.keys():
- ... control = browser.getControl(label)
- ... control.value = submit_data[label]
- ... for label in submit_data_checkboxes.keys():
- ... control = browser.getControl(label)
- ... control.selected = submit_data_checkboxes[label]
- ... if filedata is not None:
- ... filedata.seek(0)
- ... control = browser.getControl('Submission data:')
- ... control.add_file(filedata, 'text/plain', filename)
>>> fill_form(
... browser, submit_data, submit_data_checkboxes, submit_file,
... 'test2.txt')
@@ -344,7 +330,6 @@ visible for members of the team and admins.
... 'Private Submission': True,
... 'Contactable': False,
... }
- >>> submit_file = StringIO('some data')
>>> fill_form(
... browser, team_submit_data, team_submit_data_checkboxes,
... submit_file, 'teamtest.txt')
diff --git a/lib/lp/registry/stories/product/xx-product-files.txt b/lib/lp/registry/stories/product/xx-product-files.txt
index 02e6813..4d72d4d 100644
--- a/lib/lp/registry/stories/product/xx-product-files.txt
+++ b/lib/lp/registry/stories/product/xx-product-files.txt
@@ -226,9 +226,9 @@ The maximum size of the upload file is shown on the page.
Create a file to upload, and upload it. We'll also upload a dummy signature.
Uploading file signatures is optional, so we'll just try it this once.
- >>> from cStringIO import StringIO
- >>> foo_file = StringIO('Foo installer package...')
- >>> foo_signature = StringIO('Dummy GPG signature for the Foo installer')
+ >>> from io import BytesIO
+ >>> foo_file = BytesIO(b'Foo installer package...')
+ >>> foo_signature = BytesIO(b'Dummy GPG signature for the Foo installer')
>>> firefox_owner.getControl(name='field.filecontent').add_file(foo_file,
... 'text/plain', 'foo.txt')
>>> firefox_owner.getControl(name='field.signature').add_file(
@@ -244,7 +244,7 @@ A file can be uploaded without a GPG signature.
>>> firefox_owner.open(
... 'http://launchpad.test/firefox/1.0/1.0.0/+adddownloadfile')
- >>> bar_file = StringIO('Bar installer package...')
+ >>> bar_file = BytesIO(b'Bar installer package...')
>>> firefox_owner.getControl(name='field.filecontent').add_file(bar_file,
... 'text/plain', 'bar.txt')
>>> firefox_owner.getControl('Description').value="Bar installer"
@@ -308,7 +308,7 @@ Try to add a file with no description.
Create a file to upload.
- >>> foo_file = StringIO('Foo installer package...')
+ >>> foo_file = BytesIO(b'Foo installer package...')
>>> firefox_owner.getControl(name='field.filecontent').add_file(foo_file,
... 'text/plain', 'foo1.txt')
>>> firefox_owner.getControl(
@@ -325,7 +325,7 @@ Try to add a file that is empty.
Create a file to upload.
- >>> foo_file = StringIO('')
+ >>> foo_file = BytesIO(b'')
>>> firefox_owner.getControl(name='field.filecontent').add_file(foo_file,
... 'text/plain', 'foo2.txt')
>>> firefox_owner.getControl('Description').value="Foo installer"
@@ -340,7 +340,7 @@ Now let's successfully upload two more files.
>>> firefox_owner.open('http://launchpad.test/firefox/1.0/1.0.0')
>>> firefox_owner.getLink('Add download file').click()
- >>> foo_file = StringIO('Foo2 installer package...')
+ >>> foo_file = BytesIO(b'Foo2 installer package...')
>>> firefox_owner.getControl(name='field.filecontent').add_file(foo_file,
... 'text/plain', 'foo2.txt')
>>> firefox_owner.getControl('Description').value="Foo2 installer"
@@ -352,7 +352,7 @@ Now let's successfully upload two more files.
>>> firefox_owner.open('http://launchpad.test/firefox/1.0/1.0.0')
>>> firefox_owner.getLink('Add download file').click()
- >>> foo_file = StringIO('Foo installer package...')
+ >>> foo_file = BytesIO(b'Foo installer package...')
>>> firefox_owner.getControl(name='field.filecontent').add_file(foo_file,
... 'text/plain', 'foo3.txt')
>>> firefox_owner.getControl('Description').value="Foo3 installer"
@@ -366,7 +366,7 @@ Add a file to a different release on the same project.
>>> firefox_owner.open('http://launchpad.test/firefox/trunk/0.9')
>>> firefox_owner.getLink('Add download file').click()
- >>> foo_file = StringIO('Foo installer package...')
+ >>> foo_file = BytesIO(b'Foo installer package...')
>>> firefox_owner.getControl(name='field.filecontent').add_file(foo_file,
... 'text/plain', 'foo09.txt')
>>> firefox_owner.getControl('Description').value="Foo09 installer"
diff --git a/lib/lp/registry/tests/test_product.py b/lib/lp/registry/tests/test_product.py
index 00e840d..c28eb8b 100644
--- a/lib/lp/registry/tests/test_product.py
+++ b/lib/lp/registry/tests/test_product.py
@@ -3,11 +3,11 @@
__metaclass__ = type
-from cStringIO import StringIO
from datetime import (
datetime,
timedelta,
)
+from io import BytesIO
import pytz
from storm.locals import Store
@@ -1421,8 +1421,8 @@ class TestProductFiles(TestCase):
filename = u'foo\xa5.txt'.encode('utf-8')
firefox_owner.open(
'http://launchpad.test/firefox/1.0/1.0.0/+adddownloadfile')
- foo_file = StringIO('Foo installer package...')
- foo_signature = StringIO('Dummy GPG signature for the Foo installer')
+ foo_file = BytesIO(b'Foo installer package...')
+ foo_signature = BytesIO(b'Dummy GPG signature for the Foo installer')
firefox_owner.getControl(name='field.filecontent').add_file(
foo_file, 'text/plain', filename)
firefox_owner.getControl(name='field.signature').add_file(
diff --git a/lib/lp/services/temporaryblobstorage/stories/xx-tempstorage.txt b/lib/lp/services/temporaryblobstorage/stories/xx-tempstorage.txt
index 2a8948d..c683501 100644
--- a/lib/lp/services/temporaryblobstorage/stories/xx-tempstorage.txt
+++ b/lib/lp/services/temporaryblobstorage/stories/xx-tempstorage.txt
@@ -9,8 +9,8 @@ stored for a short period of time, and deleted if unused.
And we test the ability to upload a blob. We have a \0 character in the
middle of the data so we can ensure binary data is handled correctly.
- >>> from cStringIO import StringIO
- >>> blob_file = StringIO('abcd\0efg')
+ >>> from io import BytesIO
+ >>> blob_file = BytesIO(b'abcd\0efg')
>>> anon_browser.getControl('BLOB').add_file(
... blob_file, 'ignored/mimetype', 'ignored.filename'
... )
diff --git a/lib/lp/testing/branding.py b/lib/lp/testing/branding.py
index 0a46ff7..3bbc542 100644
--- a/lib/lp/testing/branding.py
+++ b/lib/lp/testing/branding.py
@@ -35,12 +35,12 @@ def set_branding(browser, icon=True, logo=True, mugshot=True):
if icon:
browser.getControl(name='field.icon.action').value = ['change']
browser.getControl(name='field.icon.image').add_file(
- open(icon_file), 'image/png', 'icon.png')
+ open(icon_file, 'rb'), 'image/png', 'icon.png')
if logo:
browser.getControl(name='field.logo.action').value = ['change']
browser.getControl(name='field.logo.image').add_file(
- open(logo_file), 'image/png', 'logo.png')
+ open(logo_file, 'rb'), 'image/png', 'logo.png')
if mugshot:
browser.getControl(name='field.mugshot.action').value = ['change']
browser.getControl(name='field.mugshot.image').add_file(
- open(mugshot_file), 'image/png', 'mugshot.png')
+ open(mugshot_file, 'rb'), 'image/png', 'mugshot.png')
diff --git a/lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt b/lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt
index 897f81d..f8387f1 100644
--- a/lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt
+++ b/lib/lp/translations/stories/importqueue/xx-translation-import-queue-edit-autofilling.txt
@@ -8,7 +8,7 @@ First, we need to feed the import queue.
>>> test_file_name = os.path.join(
... os.path.dirname(lp.translations.__file__),
... 'stories/importqueue/xx-translation-import-queue-edit-autofilling.tar.gz')
- >>> tarball = open(test_file_name)
+ >>> tarball = open(test_file_name, 'rb')
>>> browser = setupBrowser(auth='Basic carlos@xxxxxxxxxxxxx:test')
>>> browser.open(
diff --git a/lib/lp/translations/stories/importqueue/xx-translation-import-queue-filtering.txt b/lib/lp/translations/stories/importqueue/xx-translation-import-queue-filtering.txt
index a6fe5fb..7910e05 100644
--- a/lib/lp/translations/stories/importqueue/xx-translation-import-queue-filtering.txt
+++ b/lib/lp/translations/stories/importqueue/xx-translation-import-queue-filtering.txt
@@ -11,7 +11,7 @@ is no human readable labels associated with them.
>>> test_file_name = os.path.join(
... os.path.dirname(lp.translations.__file__),
... 'stories/importqueue/xx-translation-import-queue-filtering.tar.gz')
- >>> tarball = open(test_file_name)
+ >>> tarball = open(test_file_name, 'rb')
Our star for this session is Carlos, who has full access rights to the
import queue.
@@ -277,13 +277,13 @@ It's also possible to filter by target. In this case, Evolution.
Carlos uploads files for Evolution in Ubuntu Hoary.
>>> import transaction
- >>> from StringIO import StringIO
+ >>> from io import BytesIO
>>> admin_browser.open(
... 'http://translations.launchpad.test/ubuntu/hoary/+source/'
... 'evolution/+pots/evolution-2.2/+upload')
>>> file_ctrl = admin_browser.getControl('File:')
>>> file_ctrl.add_file(
- ... StringIO('foo'), 'application/x-po', 'foo.pot')
+ ... BytesIO(b'foo'), 'application/x-po', 'foo.pot')
>>> admin_browser.getControl('Upload').click()
>>> for tag in find_tags_by_class(admin_browser.contents, 'message'):
... print(extract_text(tag.renderContents()))
diff --git a/lib/lp/translations/stories/importqueue/xx-translation-import-queue.txt b/lib/lp/translations/stories/importqueue/xx-translation-import-queue.txt
index 1643549..f22031e 100644
--- a/lib/lp/translations/stories/importqueue/xx-translation-import-queue.txt
+++ b/lib/lp/translations/stories/importqueue/xx-translation-import-queue.txt
@@ -112,8 +112,8 @@ Now, we attach a new file to an already existing translation resource.
>>> upload = browser.getControl('File')
>>> upload
<Control name='file' type='file'>
- >>> from StringIO import StringIO
- >>> upload.add_file(StringIO('# foo\n'),
+ >>> from io import BytesIO
+ >>> upload.add_file(BytesIO(b'# foo\n'),
... 'text/x-gettext-translation-template', 'evolution.pot')
>>> browser.getControl('Upload').click()
>>> print(browser.url)
@@ -346,7 +346,7 @@ Let's check tar.bz2 uploads. They work ;-)
>>> test_file_name = os.path.join(
... os.path.dirname(lp.translations.__file__),
... 'stories/importqueue/xx-translation-import-queue.tar.bz2')
- >>> tarball = open(test_file_name)
+ >>> tarball = open(test_file_name, 'rb')
>>> evo_owner_browser.getControl('File').add_file(
... tarball, 'application/x-bzip', test_file_name)
@@ -379,7 +379,7 @@ Let's try now a tarball upload. Should work:
>>> test_file_name = os.path.join(
... os.path.dirname(lp.translations.__file__),
... 'stories/importqueue/xx-translation-import-queue.tar')
- >>> tarball = open(test_file_name)
+ >>> tarball = open(test_file_name, 'rb')
>>> evo_owner_browser.getControl('File').add_file(
... tarball, 'application/x-gzip', test_file_name)
@@ -400,7 +400,7 @@ We can handle an empty file disguised as a bzipped tarfile:
>>> test_file_name = os.path.join(
... os.path.dirname(lp.translations.__file__),
... 'stories/importqueue/empty.tar.bz2')
- >>> tarball = open(test_file_name)
+ >>> tarball = open(test_file_name, 'rb')
>>> evo_owner_browser.getControl('File').add_file(
... tarball, 'application/x-gzip', test_file_name)
@@ -420,7 +420,7 @@ And also a truncated tarball inside a bzip2 wrapper:
>>> test_file_name = os.path.join(
... os.path.dirname(lp.translations.__file__),
... 'stories/importqueue/truncated.tar.bz2')
- >>> tarball = open(test_file_name)
+ >>> tarball = open(test_file_name, 'rb')
>>> evo_owner_browser.getControl('File').add_file(
... tarball, 'application/x-gzip', test_file_name)
@@ -438,7 +438,7 @@ says that.
... 'http://translations.launchpad.test/evolution/trunk/'
... '+translations-upload')
>>> evo_owner_browser.getControl('File').add_file(
- ... StringIO('foo'), 'application/x-gzip', test_file_name)
+ ... BytesIO(b'foo'), 'application/x-gzip', test_file_name)
>>> evo_owner_browser.getControl('Upload').click()
>>> evo_owner_browser.url
'http://translations.launchpad.test/evolution/trunk/+translations-upload'
diff --git a/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt b/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
index 7f10de4..e058852 100644
--- a/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
+++ b/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
@@ -1113,7 +1113,7 @@ an error message back.
Uploading files with an unkown file format notifies the user that it
cannot be handled.
- >>> from StringIO import StringIO
+ >>> from io import BytesIO
>>> af_file = b'''
... # Afrikaans translation for Silky
... # Copyright (C) 2004 Free Software Foundation, Inc.
@@ -1141,7 +1141,7 @@ cannot be handled.
... msgstr "Hierdie program loop as prosesnommer %1."'''
>>> upload = admin_browser.getControl(name='file')
- >>> upload.add_file(StringIO(af_file), 'application/msword', 'af.doc')
+ >>> upload.add_file(BytesIO(af_file), 'application/msword', 'af.doc')
>>> admin_browser.getControl('Upload').click()
>>> print(admin_browser.url)
http://translations.launchpad.test/ubuntu/hoary/+source/evolution/+pots/evolution-2.2/af/+upload
@@ -1154,7 +1154,7 @@ cannot be handled.
With all the correct information, a file can be uploaded.
>>> upload = admin_browser.getControl(name='file')
- >>> upload.add_file(StringIO(af_file), 'application/x-po', 'af.po')
+ >>> upload.add_file(BytesIO(af_file), 'application/x-po', 'af.po')
>>> admin_browser.getControl('Upload').click()
>>> print(admin_browser.url)
http://translations.launchpad.test/ubuntu/hoary/+source/evolution/+pots/evolution-2.2/af/+upload