diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-08 12:23:34 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-08 12:23:34 +0000 |
| commit | 748e1bdf42a17da7ede351f997018762c681457b (patch) | |
| tree | 9759340770e21522e94a5332432dae3ad81ad908 /tests/regressiontests | |
| parent | accc20d799b4a1e584688d2a5b9db555058ab7a9 (diff) | |
queryset-refactor: Merged from trunk up to [7098] (because I need the last
commit on this branch).
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7099 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/i18n/misc.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/regressiontests/i18n/misc.py b/tests/regressiontests/i18n/misc.py index fa22fd05d3..eb64263799 100644 --- a/tests/regressiontests/i18n/misc.py +++ b/tests/regressiontests/i18n/misc.py @@ -2,6 +2,11 @@ tests = """ >>> from django.utils.translation.trans_real import parse_accept_lang_header >>> p = parse_accept_lang_header +# +# Testing HTTP header parsing. First, we test that we can parse the values +# according to the spec (and that we extract all the pieces in the right order). +# + Good headers. >>> p('de') [('de', 1.0)] @@ -54,4 +59,44 @@ Bad headers; should always return []. >>> p('') [] +# +# Now test that we parse a literal HTTP header correctly. +# + +>>> from django.utils.translation.trans_real import get_language_from_request +>>> g = get_language_from_request +>>> from django.http import HttpRequest +>>> r = HttpRequest +>>> r.COOKIES = {} + +These tests assumes the es, es_AR, pt and pt_BR translations exit in the Django +source tree. +>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt-br'} +>>> g(r) +'pt-br' +>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt'} +>>> g(r) +'pt' +>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es,de'} +>>> g(r) +'es' +>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-ar,de'} +>>> g(r) +'es-ar' + +This test assumes there won't be a Django translation to a US variation +of the Spanish language, a safe assumption. When the user sets it +as the preferred language, the main 'es' translation should be selected +instead. +>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-us'} +>>> g(r) +'es' + +This tests the following scenario: there isn't a main language (zh) +translation of Django but there is a translation to variation (zh_CN) +the user sets zh-cn as the preferred language, it should be selected by +Django without falling back nor ignoring it. +>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,de'} +>>> g(r) +'zh-cn' """ |
