def __init__(self, *args: Any, **kwargs: Any) -> None: """ :param args: The arguments for initializing the form. :param kwargs: The keyword argument for initializing the form. """ super().__init__(*args, **kwargs) self.language.choices = get_language_names( BaseConfiguration.TRANSLATION_DIR)
def __init__(self, *args, **kwargs) -> None: """ Initialize the form. :param args: The arguments for initializing the form. :param kwargs: The keyworded argument for initializing the form. """ super().__init__(*args, **kwargs) self.language.choices = get_language_names(BaseConfiguration.TRANSLATION_DIR)
def test_init(self): """ Test that the form is correctly initialized. Expected result: The language field is initialized with the available languages. """ languages = get_language_names(TestConfiguration.TRANSLATION_DIR) form = UserSettingsForm() self.assertListEqual(list(languages), form.language.choices)
def test_get_language_names_with_native_names_english( self, mock_listdir: MagicMock): """ Test getting the list of language names with their native names (with 'en' as locale). Expected result: The list is returned and sorted by their name. """ mock_listdir.return_value = [ 'es', 'fr', 'de', ] expected_names = [ ('en', 'English'), ('fr', 'French (français)'), ('de', 'German (Deutsch)'), ('es', 'Spanish (español)'), ] names = get_language_names(TestConfiguration.TRANSLATION_DIR) mock_listdir.assert_called() self.assertListEqual(expected_names, list(names))
def test_get_language_names_without_native_names(self, mock_listdir: MagicMock): """ Test getting the list of language names without their native names. Expected result: The list is returned and sorted by their name. """ mock_listdir.return_value = [ 'es', 'fr', 'de', ] expected_names = [ ('en', 'English'), ('fr', 'French'), ('de', 'German'), ('es', 'Spanish'), ] names = get_language_names(TestConfiguration.TRANSLATION_DIR, with_native_names=False) mock_listdir.assert_called() self.assertListEqual(expected_names, list(names))