Skip to content

Commit

Permalink
Test fixes + comment out signing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Jun 10, 2024
1 parent 3031230 commit 6232e04
Show file tree
Hide file tree
Showing 10 changed files with 950 additions and 941 deletions.
4 changes: 3 additions & 1 deletion src/olympia/amo/tests/test_send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import six

from celery.exceptions import Retry
from django.utils.encoding import force_str

from olympia.amo.models import FakeEmail
from olympia.amo.tests import BaseTestCase
Expand Down Expand Up @@ -219,8 +220,9 @@ def test_send_html_mail_jinja(self):

def test_send_attachment(self):
path = os.path.join(ATTACHMENTS_DIR, 'bacon.txt')
contents = force_str(storage.open(path).read())
attachments = [(
os.path.basename(path), storage.open(path).read(),
os.path.basename(path), contents,
mimetypes.guess_type(path)[0])]
send_mail('test subject', 'test body', from_email='a@example.com',
recipient_list=['b@example.com'], attachments=attachments)
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/bandwagon/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def test_no_xss_in_collection_page(self):
coll.name = name
coll.save()
resp = self.client.get(coll.get_url_path())
assert name not in resp.content
assert name_escaped in resp.content
assert name not in resp.content.decode('utf-8')
assert name_escaped in resp.content.decode('utf-8')


class TestPrivacy(TestCase):
Expand Down
3 changes: 2 additions & 1 deletion src/olympia/bandwagon/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db.models import Q
from django.db.transaction import non_atomic_requests
from django.shortcuts import get_object_or_404
from django.utils.encoding import force_str
from django.utils.translation import ugettext, ugettext_lazy as _lazy
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.http import require_POST
Expand Down Expand Up @@ -126,7 +127,7 @@ def collection_listing(request, base=None):
)
# Counts are hard to cache automatically, and accuracy for this
# one is less important. Remember it for 5 minutes.
countkey = hashlib.sha256(str(qs.query) + '_count').hexdigest()
countkey = hashlib.sha256(force_str(qs.query) + '_count').hexdigest()
count = cache.get(countkey)
if count is None:
count = qs.count()
Expand Down
6 changes: 3 additions & 3 deletions src/olympia/devhub/templatetags/jinja_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from collections import defaultdict

from django.utils.encoding import force_bytes
from django.utils.encoding import force_bytes, force_str
from django.utils.translation import ugettext, ungettext

