def test_aliases(): cc = Content({ 'schema': '2', 'settings': {}, 'survey': [], 'translations': [{ 'name': 't1', 'code': 't1' }] }) assert cc.export(schema='2')['translations'][0] == { 'name': 't1', 'default': True, '$anchor': 't1' } cc = Content({ 'schema': '2', 'settings': {}, 'survey': [], 'translations': [{ 'name': 't1', 'uicode': 'en', 'code': 't1' }] }) assert cc.export(schema='2')['translations'][0] == { 'name': 't1', 'default': True, '$anchor': 't1', 'locale': 'en' }
def test_one2two(): for cc in CONTENT_1S: content = Content(cc, exports_include_defaults=True) rr = content.export(schema='2') assert 'settings' in rr content = Content(cc, exports_include_defaults=False) rr = content.export(schema='2') assert 'settings' not in rr for cc in CONTENT_1S_WITH_SETTINGS: # don't delete valid settings content = Content(cc, exports_include_defaults=True) rr = content.export(schema='2') assert 'settings' in rr content = Content(cc, exports_include_defaults=False) rr = content.export(schema='2') assert 'settings' in rr
def test_1_with_no_default_tx(): content = Content({ 'survey': [], 'translations': [ 'English', ], 'settings': {}, 'schema': '1', }) result = content.export(schema='2') defaults = [tx.get('default') for tx in result['translations']] assert defaults == [True]
def test_additional(): cc = {'schema': '1::', 'settings': [{'default_language': None}], 'survey': [{'name': 'start', 'type': 'start'}, {'name': 'end', 'type': 'end'}, {'$kuid': 'ty7yd67', 'label': 'q1', 'required': False, 'type': 'text'}, {'$kuid': 'pm4jk80', 'label': 'q2', 'required': False, 'type': 'integer'}]} content = Content(cc) result = content.export(schema='1') assert len(result['translations']) == 1 assert result['translations'] == [None] content = Content(cc) result = content.export(schema='2') assert len(result['translations']) == 1 assert result['translations'] == [{'$anchor': 'tx0', 'default': True, 'name': ''}]
def test_1_with_tx_locales(): content = Content({ 'survey': [], 'translations': [ 'English (en)', 'French (fr)', ], 'settings': { 'default_language': 'French (fr)', }, 'schema': '1', }) result = content.export(schema='2') result2 = Content(result).export(schema='1') defaults = [tx.get('default') for tx in result['translations']] assert defaults == [None, True]
def test_rename_kuid_to_anchor(): cc = Content({ 'schema': '1', 'survey': [{ 'type': 'text', 'label': ['asdf'], '$kuid': 'asdfasdf' }], 'translations': [None], 'translated': ['label'], 'settings': {}, }) exp = cc.export(schema='2') assert '$anchor' in exp['survey'][0] # and rename it back to '$kuid' when saved as schema='1' exp2 = Content(exp).export(schema='1') assert '$kuid' in exp2['survey'][0]
def test_1_plus_colons(): content = Content({ # '1+xx' equivalent to 'xlsform' 'schema': '1+::', 'survey': [ {'type': 'text', 'name': 'book', 'label::English': 'The patient', 'label::French': 'Le patient', }, ], 'translated': [ 'label' ], 'settings': {}, }) result = content.export(schema='1') row0 = result['survey'][0] assert row0['label'] == ['The patient', 'Le patient']