@@ -106,29 +106,48 @@ def test_when_locale_is_missing(monkeypatch):
106
106
assert i18n ._locale (request ) is locale_obj
107
107
108
108
109
- def test_negotiate_locale (monkeypatch ):
110
- request = pretend .stub (_LOCALE_ = "fake-locale-attr" )
111
- assert i18n ._negotiate_locale (request ) == "fake-locale-attr"
112
-
113
- request = pretend .stub (params = {"_LOCALE_" : "fake-locale-param" })
114
- assert i18n ._negotiate_locale (request ) == "fake-locale-param"
115
-
116
- request = pretend .stub (params = {}, cookies = {"_LOCALE_" : "fake-locale-cookie" })
117
- assert i18n ._negotiate_locale (request ) == "fake-locale-cookie"
118
-
119
- request = pretend .stub (params = {}, cookies = {}, accept_language = None )
120
- default_locale_negotiator = pretend .call_recorder (lambda r : "fake-locale-default" )
121
- monkeypatch .setattr (i18n , "default_locale_negotiator" , default_locale_negotiator )
122
- assert i18n ._negotiate_locale (request ) == "fake-locale-default"
123
-
124
- request = pretend .stub (
125
- params = {},
126
- cookies = {},
127
- accept_language = pretend .stub (
128
- best_match = pretend .call_recorder (lambda * a , ** kw : "fake-locale-best-match" )
109
+ @pytest .mark .parametrize (
110
+ ("req" , "expected" ),
111
+ [
112
+ (pretend .stub (_LOCALE_ = "eo" , accept_language = None ), "eo" ),
113
+ (pretend .stub (params = {"_LOCALE_" : "eo" }, accept_language = None ), "eo" ),
114
+ (
115
+ pretend .stub (params = {}, cookies = {"_LOCALE_" : "eo" }, accept_language = None ),
116
+ "eo" ,
129
117
),
130
- )
131
- assert i18n ._negotiate_locale (request ) == "fake-locale-best-match"
118
+ (pretend .stub (params = {}, cookies = {}, accept_language = None ), None ),
119
+ (
120
+ pretend .stub (
121
+ params = {},
122
+ cookies = {},
123
+ accept_language = pretend .stub (
124
+ best_match = lambda * a , ** kw : "fake-locale-best-match"
125
+ ),
126
+ ),
127
+ "fake-locale-best-match" ,
128
+ ),
129
+ (
130
+ pretend .stub (
131
+ params = {}, cookies = {}, _LOCALE_ = "garbage" , accept_language = None
132
+ ),
133
+ None ,
134
+ ),
135
+ (
136
+ pretend .stub (
137
+ params = {"_LOCALE_" : "garbage" }, cookies = {}, accept_language = None
138
+ ),
139
+ None ,
140
+ ),
141
+ (
142
+ pretend .stub (
143
+ params = {}, cookies = {"_LOCALE_" : "garbage" }, accept_language = None
144
+ ),
145
+ None ,
146
+ ),
147
+ ],
148
+ )
149
+ def test_negotiate_locale (monkeypatch , req , expected ):
150
+ assert i18n ._negotiate_locale (req ) == expected
132
151
133
152
134
153
def test_localize (monkeypatch ):
0 commit comments