Пример #1
0
    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.'
Пример #2
0
    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.'
Пример #3
0
    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.'
Пример #4
0
    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.'