示例#1
0
 def test_locale(self):
     """Get initial lang, country from the right places"""
     # Get initial lang and country from 'initial' if provided there,
     # else from the locale passed in
     # First, not passed in
     locale = "en-US"
     form = ManageSubscriptionsForm(locale=locale, initial={})
     self.assertEqual('en', form.initial['lang'])
     self.assertEqual('us', form.initial['country'])
     # now, test with them passed in.
     form = ManageSubscriptionsForm(locale=locale,
                                    initial={
                                        'lang': 'pt',
                                        'country': 'br',
                                    })
     self.assertEqual('pt', form.initial['lang'])
     self.assertEqual('br', form.initial['country'])
示例#2
0
 def test_locale(self, langs_mock):
     """Get initial lang, country from the right places"""
     # Get initial lang and country from 'initial' if provided there,
     # else from the locale passed in
     # First, not passed in
     langs_mock.return_value = [['en', 'English'], ['pt', 'Portuguese']]
     locale = "en-US"
     form = ManageSubscriptionsForm(locale=locale, initial={})
     self.assertEqual('en', form.initial['lang'])
     self.assertEqual('us', form.initial['country'])
     # now, test with them passed in.
     form = ManageSubscriptionsForm(locale=locale,
                                    initial={
                                        'lang': 'pt',
                                        'country': 'br',
                                    })
     self.assertEqual('pt', form.initial['lang'])
     self.assertEqual('br', form.initial['country'])
示例#3
0
 def test_bad_language(self):
     """Handle their language preference if it's not valid"""
     # Suppose their selected language in ET is one we don't recognize
     # at all.  Use the language from their locale instead.
     locale = "pt-BR"
     form = ManageSubscriptionsForm(locale=locale,
                                    initial={
                                        'lang': 'zz',
                                        'country': 'es',
                                    })
     self.assertEqual('pt', form.initial['lang'])
示例#4
0
 def test_locale(self, langs_mock):
     """Get initial lang, country from the right places"""
     # Get initial lang and country from 'initial' if provided there,
     # else from the locale passed in
     # First, not passed in
     langs_mock.return_value = [["en", "English"], ["pt", "Portuguese"]]
     locale = "en-US"
     form = ManageSubscriptionsForm(locale=locale, initial={})
     self.assertEqual("en", form.initial["lang"])
     self.assertEqual("us", form.initial["country"])
     # now, test with them passed in.
     form = ManageSubscriptionsForm(
         locale=locale,
         initial={
             "lang": "pt",
             "country": "br",
         },
     )
     self.assertEqual("pt", form.initial["lang"])
     self.assertEqual("br", form.initial["country"])
示例#5
0
 def test_no_country(self):
     """Handle their country preference if it's not set"""
     # Suppose they have no selected country in CTMS.
     # Use the country from their locale instead.
     locale = "en-US"
     form = ManageSubscriptionsForm(
         locale=locale,
         initial={
             "lang": "zz",
         },
     )
     self.assertEqual("us", form.initial["country"])
示例#6
0
 def test_bad_language(self):
     """Handle their language preference if it's not valid"""
     # Suppose their selected language in ET is one we don't recognize
     # at all.  Use the language from their locale instead.
     locale = "pt-BR"
     form = ManageSubscriptionsForm(
         locale=locale,
         initial={
             "lang": "zz",
             "country": "es",
         },
     )
     self.assertEqual("pt", form.initial["lang"])
示例#7
0
 def test_bad_country(self):
     """Handle their country preference if it's not valid"""
     # Suppose their selected country in CTMS is one we don't recognize
     # at all.  Use the country from their locale instead.
     locale = "pt-BR"
     form = ManageSubscriptionsForm(
         locale=locale,
         initial={
             "lang": "zz",
             "country": "Spain",
         },
     )
     self.assertEqual("br", form.initial["country"])
示例#8
0
 def test_long_language(self, langs_mock):
     """Fuzzy match their language preference"""
     # Suppose their selected language in ET is a long form ("es-ES")
     # while we only have the short forms ("es") in our list of
     # valid languages.  Or vice-versa.  Find the match to the one
     # in our list and use that, not the lang from ET.
     locale = 'en-US'
     langs_mock.return_value = [['en', 'English'], ['es', 'Spanish']]
     form = ManageSubscriptionsForm(locale=locale,
                                    initial={
                                        'lang': 'es-ES',
                                        'country': 'es',
                                    })
     # Initial value is 'es'
     self.assertEqual('es', form.initial['lang'])
示例#9
0
 def test_long_language(self, langs_mock):
     """Fuzzy match their language preference"""
     # Suppose their selected language in ET is a long form ("es-ES")
     # while we only have the short forms ("es") in our list of
     # valid languages.  Or vice-versa.  Find the match to the one
     # in our list and use that, not the lang from ET.
     locale = "en-US"
     langs_mock.return_value = [["en", "English"], ["es", "Spanish"]]
     form = ManageSubscriptionsForm(
         locale=locale,
         initial={
             "lang": "es-ES",
             "country": "es",
         },
     )
     # Initial value is 'es'
     self.assertEqual("es", form.initial["lang"])