Skip to content

Commit

Permalink
Merge pull request #291 from kobotoolbox/283-fix-translations-labels-…
Browse files Browse the repository at this point in the history
…mismatch-error-after-black-squash

Fix translations and labels mismatch error message
  • Loading branch information
jnm authored Feb 24, 2022
2 parents 05e2879 + e443ef4 commit 5695108
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/formpack/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, labels=[], translations=[]):
'Mismatched labels and translations: [{}] [{}] '
'{}!={}'.format(
', '.join(labels),
', '.join(translations),
', '.join(map(str, translations)),
len(labels),
len(translations),
)
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/translations_labels_mismatch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding: utf-8
'''
translations_labels_mismatch
'''

from ..load_fixture_json import load_fixture_json

DATA = {
'title': 'Your favourite Roman emperors',
'id_string': 'translations_labels_mismatch',
'versions': [
load_fixture_json('translations_labels_mismatch/v1'),
],
}
27 changes: 27 additions & 0 deletions tests/fixtures/translations_labels_mismatch/v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "v1",
"content": {
"survey": [
{
"type": "text",
"name": "fav_emperor",
"label": [
"Who is your favourite emperor?"
],
"hint::English (en)": "Before the decline of the Roman Empire"
}
],
"translated": [
"hint",
"label"
],
"translations": [
null
]
},
"submissions": [
{
"fav_emperor": "Marcus Aurelius"
}
]
}
6 changes: 6 additions & 0 deletions tests/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from formpack import FormPack
from formpack.constants import UNTRANSLATED
from formpack.errors import TranslationError
from formpack.schema.fields import (
ValidationStatusCopyField,
IdCopyField,
Expand Down Expand Up @@ -370,6 +371,11 @@ def test_submissions_of_group_exports(self):
],
)

def test_translations_labels_mismatch(self):
title, schemas, submissions = build_fixture('translations_labels_mismatch')
with self.assertRaises(TranslationError) as e:
fp = FormPack(schemas, title)

def test_simple_nested_grouped_repeatable(self):
title, schemas, submissions = build_fixture(
'simple_nested_grouped_repeatable'
Expand Down

0 comments on commit 5695108

Please sign in to comment.