Bug 1585251 Fix some failing tests (#1428)

* Bug 1585251 - Fix a batch of failing tests on Python 3
This commit is contained in:
Jarek 2019-10-22 14:44:33 +02:00 коммит произвёл Adrian Gaudebert
Родитель 1fa5dab0a2
Коммит 6319bd5751
11 изменённых файлов: 29 добавлений и 22 удалений

Просмотреть файл

@ -48,6 +48,9 @@ test-py3: test
shell-py3: override PYTHON_VERSION=3.7.3
shell-py3: shell
pytest-py3: override PYTHON_VERSION=3.7.3
pytest-py3: pytest
setup: .docker-build
${DC} run webapp /app/docker/set_up_webapp.sh
@ -70,6 +73,9 @@ flow:
lint-frontend:
${DC} run --rm -w /app/frontend webapp ./node_modules/.bin/eslint src/
pytest:
${DC} run --rm -w /app webapp pytest --cov-append --cov-report=term --cov=. $(opts)
shell:
${DC} run --rm webapp /bin/bash

Просмотреть файл

@ -731,7 +731,7 @@ class Locale(AggregatedStats):
if self.cldr_plurals == '':
return [1]
else:
return map(int, self.cldr_plurals.split(','))
return [int(p) for p in self.cldr_plurals.split(',')]
def cldr_plurals_list(self):
return ', '.join(
@ -1933,10 +1933,11 @@ class EntityQuerySet(models.QuerySet):
for candidate in plural_candidates:
count = 0
for i in range(locale.nplurals):
candidate_translations = filter(
lambda x: x.plural_form == i,
candidate.fetched_translations
)
candidate_translations = [
translation
for translation in candidate.fetched_translations
if translation.plural_form == i
]
if len(candidate_translations) and rule(candidate_translations[0]):
count += 1

Просмотреть файл

@ -292,6 +292,7 @@ def create_named_tempfile(contents, prefix=None, suffix=None, directory=None):
directory, and return the path to the created file.
"""
with tempfile.NamedTemporaryFile(
mode='w',
prefix=prefix,
suffix=suffix,
dir=directory,

Просмотреть файл

@ -87,12 +87,12 @@ def test_batch_edit_translations_bad_request(batch_action, member, locale_a):
# No `locale` parameter.
response = batch_action(action='reject')
assert response.status_code == 400
assert 'locale' in response.content
assert b'locale' in response.content
# No `action` parameter.
response = batch_action(locale=locale_a.code)
assert response.status_code == 400
assert 'action' in response.content
assert b'action' in response.content
# Incorrect `action` parameter.
response = batch_action(
@ -101,7 +101,7 @@ def test_batch_edit_translations_bad_request(batch_action, member, locale_a):
)
assert response.status_code == 400
assert 'action' in response.content
assert b'action' in response.content
@pytest.mark.django_db

Просмотреть файл

@ -60,7 +60,7 @@ class ChangeSet(object):
@property
def changed_translations(self):
"""A list of Translation objects that have been created or updated."""
return self.translations_to_create + self.translations_to_update.values()
return self.translations_to_create + list(self.translations_to_update.values())
def update_vcs_entity(self, locale, db_entity, vcs_entity):
"""

Просмотреть файл

@ -60,7 +60,7 @@ class CompareLocalesResource(ParsedResource):
entity.key,
None,
None,
None,
0,
)
try:
@ -106,7 +106,7 @@ class CompareLocalesResource(ParsedResource):
# Create parent folders if necessary
create_parent_directory(self.path)
with open(self.path, 'w') as output_file:
with open(self.path, 'wb') as output_file:
log.debug('Saving file: %s', self.path)
output_file.write(
serializer.serialize(

Просмотреть файл

@ -128,7 +128,7 @@ class SilmeResource(ParsedResource):
@property
def translations(self):
return self.entities.values()
return list(self.entities.values())
def save(self, locale):
"""

Просмотреть файл

@ -363,7 +363,6 @@ class FormatTestsMixin(object):
MissingString=Translated Missing String
"""
path, resource = self.parse_string(input_string, source_string=source_string)
missing_translation = match_attr(resource.translations, key=self.key('Missing String'))
missing_translation.strings = {None: expected_translation or 'Translated Missing String'}
resource.save(self.locale)

Просмотреть файл

@ -232,5 +232,5 @@ def test_view_project_tag_ajax(client, project_a, tag_a):
# response returns html
with pytest.raises(ValueError):
response.json()
assert tag_a.name in response.content
assert tag_a.slug in response.content
assert tag_a.name.encode('utf-8') in response.content
assert tag_a.slug.encode('utf-8') in response.content

Просмотреть файл

@ -136,14 +136,14 @@ def test_users_permissions_for_ajax_permissions_view(
locale=locale_a.code
))
assert response.status_code == 403
assert '<title>Forbidden page</title>' in response.content
assert b'<title>Forbidden page</title>' in response.content
# Check if users without permissions for the locale can get this tab.
response = member.client.get('/{locale}/ajax/permissions/'.format(
locale=locale_a.code
))
assert response.status_code == 403
assert '<title>Forbidden page</title>' in response.content
assert b'<title>Forbidden page</title>' in response.content
locale_a.managers_group.user_set.add(member.user)
@ -152,7 +152,7 @@ def test_users_permissions_for_ajax_permissions_view(
locale=locale_a.code
))
assert response.status_code == 200
assert '<title>Forbidden page</title>' not in response.content
assert b'<title>Forbidden page</title>' not in response.content
# Remove permissions for user0 and check if the view is not accessible.
locale_a.managers_group.user_set.clear()
@ -161,7 +161,7 @@ def test_users_permissions_for_ajax_permissions_view(
locale=locale_a.code
))
assert response.status_code == 403
assert '<title>Forbidden page</title>' in response.content
assert b'<title>Forbidden page</title>' in response.content
# All unauthorized attempts to POST data should be blocked
response = member.client.post(
@ -171,7 +171,7 @@ def test_users_permissions_for_ajax_permissions_view(
data={'smth': 'smth'}
)
assert response.status_code == 403
assert '<title>Forbidden page</title>' in response.content
assert b'<title>Forbidden page</title>' in response.content
response = client.post(
'/{locale}/ajax/permissions/'.format(
@ -180,7 +180,7 @@ def test_users_permissions_for_ajax_permissions_view(
data={'smth': 'smth'}
)
assert response.status_code == 403
assert '<title>Forbidden page</title>' in response.content
assert b'<title>Forbidden page</title>' in response.content
@pytest.mark.django_db

Просмотреть файл

@ -34,7 +34,7 @@ def test_translate_template(client):
with override_flag('translate_next', active=True):
response = client.get(url)
assert 'Pontoon' in response.content
assert b'Pontoon' in response.content
@pytest.mark.django_db