Пример #1
0
    def test_warns_if_line_format_is_incorrect(self):
        with warnings.catch_warnings(record=True) as w:
            parse_dotenv('lol$wut')

            self.assertEqual(len(w), 1)
            self.assertTrue(w[0].category is SyntaxWarning)
            self.assertEqual(str(w[0].message),
                             "Line 'lol$wut' doesn't match format")
Пример #2
0
    def test_warns_if_line_format_is_incorrect(self):
        with warnings.catch_warnings(record=True) as w:
            parse_dotenv('lol$wut')

            self.assertEqual(len(w), 1)
            self.assertTrue(w[0].category is SyntaxWarning)
            self.assertEqual(
                str(w[0].message),
                "Line 'lol$wut' doesn't match format"
            )
Пример #3
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    try:
        load_dotenv('.env')
        app.config.update(parse_dotenv('.env'))
    except TypeError:
        print('Error parsing .env')
    app.config['MONGODB_SETTINGS'] = {
        'db': app.config['MONGO_DBNAME'],
        'host': app.config['MONGO_URI']
    }
    config[config_name].init_app(app)   
    bootstrap.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

    from main import main as main_blueprint
    app.register_blueprint(main_blueprint)
    
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/auth')
 # attach routes and custom error pages here
    return app
Пример #4
0
    def __init__(self, dotenv_path):
        if dotenv is None:
            raise ImportError(
                'install configstore[dotenv] to use the dotenv backend')

        with open(dotenv_path) as file:
            content = file.read()

        self.config = dotenv.parse_dotenv(content)
Пример #5
0
def env_check():
    parsed = parse_dotenv(env_file)
    env_var_dict = dict(parsed).items()
    env_var_list = list(parsed)
    for k, v in env_var_list:
        for local_k, local_v in env_var_list:
            if local_k == k:
                if local_v == v:
                    sys.stdout.write('same value')
                else:
                    sys.stdout.write('different value')
Пример #6
0
def sync_env():
    # env_var_dict = dict(parsed).items()
    mem_file = StringIO()
    # todo add remote environment path
    get(remote_path, mem_file)
    remote_env = mem_file.getvalue()
    local_env = list(parse_dotenv(env_file))
    for k, v in remote_env:
        for local_k, local_v in local_env:
            if local_k == k:
                if local_v == v:
                    continue
                else:
                    config("set", k, v)
Пример #7
0
def set_environment_variables():
    logger = getLogger()
    try:
        import dotenv
        from path import Path

        with open(Path(__file__).dirname().abspath() / '.env') as dot_env:
            env = dotenv.parse_dotenv(dot_env.read())

            # log any updates to the environment
            logger.warning('----> Overrides from .env')
            pad = max(len(_) for _ in os.environ) + 2
            if env:
                for k, v in sorted(env.items()):
                    v = os.environ.setdefault(k, v)
                    logger.warning('  --> {k:·<{pad}} {v}'.format(pad=pad, k=k, v=v))
            else:
                logger.warning('  --> no overrides from .env')

    except (ImportError, FileNotFoundError):
        pass

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

    DATABASE_URL = os.environ.get('DATABASE_URL')
    ENVIRONMENT = os.environ.get('ENVIRONMENT')

    if DATABASE_URL and not os.environ.get('DATABASE_AWS_CHECK'):
        if ENVIRONMENT != 'PRODUCTION' and 'localhost' not in DATABASE_URL:
            confirm = input('say yes >>> ')
            if confirm != 'yes':
                exit(1)

            logger.critical(' USING PRODUCTION DATABASE '.center(80, '-'))
            logger.critical(DATABASE_URL)
            logger.critical(' USING PRODUCTION DATABASE '.center(80, '-'))
Пример #8
0
 def test_expands_variables_found_in_values(self):
     env = parse_dotenv("FOO=test\nBAR=$FOO")
     self.assertEqual(env, {'FOO': 'test', 'BAR': 'test'})
