def test_select_language_missing(): data_in = { 'deep': { 'nested': [{ 'key': { 'cs': 'česky', } }] } } data_out = {'deep': {'nested': [{'key': None}]}} assert select_language(data_in, 'en') == data_out
def test_select_language_unsupported(): data_in = { 'deep': { 'nested': [{ 'key': { 'cs': 'česky', 'en': 'anglicky', } }] } } with pytest.raises(ValueError): assert select_language(data_in, 'pl')
def test_select_language(lang, expected): data_in = { 'deep': { 'nested': [{ 'key': { 'cs': 'česky', 'en': 'anglicky', } }] } } data_out = {'deep': {'nested': [{'key': expected}]}} assert select_language(data_in, lang) == data_out
def api(lang): return jsonify(select_language(data, lang))
def index(lang): context = select_language(data, lang) context['lang'] = lang context['now'] = datetime.now() return render_template('index.html', **context)