def test_get_s3_object_decode_error(self): conn = boto3.resource('s3', region_name='us-east-1') conn.create_bucket(Bucket='test') conn.Object('test', 'vars.json').put(Body='simple_string') with pytest.raises(ValueError): S3Environ(bucket='test', key='vars.json')
def test_get_s3_object(self): conn = boto3.resource('s3', region_name='us-east-1') conn.create_bucket(Bucket='test') conn.Object('test', 'vars.json').put(Body=json.dumps(self.FILE)) s3_environ = S3Environ(bucket='test', key='vars.json') output = s3_environ.get_s3_object() assert output == self.FILE
def test_set_variables(self): conn = boto3.resource('s3', region_name='us-east-1') conn.create_bucket(Bucket='test') conn.Object('test', 'vars.json').put(Body=json.dumps(self.FILE)) S3Environ(bucket='test', key='vars.json') for key, value in self.FILE.items(): assert os.environ.get(key) == str(value)
from s3_environ import S3Environ from sentry_sdk.integrations.django import DjangoIntegration ### # Get data from .env file ### BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) dotenv.read_dotenv(os.path.join(BASE_DIR, '.env')) ENVIRONMENT = os.environ.get('ENVIRONMENT') LOAD_ENVS_FROM_FILE = True if os.environ.get('LOAD_ENVS_FROM_FILE', False) == 'True' else False env_file = 'envs-production.json' if ENVIRONMENT == 'production' else 'envs-staging.json' if not LOAD_ENVS_FROM_FILE: S3Environ(bucket='bucket-env', key=env_file) print("Loading envs from S3: {0}".format(env_file)) ### # Security ### SECRET_KEY = os.environ.get('SECRET_KEY') DEBUG = ENVIRONMENT == 'development' or os.environ.get('DEBUG', False) ALLOWED_HOSTS = [ '.us-west-2.elb.amazonaws.com', '.compute-1.amazonaws.com', 'localhost', ] EC2_PRIVATE_IP = None
from s3_environ import S3Environ from sentry_sdk.integrations.django import DjangoIntegration ### # Get data from .env file ### BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) dotenv.read_dotenv(os.path.join(BASE_DIR, '.env')) ENVIRONMENT = os.environ.get('ENVIRONMENT') LOAD_ENVS_FROM_FILE = True if os.environ.get('LOAD_ENVS_FROM_FILE', False) == 'True' else False env_file = 'envs-production.json' if ENVIRONMENT == 'production' else 'envs-staging.json' if not LOAD_ENVS_FROM_FILE: S3Environ(bucket='reddit-envs', key=env_file) print("Loading envs from S3: {0}".format(env_file)) ### # Security ### SECRET_KEY = os.environ.get('SECRET_KEY') DEBUG = ENVIRONMENT == 'development' or os.environ.get('DEBUG', False) ALLOWED_HOSTS = [ '.us-east-1.elb.amazonaws.com', '.compute-1.amazonaws.com', 'localhost', '.hnrq.in', '.clubedotrago.com', ]
def test_get_s3_object_error(self): with pytest.raises(Exception): S3Environ(bucket='test', key='vars.json')