Skip to content

Commit

Permalink
display current language.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Skiepko committed May 11, 2017
1 parent 6efc844 commit 65502fc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion acceptance_tests/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def select_language(selenium, name):

def assert_language_selected(selenium, name):
content = selenium.find_element_by_tag_name('body').text
assert 'Current language: {}.'.format(name) in content
assert 'Language: {}.'.format(name) in content


def go_homepage(selenium):
Expand Down
8 changes: 8 additions & 0 deletions dila/frontend/flask/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ def get_language_links():

def current_language_code():
return (flask.request.view_args or {}).get('language_code')


def current_language():
code = current_language_code()
if code:
return application.get_language(code).name
else:
return None
1 change: 1 addition & 0 deletions dila/frontend/flask/template_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ def inject_languages_menu():
'languages_form': languages.get_new_form(),
'languages_links': list(languages.get_language_links()),
'current_language_code': languages.current_language_code(),
'current_language': languages.current_language(),
}
10 changes: 9 additions & 1 deletion dila/frontend/flask/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@
</a>
</li>
<li class="dropdown">
<a id="languageMenuButton" class="dropdown-toggle" data-toggle="dropdown" href="#">There are no languages.</a>
<a id="languageMenuButton" class="dropdown-toggle" data-toggle="dropdown" href="#">
{% if not languages_links %}
There are no languages.
{% elif current_language %}
Language: {{ current_language }}.
{% else %}
Select language.
{% endif %}
</a>
<div class="dropdown-menu">
<button id="addLanguageButton" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#addLanguage">
Add language
Expand Down
45 changes: 45 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@mock.patch('dila.application.get_resources')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_home(get_resources, flask_client):
get_resources.return_value = []
response = flask_client.get('/')
Expand All @@ -29,6 +30,7 @@ def test_home(get_resources, flask_client):

