def test__get_asiaq_option__env_in_constructor(self): "Env-specific option with environment passed in at construction time" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT), environment='ci') self.assertEqual( 'ci_answer', config.get_asiaq_option('envy_option', section='mhcfoobar'))
def test__get_asiaq_option__missing_not_required_no_default__none(self): "Missing option with required=False and default" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertIsNone( config.get_asiaq_option('nobody-cares-about-this', section='mhcfoobar', required=False))
def test__get_asiaq_s3_bucket_name__no_suffix(self): "Missing suffix should not produce a problem for the bucket-name method." config_dict = deepcopy(self.BASE_CONFIG_DICT) config_dict[disco_config. DEFAULT_CONFIG_SECTION]['s3_bucket_base'] = 'bucket-base' config = MockAsiaqConfig(config_dict) self.assertEqual("bucket-base--foobar", config.get_asiaq_s3_bucket_name('foobar'))
def test__get_asiaq_s3_bucket_name__bad_env_specified(self): "Environment-specific behavior of get_asiaq_s3_bucket_name with a nonsense env works as expected" config_dict = deepcopy(self.BASE_CONFIG_DICT) config_dict[disco_config.DEFAULT_CONFIG_SECTION].update( self.S3_BUCKET_CONFIG) config = MockAsiaqConfig(config_dict, environment="nope") self.assertEqual("bucket-base--foobar--blah", config.get_asiaq_s3_bucket_name('foobar'))
def test__get_asiaq_option__bad_env_in_call(self): "Env-specific option with unused environment passed in at call time" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual( 'fallback_answer', config.get_asiaq_option('envy_option', section='mhcfoobar', environment='nope'))
def test__get_asiaq_option__default_section(self): "Option found in defaults as fallback" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual('fall-all-the-way-back', config.get_asiaq_option('unused_option')) self.assertEqual( 'fall-all-the-way-back', config.get_asiaq_option('unused_option', section='mhcfoobar'))
def test__get_asiaq_s3_bucket_name__defaults(self): "Base behavior of get_asiaq_s3_bucket_name works as expected." config_dict = deepcopy(self.BASE_CONFIG_DICT) config_dict[disco_config.DEFAULT_CONFIG_SECTION].update( self.S3_BUCKET_CONFIG) config = MockAsiaqConfig(config_dict) self.assertEqual("bucket-base--foobar--blah", config.get_asiaq_s3_bucket_name('foobar'))
def test__get_asiaq_option__missing_not_required__default(self): "Missing option with required=False and default" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual( "passed-in-default", config.get_asiaq_option('nobody-cares-about-this', section='mhcfoobar', required=False, default="passed-in-default"))
def test__get_asiaq_option__missing__exception(self): "Missing option with required=True" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertRaises(NoOptionError, config.get_asiaq_option, 'nobody-cares-about-this', section='mhcfoobar')
def test__get_asiaq_option__nonsense_args__error(self): "Invalid arguments to get_asiaq_option produce an error." config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertRaises(exceptions.ProgrammerError, config.get_asiaq_option, 'immaterial', required=True, default=12345)
def test__get_asiaq_option__env_in_constructor_and_call(self): "Env-specific option with environment passed in at call time" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT), environment="bad_env") self.assertEqual('ci_answer', config.get_asiaq_option('envy_option', section='mhcfoobar', environment='ci'))
def test__get_asiaq_option__missing_not_required__default(self): "Missing option with required=False and default" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual("passed-in-default", config.get_asiaq_option('nobody-cares-about-this', section='mhcfoobar', required=False, default="passed-in-default"))
def test__get_asiaq_option__default_env(self): "Env-specific option with default environment" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual('default_env_answer', config.get_asiaq_option(option='envy_option', section='mhcfoobar'))
def test__get_asiaq_s3_bucket_name__bad_env_specified(self): "Environment-specific behavior of get_asiaq_s3_bucket_name with a nonsense env works as expected" config_dict = deepcopy(self.BASE_CONFIG_DICT) config_dict[disco_config.DEFAULT_CONFIG_SECTION].update(self.S3_BUCKET_CONFIG) config = MockAsiaqConfig(config_dict, environment="nope") self.assertEqual("bucket-base--foobar--blah", config.get_asiaq_s3_bucket_name('foobar'))
def test__get_asiaq_s3_bucket_name__defaults(self): "Base behavior of get_asiaq_s3_bucket_name works as expected." config_dict = deepcopy(self.BASE_CONFIG_DICT) config_dict[disco_config.DEFAULT_CONFIG_SECTION].update(self.S3_BUCKET_CONFIG) config = MockAsiaqConfig(config_dict) self.assertEqual("bucket-base--foobar--blah", config.get_asiaq_s3_bucket_name('foobar'))
def test__get_asiaq_s3_bucket_name__no_suffix(self): "Missing suffix should not produce a problem for the bucket-name method." config_dict = deepcopy(self.BASE_CONFIG_DICT) config_dict[disco_config.DEFAULT_CONFIG_SECTION]['s3_bucket_base'] = 'bucket-base' config = MockAsiaqConfig(config_dict) self.assertEqual("bucket-base--foobar", config.get_asiaq_s3_bucket_name('foobar'))
def test__get_asiaq_option__missing_not_required_no_default__none(self): "Missing option with required=False and default" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertIsNone(config.get_asiaq_option('nobody-cares-about-this', section='mhcfoobar', required=False))
def test__get_asiaq_s3_bucket_name__no_prefix__error(self): "Missing bucket prefix should make bucket-name method raise an exception." config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertRaises(NoOptionError, config.get_asiaq_s3_bucket_name, 'foobar')
def test__get_asiaq_option__bad_env_in_call(self): "Env-specific option with unused environment passed in at call time" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual('fallback_answer', config.get_asiaq_option('envy_option', section='mhcfoobar', environment='nope'))
def test__get_asiaq_option__no_env_options(self): "Option exists in desired section: found it" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual( 'easy_answer', config.get_asiaq_option(option='easy_option', section='mhcfoobar'))
def test__get_asiaq_option__default_section(self): "Option found in defaults as fallback" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual('fall-all-the-way-back', config.get_asiaq_option('unused_option')) self.assertEqual('fall-all-the-way-back', config.get_asiaq_option('unused_option', section='mhcfoobar'))
def test__get_asiaq_option__default_env(self): "Env-specific option with default environment" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual( 'default_env_answer', config.get_asiaq_option(option='envy_option', section='mhcfoobar'))
def test__get_asiaq_option__no_env_options(self): "Option exists in desired section: found it" config = MockAsiaqConfig(deepcopy(self.BASE_CONFIG_DICT)) self.assertEqual('easy_answer', config.get_asiaq_option(option='easy_option', section='mhcfoobar'))