Пример #9
0
 def test_parses_escaped_double_quotes(self):
     env = parse_dotenv('FOO="escaped\"bar"')
     self.assertEqual(env, {'FOO': 'escaped"bar'})
Пример #10
0
 def test_parses_double_quoted_values(self):
     env = parse_dotenv('FOO="bar"')
     self.assertEqual(env, {'FOO': 'bar'})
Пример #11
0
 def test_parses_double_quoted_values(self):
     env = parse_dotenv('FOO="bar"')
     self.assertEqual(env, {'FOO': 'bar'})
Пример #12
0
 def test_allows_hash_in_quoted_values(self):
     env = parse_dotenv('foo="bar#baz" # comment ')
     self.assertEqual(env, {'foo': 'bar#baz'})
Пример #13
0
# Standard Library
import os
import sys

# External Libraries
from logging import getLogger


if __name__ == '__main__':
    logger = getLogger()

    try:
        import dotenv
        with open('.env') as dot_env:
            env = dotenv.parse_dotenv(dot_env.read())

            # log any updates to the environment
            logger.warn('----> Overrides from .env')
            if env:
                for k, v in sorted(env.items()):
                    v = os.environ.setdefault(k, v)
                    logger.warn('  --> %-20s - %s', k, v)
            else:
                logger.warn('  --> no overrides from .env')

    except (ImportError, FileNotFoundError):
        pass

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lindy.lindyfocus.settings')
Пример #14
0
    def test_does_not_expand_escaped_variables(self):
        env = parse_dotenv('FOO="foo\\$BAR"')
        self.assertEqual(env, {'FOO': 'foo$BAR'})

        env = parse_dotenv('FOO="foo\${BAR}"')
        self.assertEqual(env, {'FOO': 'foo${BAR}'})
Пример #15
0
 def test_expands_undefined_variables_to_an_empty_string(self):
     self.assertEqual(parse_dotenv('BAR=$FOO'), {'BAR': ''})
Пример #16
0
 def test_expands_variables_from_environ_if_not_found_in_local_env(self):
     os.environ.setdefault('FOO', 'test')
     env = parse_dotenv('BAR=$FOO')
     self.assertEqual(env, {'BAR': 'test'})
Пример #17
0
 def test_expands_variables_wrapped_in_brackets(self):
     env = parse_dotenv("FOO=test\nBAR=${FOO}bar")
     self.assertEqual(env, {'FOO': 'test', 'BAR': 'testbar'})
Пример #18
0
 def test_expands_variables_found_in_values(self):
     env = parse_dotenv("FOO=test\nBAR=$FOO")
     self.assertEqual(env, {'FOO': 'test', 'BAR': 'test'})
Пример #19
0
 def test_parses_empty_values(self):
     env = parse_dotenv('FOO=')
     self.assertEqual(env, {'FOO': ''})
Пример #20
0
 def test_parses_escaped_double_quotes(self):
     env = parse_dotenv('FOO="escaped\\"bar"')
     self.assertEqual(env, {'FOO': 'escaped"bar'})
Пример #21
0
 def test_parses_single_quoted_values(self):
     env = parse_dotenv("FOO='bar'")
     self.assertEqual(env, {'FOO': 'bar'})
Пример #22
0
 def test_expands_variables_from_environ_if_not_found_in_local_env(self):
     os.environ.setdefault('FOO', 'test')
     env = parse_dotenv('BAR=$FOO')
     self.assertEqual(env, {'BAR': 'test'})
Пример #23
0
 def test_expands_variables_in_double_quoted_values(self):
     env = parse_dotenv("FOO=test\nBAR=\"quote $FOO\"")
     self.assertEqual(env, {'FOO': 'test', 'BAR': 'quote test'})
Пример #24
0
 def test_expands_variables_in_double_quoted_values(self):
     env = parse_dotenv("FOO=test\nBAR=\"quote $FOO\"")
     self.assertEqual(env, {'FOO': 'test', 'BAR': 'quote test'})
Пример #25
0
 def test_parses_key_with_dot_in_the_name(self):
     env = parse_dotenv('FOO.BAR=foobar')
     self.assertEqual(env, {'FOO.BAR': 'foobar'})