@mock.patch('dila.application.get_resources')
@mock.patch('dila.application.get_languages')
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_home_with_selected_language_links_to_resource_page(get_languages, get_resources, flask_client):
get_resources.return_value = []
get_languages.return_value = [
Expand All @@ -42,8 +44,32 @@ def test_home_with_selected_language_links_to_resource_page(get_languages, get_r
response.data.decode())


@mock.patch('dila.application.get_resources')
@mock.patch('dila.application.get_languages')
def test_home_prompts_to_select_language(get_languages, get_resources, flask_client):
get_resources.return_value = []
get_languages.return_value = [structures.Language('dutch', 'nl')]
response = flask_client.get('/')
assert 'Select language.' in response.data.decode()



@mock.patch('dila.application.get_resources')
@mock.patch('dila.application.get_languages')
@mock.patch('dila.application.get_language')
def test_home_shows_selected_language(get_language, get_languages, get_resources, flask_client):
get_resources.return_value = []
get_languages.return_value = [
structures.Language('dutch', 'nl'),
]
get_language.return_value = structures.Language('dutch', 'nl')
response = flask_client.get('/lang/nl/')
assert 'Language: dutch.' in response.data.decode()


@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_add_resource_form_visible(flask_client):
response = flask_client.get('/')
assert re.search('<input class="[^"]*" id="new_resource_name" name="new_resource_name" type="text" value="">',
Expand All @@ -53,6 +79,7 @@ def test_add_resource_form_visible(flask_client):

@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_add_language_form_visible(flask_client):
response = flask_client.get('/')
assert re.search('<input class="[^"]*" id="new_language_name" name="new_language_name" type="text" value="">',
Expand All @@ -64,6 +91,7 @@ def test_add_language_form_visible(flask_client):

@mock.patch('dila.application.get_resources')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_links_to_resource_page(get_resources, flask_client):
get_resources.return_value = [
structures.Resource(
Expand All @@ -76,6 +104,7 @@ def test_links_to_resource_page(get_resources, flask_client):

@mock.patch('dila.application.get_resources')
@mock.patch('dila.application.get_languages')
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_home_with_selected_language_links_to_resource_page(get_languages, get_resources, flask_client):
get_languages.return_value = [
structures.Language('polish', 'pl'),
Expand All @@ -92,6 +121,7 @@ def test_home_with_selected_language_links_to_resource_page(get_languages, get_r

@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
@mock.patch('dila.application.add_resource')
def test_add_resource(add_resource, flask_client):
response = flask_client.post(
Expand All @@ -107,6 +137,7 @@ def test_add_resource(add_resource, flask_client):


@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
@mock.patch('dila.application.get_languages')
def test_home_links_to_language(get_languages, flask_client):
get_languages.return_value = [
Expand All @@ -117,6 +148,7 @@ def test_home_links_to_language(get_languages, flask_client):


@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
@mock.patch('dila.application.get_languages')
def test_home_with_selected_language_links_to_language(get_languages, flask_client):
get_languages.return_value = [
Expand All @@ -129,6 +161,7 @@ def test_home_with_selected_language_links_to_language(get_languages, flask_clie

@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
@mock.patch('dila.application.add_language')
def test_add_language(add_language, flask_client):
response = flask_client.post(
Expand All @@ -146,6 +179,7 @@ def test_add_language(add_language, flask_client):


@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_resource_page(flask_client):
response = flask_client.get('/res/1/')
assert re.search('<li class="">\s*<a class="navbar-brand" href="/">\s*Select resource\s*</a>\s*</li>',
Expand All @@ -154,6 +188,7 @@ def test_resource_page(flask_client):

@mock.patch('dila.application.get_translated_strings')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_resource_page_with_selected_language(get_translated_strings, flask_client):
response = flask_client.get('/lang/pl/res/1/')
assert re.search('<li class="">\s*<a class="navbar-brand" href="/lang/pl/">\s*Select resource\s*</a>\s*</li>',
Expand All @@ -162,6 +197,7 @@ def test_resource_page_with_selected_language(get_translated_strings, flask_clie


@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
@mock.patch('dila.application.get_languages')
def test_resource_page_links_to_language(get_languages, flask_client):
get_languages.return_value = [
Expand All @@ -172,6 +208,7 @@ def test_resource_page_links_to_language(get_languages, flask_client):


@mock.patch('dila.application.get_translated_strings', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
@mock.patch('dila.application.get_languages')
def test_resource_page_with_selected_language_links_to_language(get_languages, flask_client):
get_languages.return_value = [
Expand All @@ -183,6 +220,7 @@ def test_resource_page_with_selected_language_links_to_language(get_languages, f


@mock.patch('dila.application.get_resources', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
@mock.patch('dila.application.get_languages')
def test_resource_page_ensures_language_is_selected(get_languages, flask_client):
get_languages.return_value = [
Expand All @@ -195,13 +233,15 @@ def test_resource_page_ensures_language_is_selected(get_languages, flask_client)
@mock.patch('dila.application.get_translated_strings', mock.MagicMock())
@mock.patch('dila.application.upload_po_file', mock.MagicMock())
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_upload_po_file_form_visible(flask_client):
response = flask_client.get('/lang/pl/res/1/')
assert '<input id="po_file" name="po_file" type="file">' in response.data.decode()

@mock.patch('dila.application.get_translated_strings', mock.MagicMock())
@mock.patch('dila.application.upload_po_file', mock.MagicMock())
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_download_po_file_visible(flask_client):
response = flask_client.get('/lang/pl/res/1/')
assert re.search('<a class="[^"]*" href="/lang/pl/res/1/po-file/">\s*Download po\s*</a>', response.data.decode())
Expand All @@ -210,6 +250,7 @@ def test_download_po_file_visible(flask_client):
@mock.patch('dila.application.get_translated_strings', mock.MagicMock())
@mock.patch('dila.application.upload_po_file')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_upload_po_file(upload_po_file, flask_client):
response = flask_client.post(
'/lang/pl/res/1/',
Expand All @@ -225,6 +266,7 @@ def test_upload_po_file(upload_po_file, flask_client):

@mock.patch('dila.application.get_translated_strings')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_links_to_stored_translation_page(get_translated_strings, flask_client):
get_translated_strings.return_value = [
structures.TranslatedStringData(
Expand All @@ -242,6 +284,7 @@ def test_links_to_stored_translation_page(get_translated_strings, flask_client):

@mock.patch('dila.application.get_translated_string')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_get_translation_form(get_translated_string, flask_client):
get_translated_string.return_value = structures.TranslatedStringData(
'34',
Expand All @@ -262,6 +305,7 @@ def test_get_translation_form(get_translated_string, flask_client):
@mock.patch('dila.application.get_translated_string')
@mock.patch('dila.application.set_translated_string')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_post_translation_form(set_translated_string, get_translated_string, flask_client):
get_translated_string.return_value = structures.TranslatedStringData(
'34',
Expand All @@ -282,6 +326,7 @@ def test_post_translation_form(set_translated_string, get_translated_string, fla

@mock.patch('dila.application.get_po_file')
@mock.patch('dila.application.get_languages', mock.MagicMock())
@mock.patch('dila.application.get_language', mock.MagicMock())
def test_get_po_file_view(get_po_file, flask_client):
get_po_file.return_value = 'asdf'
response = flask_client.get('/lang/pl/res/1/po-file/')
Expand Down

0 comments on commit 65502fc

Please sign in to comment.