def test_exception_thrown_if_there_are_no_credential_files(self): override = ConfigFileOverride() with override: with self.assertRaisesRegexp(AWSCredentialsMissing, "Missing AWS configuration file"): settings = Settings() _ = settings.key
def test_exception_thrown_if_dot_bodylabs_malformed(self): override = ConfigFileOverride() override.dot_bodylabs = FakeConfigFile("This is a random text file") with override: with self.assertRaisesRegexp( AWSCredentialsMissing, "Unable to read AWS configuration file"): settings = Settings() _ = settings.key
def test_defaults_to_us_east_1_if_config_missing(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) with override: settings = Settings() self.assertEqual(settings.region, 'us-east-1')
def test_exception_thrown_if_dot_bodylabs_not_a_dictionary(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile([1, 2, 3]) with override: with self.assertRaisesRegexp( AWSCredentialsMissing, "Unable to read AWS configuration file"): settings = Settings() _ = settings.key
def test_exception_not_thrown_with_environment_variables_set_but_no_config_files( self): override = ConfigFileOverride() override.env.set('AWS_ACCESS_KEY_ID', 'abc') override.env.set('AWS_SECRET_ACCESS_KEY', 'cba') with override: settings = Settings() self.assertEqual(settings.key, 'abc') self.assertEqual(settings.secret, 'cba')
def test_region_being_overriden_by_env_var_when_config_missing(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) override.env.set('AWS_DEFAULT_REGION', 'ap-northeast-1') with override: settings = Settings() self.assertEqual(settings.region, 'ap-northeast-1')
def test_just_a_dot_bodylabs_file(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) with override: settings = Settings() self.assertEqual(settings.key, 'abc') self.assertEqual(settings.secret, 'cba')
def test_exception_thrown_if_no_credentials_found(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'NO_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) with override: with self.assertRaisesRegexp(AWSCredentialsMissing, "Missing AWS credentials"): settings = Settings() _ = settings.key
def test_environment_variables_override_files(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'XXX', 'AWS_SECRET': 'XYZZX' }) override.env.set('AWS_ACCESS_KEY_ID', 'abc') override.env.set('AWS_SECRET_ACCESS_KEY', 'cba') with override: settings = Settings() self.assertEqual(settings.key, 'abc') self.assertEqual(settings.secret, 'cba')
def test_just_a_aws_credentials_file(self): override = ConfigFileOverride() override.aws_credentials = FakeConfConfigFile({ 'aws_access_key_id': 'abc', 'aws_secret_access_key': 'cba' }) with override: settings = Settings() self.assertEqual(settings.key, 'abc') self.assertEqual(settings.secret, 'cba')
def test_region_being_pulled_from_config(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) override.aws_config = FakeConfConfigFile({ 'region': 'northpole-santasvillage-1', 'otherstuff': 'just-some-junk' }) with override: settings = Settings() self.assertEqual(settings.region, 'northpole-santasvillage-1')
def test_defaults_to_us_east_1_if_config_contains_no_region(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) override.aws_config = FakeConfConfigFile({ 'not_a_region': 'northpole-santasvillage-1', 'otherstuff': 'just-some-junk' }) with override: settings = Settings() self.assertEqual(settings.region, 'us-east-1')
def test_empty_dot_bodylabs_is_fine(self): override = ConfigFileOverride() override.dot_bodylabs = FakeConfigFile('') override.aws_credentials = FakeConfConfigFile({ 'aws_access_key_id': 'abc', 'aws_secret_access_key': 'cba' }) with override: settings = Settings() self.assertEqual(settings.key, 'abc') self.assertEqual(settings.secret, 'cba')
def test_region_being_overriden_by_env_var_when_config_exists(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) override.aws_config = FakeConfConfigFile({ 'region': 'northpole-santasvillage-1', 'otherstuff': 'just-some-junk' }) override.env.set('AWS_DEFAULT_REGION', 'ap-northeast-1') with override: settings = Settings() self.assertEqual(settings.region, 'ap-northeast-1')
def test_dot_bodylabs_overrides_aws_credentials(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'AWS_ACCESS_KEY': 'abc', 'AWS_SECRET': 'cba' }) override.aws_credentials = FakeConfConfigFile({ 'aws_access_key_id': 'XXX', 'aws_secret_access_key': 'XYZZX' }) with override: settings = Settings() self.assertEqual(settings.key, 'abc') self.assertEqual(settings.secret, 'cba')
def test_dot_bodylabs_without_keys_is_fine(self): override = ConfigFileOverride() override.dot_bodylabs = FakeYAMLConfigFile({ 'FOO': 'XXX', 'BAR': 'XYZZX' }) override.aws_credentials = FakeConfConfigFile({ 'aws_access_key_id': 'abc', 'aws_secret_access_key': 'cba' }) with override: settings = Settings() self.assertEqual(settings.key, 'abc') self.assertEqual(settings.secret, 'cba')