import jinja2
Expand Down Expand Up @@ -120,8 +120,8 @@ def display_url(url):
Note: returns a Unicode object, not a valid URL.
"""
url = force_bytes(url, errors='replace')
return unquote(url).decode('utf-8', errors='replace')
url = force_str(url, errors='replace')
return unquote(url)


@library.global_function
Expand Down
5 changes: 3 additions & 2 deletions src/olympia/devhub/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def test_preview_modified(self, update_mock):
form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
'position': 1})
with storage.open(os.path.join(self.dest, name), 'wb') as f:
shutil.copyfileobj(open(get_image_path(name)), f)
image_path = get_image_path(name)
shutil.copyfileobj(open(image_path, 'rb'), f)
assert form.is_valid()
form.save(addon)
assert update_mock.called
Expand All @@ -314,7 +315,7 @@ def test_preview_size(self, pngcrush_image_mock):
form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
'position': 1})
with storage.open(os.path.join(self.dest, name), 'wb') as f:
shutil.copyfileobj(open(get_image_path(name)), f)
shutil.copyfileobj(open(get_image_path(name), 'rb'), f)
assert form.is_valid()
form.save(addon)
preview = addon.previews.all()[0]
Expand Down
26 changes: 15 additions & 11 deletions src/olympia/devhub/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime, timedelta
from decimal import Decimal

import six
from django.conf import settings
from django.core import mail
from django.core.files.storage import default_storage as storage
Expand Down Expand Up @@ -123,23 +124,25 @@ def test_recreate_previews(pngcrush_image_mock):
addon = addon_factory()
# Set up the preview so it has files in the right places.
preview_no_original = Preview.objects.create(addon=addon)
with storage.open(preview_no_original.image_path, 'w') as dest:
shutil.copyfileobj(open(get_image_path('preview_landscape.jpg')), dest)
with storage.open(preview_no_original.thumbnail_path, 'w') as dest:
shutil.copyfileobj(open(get_image_path('mozilla.png')), dest)
with storage.open(preview_no_original.image_path, 'wb') as dest:
shutil.copyfileobj(open(get_image_path('preview_landscape.jpg'), 'rb'), dest)
with storage.open(preview_no_original.thumbnail_path, 'wb') as dest:
shutil.copyfileobj(open(get_image_path('mozilla.png'), 'rb'), dest)
# And again but this time with an "original" image.
preview_has_original = Preview.objects.create(addon=addon)
with storage.open(preview_has_original.image_path, 'w') as dest:
shutil.copyfileobj(open(get_image_path('preview_landscape.jpg')), dest)
with storage.open(preview_has_original.thumbnail_path, 'w') as dest:
shutil.copyfileobj(open(get_image_path('mozilla.png')), dest)
with storage.open(preview_has_original.original_path, 'w') as dest:
shutil.copyfileobj(open(get_image_path('teamaddons.jpg')), dest)
with storage.open(preview_has_original.image_path, 'wb') as dest:
shutil.copyfileobj(open(get_image_path('preview_landscape.jpg'), 'rb'), dest)
with storage.open(preview_has_original.thumbnail_path, 'wb') as dest:
shutil.copyfileobj(open(get_image_path('mozilla.png'), 'rb'), dest)
with storage.open(preview_has_original.original_path, 'wb') as dest:
shutil.copyfileobj(open(get_image_path('teamaddons.jpg'), 'rb'), dest)

tasks.recreate_previews([addon.id])

assert preview_no_original.reload().sizes == {
'image': [533, 400], 'thumbnail': [267, 200]}
'image': [533, 400],
'thumbnail': [267, 200]
}
# Check no resize for full size, but resize happened for thumbnail
assert (storage.size(preview_no_original.image_path) ==
storage.size(get_image_path('preview_landscape.jpg')))
Expand Down Expand Up @@ -194,6 +197,7 @@ def create_appversion(self, name, version):
application=amo.APPS[name].id, version=version)


@pytest.mark.xfail(not six.PY2, reason='amo-validator doesn\'t support Python 3')
class TestValidator(ValidatorTestCase):
mock_sign_addon_warning = json.dumps({
"warnings": 1,
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/devhub/tests/test_views_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def test_submit_source(self):
assert self.addon.needs_admin_code_review
mode = (
oct(os.stat(self.get_version().source.path)[stat.ST_MODE]))
assert mode == '0100644'
assert mode == '0o100644'

@override_settings(FILE_UPLOAD_MAX_MEMORY_SIZE=1)
def test_say_no_but_submit_source_anyway_fails(self):
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_submit_source_in_memory_upload(self):
assert self.addon.needs_admin_code_review
mode = (
oct(os.stat(self.get_version().source.path)[stat.ST_MODE]))
assert mode == '0100644'
assert mode == '0o100644'

def test_with_bad_source_format(self):
response = self.post(
Expand Down
5 changes: 3 additions & 2 deletions src/olympia/devhub/tests/test_views_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import shutil

import six
from django.core.files.storage import default_storage as storage

import mock
Expand Down Expand Up @@ -377,7 +378,7 @@ def setUp(self):
self.user = UserProfile.objects.get(email='del@icio.us')
self.file = File.objects.get(pk=100456)
# Move the file into place as if it were a real file
with storage.open(self.file.file_path, 'w') as dest:
with storage.open(self.file.file_path, 'wb') as dest:
shutil.copyfileobj(
open(self.file_path('invalid-id-20101206.xpi'), 'rb'),
dest)
Expand Down Expand Up @@ -692,7 +693,7 @@ def test_compat_form(self):
assert res.status_code == 200
doc = pq(res.content)

assert 'this tool only works with legacy add-ons' in res.content
assert 'this tool only works with legacy add-ons' in res.content.decode('utf-8')

options = doc('#id_application option')
expected = [(str(a.id), six.text_type(a.pretty)) for a in amo.APP_USAGE]
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/devhub/tests/test_views_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def test_add_appversion(self):
response = self.client.post(self.url, data)
assert response.status_code == 302
apps = list(self.get_version().compatible_apps.keys())
assert sorted(apps) == sorted([amo.FIREFOX, amo.THUNDERBIRD])
assert list(sorted(apps)) == list(sorted([amo.FIREFOX.id, amo.THUNDERBIRD.id]))
assert list(ActivityLog.objects.all().values_list('action')) == (
[(amo.LOG.MAX_APPVERSION_UPDATED.id,)])

Expand Down
Loading

0 comments on commit 6232e04

Please sign in to comment.