def test_user_customized_lang_code_as_settings_language_code(self): with override_settings(USE_I18N=True, LANGUAGES=self.LANGUAGES_CONF2, LANGUAGE_CODE='user_customized_lang_code'): with self.assertRaises(IOError): # because there's no file named "user_customized_lang_code.mo" get_course_specific_language_choices() with mock.patch(REAL_TRANSLATION_FUNCTION_TO_MOCK) as mock_gettext: mock_gettext.side_effect = real_trans_side_effect choices = get_course_specific_language_choices() # The language description is the language_code, because it can't # be found in django.conf.locale.LANG_INFO self.assertEqual(choices[1][1], "user_customized_lang_code") with override_settings(USE_I18N=False, LANGUAGES=self.LANGUAGES_CONF2, LANGUAGE_CODE='user_customized_lang_code'): with mock.patch(REAL_TRANSLATION_FUNCTION_TO_MOCK) as mock_gettext: mock_gettext.side_effect = real_trans_side_effect choices = get_course_specific_language_choices() # The language description is the language_code, because it can't # be found in django.conf.locale.LANG_INFO self.assertIn("user_customized_lang_code", choices[0][1])
class Meta: model = Course fields = ( "identifier", "name", "number", "time_period", "start_date", "end_date", "hidden", "listed", "accepts_enrollment", "git_source", "ssh_private_key", "course_root_path", "course_file", "events_file", "enrollment_approval_required", "preapproval_require_verified_inst_id", "enrollment_required_email_suffix", "from_email", "notify_email", "force_lang", ) widgets = { "start_date": DateTimePicker(options={"format": "YYYY-MM-DD"}), "end_date": DateTimePicker(options={"format": "YYYY-MM-DD"}), "force_lang": forms.Select(choices=get_course_specific_language_choices()), }
class Meta: model = Course exclude = ("participants", ) widgets = { "start_date": DateTimePicker(options={"format": "YYYY-MM-DD"}), "end_date": DateTimePicker(options={"format": "YYYY-MM-DD"}), "force_lang": forms.Select(choices=get_course_specific_language_choices()), }
def test_user_customized_lang_code_as_settings_language_code(self): with override_settings(USE_I18N=True, LANGUAGES=self.LANGUAGES_CONF2, LANGUAGE_CODE='user_customized_lang_code'): with self.assertRaises(IOError): # because there's no file named "user_customized_lang_code.mo" get_course_specific_language_choices() with mock.patch(REAL_TRANSLATION_FUNCTION_TO_MOCK) as mock_gettext: mock_gettext.side_effect = real_trans_side_effect choices = get_course_specific_language_choices() # The language description is the language_code, because it can't # be found in django.conf.locale.LANG_INFO self.assertEqual(choices[1][1], "user_customized_lang_code") with override_settings(USE_I18N=False, LANGUAGES=self.LANGUAGES_CONF2, LANGUAGE_CODE='user_customized_lang_code'): with mock.patch(REAL_TRANSLATION_FUNCTION_TO_MOCK) as mock_gettext: mock_gettext.side_effect = real_trans_side_effect choices = get_course_specific_language_choices() # The language description is the language_code, because it can't # be found in django.conf.locale.LANG_INFO self.assertIn("user_customized_lang_code", choices[0][1])
def lang_descr_get_translated(self, choice_count): with mock.patch("course.utils._") as mock_ugettext, \ mock.patch("django.utils.translation.ugettext_lazy") \ as mock_ugettext_lazy: mock_ugettext.side_effect = lambda x: x mock_ugettext_lazy.side_effect = lambda x: x choices = get_course_specific_language_choices() self.assertEqual(len(choices), choice_count) # "English", "Default", "my Simplified Chinese" and "German" are # called by django.utils.translation.ugettext, for at least once. # Another language description literals (especially "Simplified Chinese") # are not called by it. self.assertTrue(mock_ugettext.call_count >= 4) simplified_chinese_as_arg_count = 0 my_simplified_chinese_as_arg_count = 0 for call in mock_ugettext.call_args_list: arg, kwargs = call if "my Simplified Chinese" in arg: my_simplified_chinese_as_arg_count += 1 if "Simplified Chinese" in arg: simplified_chinese_as_arg_count += 1 self.assertEqual(simplified_chinese_as_arg_count, 0) self.assertTrue(my_simplified_chinese_as_arg_count > 0)
def lang_descr_get_translated(self, choice_count): with mock.patch("course.utils._") as mock_ugettext, \ mock.patch("django.utils.translation.ugettext_lazy") \ as mock_ugettext_lazy: mock_ugettext.side_effect = lambda x: x mock_ugettext_lazy.side_effect = lambda x: x choices = get_course_specific_language_choices() self.assertEqual(len(choices), choice_count) # "English", "Default", "my Simplified Chinese" and "German" are # called by django.utils.translation.ugettext, for at least once. # Another language description literals (especially "Simplified Chinese") # are not called by it. self.assertTrue(mock_ugettext.call_count >= 4) simplified_chinese_as_arg_count = 0 my_simplified_chinese_as_arg_count = 0 for call in mock_ugettext.call_args_list: arg, kwargs = call if "my Simplified Chinese" in arg: my_simplified_chinese_as_arg_count += 1 if "Simplified Chinese" in arg: simplified_chinese_as_arg_count += 1 self.assertEqual(simplified_chinese_as_arg_count, 0) self.assertTrue(my_simplified_chinese_as_arg_count > 0)
def test_i18n_disabled_lang_items_having_duplicated_lang_code(self): choices = get_course_specific_language_choices() self.assertTrue(choices[0][1].startswith("Default:")) self.assertNotIn("disabled", choices[0][1]) self.assertEqual(len(choices), 4)
def test_i18n_disabled(self): choices = get_course_specific_language_choices() self.assertTrue(choices[0][1].startswith("Default:")) self.assertNotIn("disabled", choices[0][1]) self.assertEqual(len(choices), 4) self.assertIn("(ko)", choices[0][1])
def test_i18n_enabled_lang_items_has_same_lang_code_with_language_code(self): choices = get_course_specific_language_choices() self.assertTrue(choices[0][1].startswith("Default: disabled")) self.assertEqual(len(choices), 4)
def test_i18n_enabled_lang_items_having_duplicated_lang_code(self): choices = get_course_specific_language_choices() self.assertEqual(len(choices), 5) self.assertTrue(choices[0][1].startswith("Default: disabled"))
def test_i18n_enabled(self): choices = get_course_specific_language_choices() self.assertTrue(choices[0][1].startswith("Default: disabled")) self.assertEqual(len(choices), 5) self.assertIn("(ko)", choices[1][1])
def test_i18n_disabled_lang_items_has_same_lang_code_with_language_code(self): choices = get_course_specific_language_choices() self.assertTrue(choices[0][1].startswith("Default:")) self.assertNotIn("disabled", choices[0][1]) self.assertEqual(len(choices), 3)