Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
 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')
Exemple #4
0
 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
Exemple #5
0
 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')
Exemple #6
0
 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')
Exemple #7
0
 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')
Exemple #8
0
 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
Exemple #9
0
 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')
Exemple #10
0
 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')
Exemple #11
0
 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')
Exemple #12
0
 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')
Exemple #13
0
 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')
Exemple #14
0
 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')
Exemple #15
0
 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')
Exemple #16
0
 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')