Пример #26
0
 def test_does_not_expand_variables_in_single_quoted_values(self):
     env = parse_dotenv("BAR='quote $FOO'")
     self.assertEqual(env, {'BAR': 'quote $FOO'})
Пример #27
0
 def test_ignores_empty_lines(self):
     env = parse_dotenv("\n \t  \nfoo=bar\n \nfizz=buzz")
     self.assertEqual(env, {'foo': 'bar', 'fizz': 'buzz'})
Пример #28
0
    def test_does_not_expand_escaped_variables(self):
        env = parse_dotenv('FOO="foo\\$BAR"')
        self.assertEqual(env, {'FOO': 'foo$BAR'})

        env = parse_dotenv('FOO="foo\${BAR}"')
        self.assertEqual(env, {'FOO': 'foo${BAR}'})
Пример #29
0
 def test_parses_export_keyword(self):
     env = parse_dotenv('export FOO=bar')
     self.assertEqual(env, {'FOO': 'bar'})
Пример #30
0
 def test_parses_key_with_dot_in_the_name(self):
     env = parse_dotenv('FOO.BAR=foobar')
     self.assertEqual(env, {'FOO.BAR': 'foobar'})
Пример #31
0
    def test_parses_values_with_spaces_around_equal_sign(self):
        env = parse_dotenv('FOO =bar')
        self.assertEqual(env, {'FOO': 'bar'})

        env = parse_dotenv('FOO= bar')
        self.assertEqual(env, {'FOO': 'bar'})
Пример #32
0
 def test_strips_unquoted_values(self):
     env = parse_dotenv('foo=bar ')
     self.assertEqual(env, {'foo': 'bar'})  # not 'bar '
Пример #33
0
 def test_parses_single_quoted_values(self):
     env = parse_dotenv("FOO='bar'")
     self.assertEqual(env, {'FOO': 'bar'})
Пример #34
0
    def test_parses_hash_in_quoted_values(self):
        env = parse_dotenv('foo="ba#r"')
        self.assertEqual(env, {'foo': 'ba#r'})

        env = parse_dotenv('foo="ba#r"')
        self.assertEqual(parse_dotenv("foo='ba#r'"), {'foo': 'ba#r'})
Пример #35
0
 def test_parses_empty_values(self):
     env = parse_dotenv('FOO=')
     self.assertEqual(env, {'FOO': ''})
Пример #36
0
 def test_parses_unquoted_values(self):
     env = parse_dotenv('FOO=bar')
     self.assertEqual(env, {'FOO': 'bar'})
Пример #37
0
 def test_expands_variables_wrapped_in_brackets(self):
     env = parse_dotenv("FOO=test\nBAR=${FOO}bar")
     self.assertEqual(env, {'FOO': 'test', 'BAR': 'testbar'})
Пример #38
0
 def test_ignores_empty_lines(self):
     env = parse_dotenv("\n \t  \nfoo=bar\n \nfizz=buzz")
     self.assertEqual(env, {'foo': 'bar', 'fizz': 'buzz'})
Пример #39
0
 def test_expands_undefined_variables_to_an_empty_string(self):
     self.assertEqual(parse_dotenv('BAR=$FOO'), {'BAR': ''})
Пример #40
0
 def test_ignores_inline_comments(self):
     env = parse_dotenv('foo=bar # this is foo')
     self.assertEqual(env, {'foo': 'bar'})
Пример #41
0
 def test_does_not_expand_variables_in_single_quoted_values(self):
     env = parse_dotenv("BAR='quote $FOO'")
     self.assertEqual(env, {'BAR': 'quote $FOO'})
Пример #42
0
 def test_allows_hash_in_quoted_values(self):
     env = parse_dotenv('foo="bar#baz" # comment ')
     self.assertEqual(env, {'foo': 'bar#baz'})
Пример #43
0
 def test_parses_export_keyword(self):
     env = parse_dotenv('export FOO=bar')
     self.assertEqual(env, {'FOO': 'bar'})
