Skip to content

Commit

Permalink
added tests for localized country name list
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibhas committed Apr 8, 2019
1 parent 5061032 commit 02bfab0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion baseframe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _localized_country_list_inner(locale):
countries = [(country.name, country.alpha_2) for country in pycountry.countries]
else:
pycountry_locale = gettext.translation('iso3166-1', pycountry.LOCALES_DIR, languages=[locale])
countries = [(pycountry_locale.gettext(country.name), country.alpha_2) for country in pycountry.countries]
countries = [(pycountry_locale.gettext(country.name).decode('utf-8'), country.alpha_2) for country in pycountry.countries]
countries.sort()
return [(code, name) for (name, code) in countries]

Expand Down
16 changes: 16 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-

from baseframe import _localized_country_list_inner
from .fixtures import TestCaseBaseframe


class TestUtils(TestCaseBaseframe):
def test_localized_country_list(self):
countries = _localized_country_list_inner('en')
assert dict(countries)['DE'] == u"Germany"
countries = _localized_country_list_inner('de')
assert dict(countries)['DE'] == u"Deutschland"
countries = _localized_country_list_inner('es')
assert dict(countries)['DE'] == u"Alemania"
countries = _localized_country_list_inner('hi')
assert dict(countries)['DE'] == u"जर्मनी"

0 comments on commit 02bfab0

Please sign in to comment.