def test_change_setting_by_name(self):
        """
        To test the method AppSettings.change_setting_by_name, we have to assert the following:
        1.Trying to change a setting, which does not exist should throw a SettingUnknownException.
        2.Trying to change a setting, which does exist, should result in the setting having the changed value.
        """
        # make sure we have a string, which is not a key in the dictionary
        random_word_length = 10
        random_word = RandomStringCreator.randomword(random_word_length)
        while random_word in AppSettings.settings:
            random_word_length += 1
            random_word = RandomStringCreator.randomword(random_word_length)

        # check for 1. (Does the method throw the correct exception?)
        try:
            AppSettings.change_setting_by_name(random_word, 'abc')
            assert False, 'Could change a not existing setting.'
        except SettingUnknownException:
            assert random_word not in AppSettings.settings, \
                'The method AppSettings.change_setting_by_name falsely throws exception SettingUnknownException.'

        # check for 2. (Does the method set the correct value for the setting?)
        if len(AppSettings.settings.keys()) == 0:
            test_setting_name = 'test_setting_name'
            test_setting_value = 'test_setting_value'
            new_value = test_setting_value + '_1'
            AppSettings.add_setting_by_name(test_setting_name,
                                            test_setting_value)
            AppSettings.change_setting_by_name(test_setting_name, new_value)
            assert AppSettings.get_setting_by_name(test_setting_name) == new_value, \
                'The method AppSettings.change_setting_by_name not set the correct value.'
        else:
            existing_dictionary_key = list(AppSettings.settings.keys())[0]
            try:
                old_value = AppSettings.get_setting_by_name(
                    existing_dictionary_key)
                new_value = old_value + '_1'
                AppSettings.change_setting_by_name(existing_dictionary_key,
                                                   new_value)
                assert AppSettings.get_setting_by_name(existing_dictionary_key) == new_value, \
                    'The method AppSettings.change_setting_by_name does change to the correct value.'
            except SettingUnknownException:
                assert False, 'AppSettings.change_setting_by_name a SettingUnknownException, ' \
                              'although the accessed key existed in the settings dictionary.'
    def test_change_setting_by_name(self):
        """
        To test the method AppSettings.change_setting_by_name, we have to assert the following:
        1.Trying to change a setting, which does not exist should throw a SettingUnknownException.
        2.Trying to change a setting, which does exist, should result in the setting having the changed value.
        """
        # make sure we have a string, which is not a key in the dictionary
        random_word_length = 10
        random_word = RandomStringCreator.randomword(random_word_length)
        while random_word in AppSettings.settings:
            random_word_length += 1
            random_word = RandomStringCreator.randomword(random_word_length)

        # check for 1. (Does the method throw the correct exception?)
        try:
            AppSettings.change_setting_by_name(random_word, 'abc')
            assert False, 'Could change a not existing setting.'
        except SettingUnknownException:
            assert random_word not in AppSettings.settings, \
                'The method AppSettings.change_setting_by_name falsely throws exception SettingUnknownException.'

        # check for 2. (Does the method set the correct value for the setting?)
        if len(AppSettings.settings.keys()) == 0:
            test_setting_name = 'test_setting_name'
            test_setting_value = 'test_setting_value'
            new_value = test_setting_value + '_1'
            AppSettings.add_setting_by_name(test_setting_name, test_setting_value)
            AppSettings.change_setting_by_name(test_setting_name, new_value)
            assert AppSettings.get_setting_by_name(test_setting_name) == new_value, \
                'The method AppSettings.change_setting_by_name not set the correct value.'
        else:
            existing_dictionary_key = list(AppSettings.settings.keys())[0]
            try:
                old_value = AppSettings.get_setting_by_name(existing_dictionary_key)
                new_value = old_value + '_1'
                AppSettings.change_setting_by_name(existing_dictionary_key, new_value)
                assert AppSettings.get_setting_by_name(existing_dictionary_key) == new_value, \
                    'The method AppSettings.change_setting_by_name does change to the correct value.'
            except SettingUnknownException:
                assert False, 'AppSettings.change_setting_by_name a SettingUnknownException, ' \
                              'although the accessed key existed in the settings dictionary.'
    def test_get_setting_by_name(self):
        """
        To test the get_setting_by_name method, we have to assert the following:
        1. trying to access a setting, which does not exist raises the appropriate exception
        2. trying to access a setting, which does exist, will return the correct settings value
        To assert 2., we can set a settings value using the change_setting_by_name or add_setting_by_name.
        """

        # make sure we have a string, which is not a key in the dictionary
        random_word_length = 10
        random_word = RandomStringCreator.randomword(random_word_length)
        while random_word in AppSettings.settings:
            random_word_length += 1
            random_word = RandomStringCreator.randomword(random_word_length)

        # check for 1. (does it throw the correct exception?)
        try:
            AppSettings.get_setting_by_name(random_word)
            assert False, 'Could get a value for a not existing setting.'
        except SettingUnknownException:
            assert random_word not in AppSettings.settings, \
                'The method AppSettings.get_setting_by_name falsely throws exception SettingUnknownException.'

        # check for 2.
        if len(AppSettings.settings.keys()) == 0:
            test_setting_name = 'test_setting_name'
            test_setting_value = 'test_setting_value'
            AppSettings.add_setting_by_name(test_setting_name,
                                            test_setting_value)
            assert AppSettings.get_setting_by_name(test_setting_name) == test_setting_value, \
                'The method AppSettings.get_setting_by_name does not return the correct value.'
        else:
            existing_dictionary_key = list(AppSettings.settings.keys())[0]
            try:
                returned_value = AppSettings.get_setting_by_name(
                    existing_dictionary_key)
                expected_value = AppSettings.settings[existing_dictionary_key]
                assert returned_value == expected_value, \
                    'The method AppSettings.get_setting_by_name does not return the correct value.'
            except SettingUnknownException:
                assert False, 'Exception raised although the accessed key existed in the settings dictionary.'
    def test_get_setting_by_name(self):
        """
        To test the get_setting_by_name method, we have to assert the following:
        1. trying to access a setting, which does not exist raises the appropriate exception
        2. trying to access a setting, which does exist, will return the correct settings value
        To assert 2., we can set a settings value using the change_setting_by_name or add_setting_by_name.
        """

        # make sure we have a string, which is not a key in the dictionary
        random_word_length = 10
        random_word = RandomStringCreator.randomword(random_word_length)
        while random_word in AppSettings.settings:
            random_word_length += 1
            random_word = RandomStringCreator.randomword(random_word_length)

        # check for 1. (does it throw the correct exception?)
        try:
            AppSettings.get_setting_by_name(random_word)
            assert False, 'Could get a value for a not existing setting.'
        except SettingUnknownException:
            assert random_word not in AppSettings.settings, \
                'The method AppSettings.get_setting_by_name falsely throws exception SettingUnknownException.'

        # check for 2.
        if len(AppSettings.settings.keys()) == 0:
            test_setting_name = 'test_setting_name'
            test_setting_value = 'test_setting_value'
            AppSettings.add_setting_by_name(test_setting_name, test_setting_value)
            assert AppSettings.get_setting_by_name(test_setting_name) == test_setting_value, \
                'The method AppSettings.get_setting_by_name does not return the correct value.'
        else:
            existing_dictionary_key = list(AppSettings.settings.keys())[0]
            try:
                returned_value = AppSettings.get_setting_by_name(existing_dictionary_key)
                expected_value = AppSettings.settings[existing_dictionary_key]
                assert returned_value == expected_value, \
                    'The method AppSettings.get_setting_by_name does not return the correct value.'
            except SettingUnknownException:
                assert False, 'Exception raised although the accessed key existed in the settings dictionary.'
 def create_random_vocable(self):
     return Vocable(
         first_language_translations=[RandomStringCreator.randomword(10)],
         first_language_phonetic_scripts=[RandomStringCreator.randomword(10)],
         second_language_translations=[RandomStringCreator.randomword(10)],
         second_language_phonetic_scripts=[RandomStringCreator.randomword(10)],
         topics=[RandomStringCreator.randomword(10)],
         chapters=[RandomStringCreator.randomword(10)],
         learn_level=str(randint(0, 5)),
         relevance_level=str(randint(0, 5)),
         description=RandomStringCreator.randomword(10)
     )
    def vocable_not_in_list(self):
        vocable_not_in_list = Vocable(
            first_language_translations=[RandomStringCreator.randomword(10)],
            first_language_phonetic_scripts=[RandomStringCreator.randomword(10)],
            second_language_translations=[RandomStringCreator.randomword(10)],
            second_language_phonetic_scripts=[RandomStringCreator.randomword(10)],
            topics=[RandomStringCreator.randomword(10)],
            chapters=[RandomStringCreator.randomword(10)],
            learn_level=str(randint(0, 5)),
            relevance_level=str(randint(0, 5)),
            description=RandomStringCreator.randomword(10)
        )

        while any(
                item for item in VocableManager.vocables
                if item.first_language_translations == vocable_not_in_list.first_language_translations
        ):
            vocable_not_in_list = Vocable(
                first_language_translations=[RandomStringCreator.randomword(10)],
                first_language_phonetic_scripts=[RandomStringCreator.randomword(10)],
                second_language_translations=[RandomStringCreator.randomword(10)],
                second_language_phonetic_scripts=[RandomStringCreator.randomword(10)],
                topics=[RandomStringCreator.randomword(10)],
                chapters=[RandomStringCreator.randomword(10)],
                learn_level=str(randint(0, 5)),
                relevance_level=str(randint(0, 5)),
                description=RandomStringCreator.randomword(10)
            )

        return vocable_not_in_list
    def vocable_not_in_list(self):
        vocable_not_in_list = Vocable(
            first_language_translations=[RandomStringCreator.randomword(10)],
            first_language_phonetic_scripts=[
                RandomStringCreator.randomword(10)
            ],
            second_language_translations=[RandomStringCreator.randomword(10)],
            second_language_phonetic_scripts=[
                RandomStringCreator.randomword(10)
            ],
            topics=[RandomStringCreator.randomword(10)],
            chapters=[RandomStringCreator.randomword(10)],
            learn_level=str(randint(0, 5)),
            relevance_level=str(randint(0, 5)),
            description=RandomStringCreator.randomword(10))

        while any(item for item in VocableManager.vocables
                  if item.first_language_translations ==
                  vocable_not_in_list.first_language_translations):
            vocable_not_in_list = Vocable(
                first_language_translations=[
                    RandomStringCreator.randomword(10)
                ],
                first_language_phonetic_scripts=[
                    RandomStringCreator.randomword(10)
                ],
                second_language_translations=[
                    RandomStringCreator.randomword(10)
                ],
                second_language_phonetic_scripts=[
                    RandomStringCreator.randomword(10)
                ],
                topics=[RandomStringCreator.randomword(10)],
                chapters=[RandomStringCreator.randomword(10)],
                learn_level=str(randint(0, 5)),
                relevance_level=str(randint(0, 5)),
                description=RandomStringCreator.randomword(10))

        return vocable_not_in_list