Пример #44
0
 def test_ignores_comment_lines(self):
     env = parse_dotenv("\n\n\n # HERE GOES FOO \nfoo=bar")
     self.assertEqual(env, {'foo': 'bar'})
Пример #45
0
 def test_strips_unquoted_values(self):
     env = parse_dotenv('foo=bar ')
     self.assertEqual(env, {'foo': 'bar'})  # not 'bar '
Пример #46
0
def create_app(config_name):
    app = Flask(__name__)

    app.config.from_object(config[config_name])
    try:
        load_dotenv('.env')
        app.config.update(parse_dotenv('.env'))
    except TypeError:
        print('Error parsing .env')
    app.config['SECRET_KEY']
    app.config['SESSION_TYPE']= 'filesystem'
    app.config['MONGODB_SETTINGS'] = {
        'db': app.config['MONGO_DBNAME'],
        'host': app.config['MONGO_URI']
    }

    #MAIL
    app.config.update(
        DEBUG=True,
        #EMAIL SETTINGS
        MAIL_SERVER= app.config['MAIL_SERVER'],
        MAIL_PORT = app.config['MAIL_PORT'],
        MAIL_USE_TLS = False,
        MAIL_USE_SSL = True,
        MAIL_USERNAME = app.config['MAIL_USERNAME'],
        MAIL_PASSWORD = app.config['MAIL_PASSWORD']
    )

    mail = Mail(app)


    config[config_name].init_app(app)
    bootstrap.init_app(app)
    # mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

    Session(app)

# additional _init_.py file in each of these modules
    from main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/auth')

    from .browse import browse as browse_blueprint
    app.register_blueprint(browse_blueprint)

    from .literature import lit as lit_blueprint
    app.register_blueprint(lit_blueprint)

    from .preferences import pref as pref_blueprint
    app.register_blueprint(pref_blueprint)

    from .search import search as search_blueprint
    app.register_blueprint(search_blueprint)

    from .user import user as user_blueprint
    app.register_blueprint(user_blueprint)

 # attach routes and custom error pages here
    return app
Пример #47
0
 def test_parses_unquoted_values(self):
     env = parse_dotenv('FOO=bar')
     self.assertEqual(env, {'FOO': 'bar'})
Пример #48
0
 def test_source_env_relative(self):
     fname = '~/.envrc.user'
     env = parse_dotenv(f'[[ -f {fname} ]] && source_env {fname}')
     self.assertEqual(env, {'source_env': [f'{os.path.expanduser(fname)}']})
Пример #49
0
 def test_ignores_inline_comments(self):
     env = parse_dotenv('foo=bar # this is foo')
     self.assertEqual(env, {'foo': 'bar'})
Пример #50
0
 def test_replaces_from_previous_value(self):
     env = parse_dotenv('foo=bar\nbaz=$foo')
     self.assertEqual(env, {'foo': 'bar', 'baz': 'bar'})
Пример #51
0
 def test_ignores_comment_lines(self):
     env = parse_dotenv("\n\n\n # HERE GOES FOO \nfoo=bar")
     self.assertEqual(env, {'foo': 'bar'})
Пример #52
0
    def test_parses_hash_in_quoted_values(self):
        env = parse_dotenv('foo="ba#r"')
        self.assertEqual(env, {'foo': 'ba#r'})

        env = parse_dotenv('foo="ba#r"')
        self.assertEqual(parse_dotenv("foo='ba#r'"), {'foo': 'ba#r'})
Пример #53
0
 def test_source_env_absolute(self):
     fname = '.envrc.local'
     env = parse_dotenv(f'[[ -f {fname} ]] && source_env {fname}')
     self.assertEqual(env, {'source_env': ['.envrc.local']})
Пример #54
0
    def test_parses_values_with_spaces_around_equal_sign(self):
        env = parse_dotenv('FOO =bar')
        self.assertEqual(env, {'FOO': 'bar'})

        env = parse_dotenv('FOO= bar')
        self.assertEqual(env, {'FOO': 'bar'})