def test_boto3_not_installed(self): from central.config import s3 boto3_tmp = s3.boto3 s3.boto3 = None with self.assertRaises(LibraryRequiredError): S3Config(self.s3, 'bucket name', 'config.json') s3.boto3 = boto3_tmp
def test_init_reader_with_reader_value(self): reader = JsonReader() config = S3Config(client=self.s3, bucket_name='bucket name', filename='config.json', reader=reader) self.assertEqual(reader, config.reader)
def test_init_reader_with_str_value(self): with self.assertRaises(TypeError): S3Config(client=self.s3, bucket_name='bucket name', filename='config.json', reader='non raeader')
def test_get_reader_with_default_value(self): config = S3Config(client=self.s3, bucket_name='bucket name', filename='config.json') self.assertIsNone(config.reader)
def test_init_filename_with_str_value(self): config = S3Config(client=self.s3, bucket_name='bucket name', filename='config.json') self.assertEqual('config.json', config.filename)
def test_init_filename_with_int_value(self): with self.assertRaises(TypeError): S3Config(client=self.s3, bucket_name='bucket name', filename=123)
def test_init_bucket_name_with_none_value(self): with self.assertRaises(TypeError): S3Config(client=self.s3, bucket_name=None, filename='config.json')
def test_load_without_file_extension(self): config = S3Config(client=self.s3, bucket_name='bucket name', filename='./config') with self.assertRaises(ConfigError): config.load()
# # UPLOAD config.json into your S3 Account # import boto3 from central.config.s3 import S3Config s3 = boto3.resource('s3') config = S3Config(s3, 'bucket-name', 'config.json') config.load() print(config.get('timeout')) print(config.get('database')) print(config.get('database.host')) print(config.get('database.port'))