Fix failing tests
This commit is contained in:
Родитель
0e346e7e00
Коммит
b0be96378d
|
@ -1338,11 +1338,11 @@ class TestAddonSharing(amo.tests.TestCase):
|
|||
assert iri_to_uri(summary) in r['Location']
|
||||
|
||||
|
||||
@patch.object(settings, 'RECAPTCHA_PRIVATE_KEY', 'something')
|
||||
class TestReportAbuse(amo.tests.TestCase):
|
||||
fixtures = ['addons/persona', 'base/addon_3615', 'base/users']
|
||||
|
||||
def setUp(self):
|
||||
settings.RECAPTCHA_PRIVATE_KEY = 'something'
|
||||
self.full_page = reverse('addons.abuse', args=['a3615'])
|
||||
|
||||
@patch('captcha.fields.ReCaptchaField.clean')
|
||||
|
|
|
@ -8,12 +8,14 @@ from django.core.cache import cache
|
|||
from django.core.validators import ValidationError
|
||||
from django.utils import translation
|
||||
|
||||
import jingo
|
||||
import mock
|
||||
from nose.tools import eq_, assert_raises, raises
|
||||
|
||||
from amo.utils import (cache_ns_key, escape_all, find_language,
|
||||
LocalFileStorage, no_translation, resize_image,
|
||||
rm_local_tmp_dir, slugify, slug_validator, to_language)
|
||||
LocalFileStorage, no_jinja_autoescape, no_translation,
|
||||
resize_image, rm_local_tmp_dir, slugify, slug_validator,
|
||||
to_language)
|
||||
from product_details import product_details
|
||||
|
||||
u = u'Ελληνικά'
|
||||
|
@ -45,8 +47,7 @@ def test_slugify():
|
|||
# I don't really care what slugify returns. Just don't crash.
|
||||
(u'x荿', u'x\u837f'),
|
||||
(u'ϧ蒬蓣', u'\u03e7\u84ac\u84e3'),
|
||||
(u'¿x', u'x'),
|
||||
]
|
||||
(u'¿x', u'x')]
|
||||
for val, expected in s:
|
||||
yield check, val, expected
|
||||
|
||||
|
@ -158,7 +159,7 @@ class TestLocalFileStorage(unittest.TestCase):
|
|||
dp = os.path.join(self.tmp, 'path', 'to')
|
||||
self.stor.open(os.path.join(dp, 'file.txt'), 'w').close()
|
||||
assert os.path.exists(self.stor.path(dp)), (
|
||||
'Directory not created: %r' % dp)
|
||||
'Directory not created: %r' % dp)
|
||||
|
||||
def test_do_not_make_file_dirs_when_reading(self):
|
||||
fpath = os.path.join(self.tmp, 'file.txt')
|
||||
|
@ -248,3 +249,14 @@ def test_escape_all():
|
|||
]
|
||||
for val, expected in s:
|
||||
yield check, val, expected
|
||||
|
||||
|
||||
def test_no_jinja_autoescape():
|
||||
val = 'some double quote: " and a <'
|
||||
tpl = '{{ val }}'
|
||||
ctx = {'val': val}
|
||||
template = jingo.env.from_string(tpl)
|
||||
eq_(template.render(ctx), 'some double quote: " and a <')
|
||||
with no_jinja_autoescape():
|
||||
template = jingo.env.from_string(tpl)
|
||||
eq_(template.render(ctx), 'some double quote: " and a <')
|
||||
|
|
|
@ -144,6 +144,7 @@ def paginate(request, queryset, per_page=20, count=None):
|
|||
paginated.url = u'%s?%s' % (request.path, request.GET.urlencode())
|
||||
return paginated
|
||||
|
||||
|
||||
def send_mail(subject, message, from_email=None, recipient_list=None,
|
||||
fail_silently=False, use_blacklist=True, perm_setting=None,
|
||||
manage_url=None, headers=None, cc=None, real_email=False,
|
||||
|
@ -230,9 +231,10 @@ def send_mail(subject, message, from_email=None, recipient_list=None,
|
|||
for recipient in white_list:
|
||||
# Add unsubscribe link to footer.
|
||||
token, hash = UnsubscribeCode.create(recipient)
|
||||
unsubscribe_url = absolutify(reverse('users.unsubscribe',
|
||||
args=[token, hash, perm_setting.short],
|
||||
add_prefix=False))
|
||||
unsubscribe_url = absolutify(
|
||||
reverse('users.unsubscribe',
|
||||
args=[token, hash, perm_setting.short],
|
||||
add_prefix=False))
|
||||
|
||||
context_options = {
|
||||
'message': message,
|
||||
|
@ -268,36 +270,37 @@ def send_mail(subject, message, from_email=None, recipient_list=None,
|
|||
return result
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def no_jinja_autoescape():
|
||||
"""Disable Jinja2 autoescape."""
|
||||
autoescape_orig = env.autoescape
|
||||
env.autoescape = False
|
||||
yield
|
||||
env.autoescape = autoescape_orig
|
||||
|
||||
|
||||
def send_mail_jinja(subject, template, context, *args, **kwargs):
|
||||
"""Sends mail using a Jinja template with autoescaping turned off.
|
||||
|
||||
Jinja is especially useful for sending email since it has whitespace
|
||||
control.
|
||||
"""
|
||||
# Get a jinja environment so we can override autoescaping for text emails.
|
||||
autoescape_orig = env.autoescape
|
||||
env.autoescape = False
|
||||
template = env.get_template(template)
|
||||
with no_jinja_autoescape():
|
||||
template = env.get_template(template)
|
||||
msg = send_mail(subject, template.render(context), *args, **kwargs)
|
||||
env.autoescape = autoescape_orig
|
||||
return msg
|
||||
|
||||
|
||||
def send_html_mail_jinja(subject, html_template, text_template, context,
|
||||
*args, **kwargs):
|
||||
"""Sends HTML mail using a Jinja template with autoescaping turned off."""
|
||||
autoescape_orig = env.autoescape
|
||||
env.autoescape = False
|
||||
|
||||
html_template = env.get_template(html_template)
|
||||
text_template = env.get_template(text_template)
|
||||
|
||||
# Get a jinja environment so we can override autoescaping for text emails.
|
||||
with no_jinja_autoescape():
|
||||
html_template = env.get_template(html_template)
|
||||
text_template = env.get_template(text_template)
|
||||
msg = send_mail(subject, text_template.render(context),
|
||||
html_message=html_template.render(context), *args,
|
||||
**kwargs)
|
||||
|
||||
env.autoescape = autoescape_orig
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
|
@ -649,8 +652,6 @@ def redirect_for_login(request):
|
|||
return http.HttpResponseRedirect(url)
|
||||
|
||||
|
||||
|
||||
|
||||
def cache_ns_key(namespace, increment=False):
|
||||
"""
|
||||
Returns a key with namespace value appended. If increment is True, the
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import path
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
|
@ -70,9 +69,12 @@ def _uploader(resize_size, final_size):
|
|||
|
||||
if isinstance(final_size, list):
|
||||
uploadto = user_media_path('addon_icons')
|
||||
os.makedirs(uploadto)
|
||||
try:
|
||||
os.makedirs(uploadto)
|
||||
except OSError:
|
||||
pass
|
||||
for rsize, fsize in zip(resize_size, final_size):
|
||||
dest_name = str(path.path(uploadto) / '1234')
|
||||
dest_name = os.path.join(uploadto, '1234')
|
||||
|
||||
tasks.resize_icon(src.name, dest_name, resize_size, locally=True)
|
||||
dest_image = Image.open(open('%s-%s.png' % (dest_name, rsize)))
|
||||
|
@ -81,6 +83,7 @@ def _uploader(resize_size, final_size):
|
|||
if os.path.exists(dest_image.filename):
|
||||
os.remove(dest_image.filename)
|
||||
assert not os.path.exists(dest_image.filename)
|
||||
shutil.rmtree(uploadto)
|
||||
else:
|
||||
dest = tempfile.mktemp(suffix='.png')
|
||||
tasks.resize_icon(src.name, dest, resize_size, locally=True)
|
||||
|
|
|
@ -107,9 +107,6 @@ class HelpersTest(amo.tests.TestCase):
|
|||
eq_(doc('a').text(), 'See All Reviews')
|
||||
|
||||
def test_report_review_popup(self):
|
||||
# Set autoescape to False otherwise the inner ``pretty_form`` is
|
||||
# escaped and pyquery can't access the ``name`` attribute.
|
||||
jingo.register.env.autoescape = False
|
||||
doc = pq(self.render('{{ report_review_popup() }}'))
|
||||
eq_(doc('.popup.review-reason').length, 1)
|
||||
for flag, text in ReviewFlag.FLAGS:
|
||||
|
@ -117,9 +114,6 @@ class HelpersTest(amo.tests.TestCase):
|
|||
eq_(doc('form input[name=note]').length, 1)
|
||||
|
||||
def test_edit_review_form(self):
|
||||
# Set autoescape to False otherwise the inner ``pretty_form`` is
|
||||
# escaped and pyquery can't access the ``name`` attribute.
|
||||
jingo.register.env.autoescape = False
|
||||
doc = pq(self.render('{{ edit_review_form() }}'))
|
||||
eq_(doc('#review-edit-form').length, 1)
|
||||
eq_(doc('p.req').length, 1)
|
||||
|
|
|
@ -25,6 +25,7 @@ class TestXSS(amo.tests.TestCase):
|
|||
'tags/tags.json']
|
||||
|
||||
xss = "<script src='foo.bar'>"
|
||||
escaped = "<script src='foo.bar'>"
|
||||
|
||||
def setUp(self):
|
||||
self.addon = Addon.objects.get(pk=3615)
|
||||
|
@ -37,15 +38,15 @@ class TestXSS(amo.tests.TestCase):
|
|||
"""Test xss tag detail."""
|
||||
url = reverse('addons.detail_more', args=['a3615'])
|
||||
r = self.client.get_ajax(url, follow=True)
|
||||
doc = pq(r.content)
|
||||
eq_(doc('li.tag')[0].text_content().strip(), self.xss)
|
||||
assert self.escaped in r.content
|
||||
assert self.xss not in r.content
|
||||
|
||||
def test_tags_xss_cloud(self):
|
||||
"""Test xss tag cloud."""
|
||||
url = reverse('tags.top_cloud')
|
||||
r = self.client.get(url, follow=True)
|
||||
doc = pq(r.content)
|
||||
eq_(doc('a.tag')[0].text_content().strip(), self.xss)
|
||||
assert self.escaped in r.content
|
||||
assert self.xss not in r.content
|
||||
|
||||
|
||||
class TestXSSURLFail(amo.tests.TestCase):
|
||||
|
@ -53,6 +54,7 @@ class TestXSSURLFail(amo.tests.TestCase):
|
|||
'tags/tags.json']
|
||||
|
||||
xss = "<script>alert('xss')</script>"
|
||||
escaped = "<script>alert('xss')</script>"
|
||||
|
||||
def setUp(self):
|
||||
self.addon = Addon.objects.get(pk=3615)
|
||||
|
@ -65,8 +67,8 @@ class TestXSSURLFail(amo.tests.TestCase):
|
|||
"""Test xss tag detail."""
|
||||
url = reverse('addons.detail_more', args=['a3615'])
|
||||
r = self.client.get_ajax(url, follow=True)
|
||||
doc = pq(r.content)
|
||||
eq_(doc('li.tag')[0].text_content().strip(), self.xss)
|
||||
assert self.escaped in r.content
|
||||
assert self.xss not in r.content
|
||||
|
||||
def test_tags_xss_home(self):
|
||||
"""Test xss tag home."""
|
||||
|
|
|
@ -1461,11 +1461,11 @@ class TestThemesProfile(amo.tests.TestCase):
|
|||
self._test_good(res)
|
||||
|
||||
|
||||
@patch.object(settings, 'RECAPTCHA_PRIVATE_KEY', 'something')
|
||||
class TestReportAbuse(amo.tests.TestCase):
|
||||
fixtures = ['base/users']
|
||||
|
||||
def setUp(self):
|
||||
settings.RECAPTCHA_PRIVATE_KEY = 'something'
|
||||
self.full_page = reverse('users.abuse', args=[10482])
|
||||
|
||||
@patch('captcha.fields.ReCaptchaField.clean')
|
||||
|
|
|
@ -1475,3 +1475,4 @@ STATICFILES_DIRS = (
|
|||
path('static'),
|
||||
JINGO_MINIFY_ROOT
|
||||
)
|
||||
NETAPP_STORAGE = TMP_PATH
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
# This script builds assets in Jenkins to make sure there are no
|
||||
# less compilation errors
|
||||
|
||||
if [ ! -z $SET_PY_27 ]; then
|
||||
source /opt/rh/python27/enable
|
||||
fi
|
||||
|
||||
# Echo the python version used in this build.
|
||||
python --version
|
||||
|
||||
cd $WORKSPACE
|
||||
VENV=$WORKSPACE/venv
|
||||
VENDOR=$WORKSPACE/vendor
|
||||
|
||||
echo "Starting build on executor $EXECUTOR_NUMBER..." `date`
|
||||
|
||||
if [ -z $1 ]; then
|
||||
echo "Usage: $0 django_settings_module"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SETTINGS=$1
|
||||
|
||||
# Delete old artifacts.
|
||||
find . -name '*.pyc' -or -name '*.less.css' -or -name '*.styl.css' -or -name '*-min.css' -or -name '*-all.css' -or -name '*-min.js' -or -name '*-all.js' | grep -v static/js/lib/ | xargs rm
|
||||
|
||||
if [ ! -d "$VENV/bin" ]; then
|
||||
echo "No virtualenv found. Making one..."
|
||||
virtualenv $VENV --system-site-packages
|
||||
fi
|
||||
|
||||
source $VENV/bin/activate
|
||||
|
||||
pip install -U --exists-action=w --no-deps -q \
|
||||
--download-cache=$WORKSPACE/.pip-cache \
|
||||
-f https://pyrepo.addons.mozilla.org/ \
|
||||
-r requirements/compiled.txt -r requirements/test.txt
|
||||
|
||||
if [ ! -d "$VENDOR" ]; then
|
||||
echo "No vendor lib? Cloning..."
|
||||
git clone --recursive git://github.com/mozilla/zamboni-lib.git $VENDOR
|
||||
fi
|
||||
|
||||
# Install node deps locally.
|
||||
npm install
|
||||
export PATH="./node_modules/.bin/:${PATH}"
|
||||
|
||||
cat > settings_local.py <<SETTINGS
|
||||
from ${SETTINGS} import *
|
||||
CLEANCSS_BIN = 'cleancss'
|
||||
UGLIFY_BIN = 'uglifyjs'
|
||||
SETTINGS
|
||||
|
||||
export DJANGO_SETTINGS_MODULE=settings_local
|
||||
|
||||
# Update the vendor lib.
|
||||
echo "Updating vendor..."
|
||||
git submodule --quiet foreach 'git submodule --quiet sync'
|
||||
git submodule --quiet sync && git submodule update --init --recursive
|
||||
|
||||
echo "building assets..." `date`
|
||||
|
||||
python manage.py compress_assets
|
||||
exit $?
|
|
@ -66,6 +66,20 @@ echo "Updating vendor..."
|
|||
git submodule --quiet foreach 'git submodule --quiet sync'
|
||||
git submodule --quiet sync && git submodule update --init --recursive
|
||||
|
||||
# Install node deps locally.
|
||||
npm install
|
||||
export PATH="./node_modules/.bin/:${PATH}"
|
||||
|
||||
# Manage statics (collect and compress).
|
||||
echo "collecting statics..." `date`
|
||||
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
echo "building assets..." `date`
|
||||
|
||||
python manage.py compress_assets
|
||||
|
||||
|
||||
if [ -z $SET_ES_TESTS ]; then
|
||||
RUN_ES_TESTS=False
|
||||
else
|
||||
|
@ -86,15 +100,14 @@ DATABASES['default']['TEST_CHARSET'] = 'utf8'
|
|||
DATABASES['default']['TEST_COLLATION'] = 'utf8_general_ci'
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'caching.backends.locmem.LocMemCache',
|
||||
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
||||
'LOCATION': 'localhost:11211',
|
||||
}
|
||||
}
|
||||
CELERY_ALWAYS_EAGER = True
|
||||
RUN_ES_TESTS = ${RUN_ES_TESTS}
|
||||
ES_HOSTS = ['${ES_HOST}:9200']
|
||||
ES_URLS = ['http://%s' % h for h in ES_HOSTS]
|
||||
ADDONS_PATH = '/tmp/warez'
|
||||
STATIC_URL = ''
|
||||
RUNNING_IN_JENKINS = True
|
||||
|
||||
SETTINGS
|
||||
|
|
Загрузка…
Ссылка в новой задаче