Beispiel #1
0
    def prepare_with_browser(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ()
        result = prepare_with_browser_ui(project, environ=environ, keep_going_until_success=False, io_loop=io_loop)
        assert result
        assert dict(FOO_PASSWORD='******', PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
        assert dict() == strip_environ(environ)

        # wait for the results of the POST to come back,
        # awesome hack-tacular
        while 'post_fill_in_password' not in http_results:
            io_loop.call_later(0.01, lambda: io_loop.stop())
            io_loop.start()

        assert 'get_click_submit' in http_results
        assert 'post_click_submit' in http_results
        assert 'post_fill_in_password' in http_results

        assert 200 == http_results['get_click_submit'].code
        assert 200 == http_results['post_click_submit'].code
        assert 200 == http_results['post_fill_in_password'].code

        final_done_html = str(http_results['post_fill_in_password'].body)
        assert "Done!" in final_done_html
        assert "Environment variable FOO_PASSWORD is set." in final_done_html

        local_state_file = LocalStateFile.load_for_directory(project.directory_path)
        assert local_state_file.get_value(['variables', 'FOO_PASSWORD']) is None
Beispiel #2
0
 def prepare_some_env_var(dirname):
     project = project_no_dedicated_env(dirname)
     environ = minimal_environ(FOO='bar')
     result = prepare_without_interaction(project, environ=environ)
     assert result
     assert dict(FOO='bar', PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
     assert dict(FOO='bar') == strip_environ(environ)
Beispiel #3
0
    def prepare_with_browser(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ()
        result = prepare_with_browser_ui(project, environ=environ, keep_going_until_success=False, io_loop=io_loop)
        assert result
        assert dict(FOO_PASSWORD='******', PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
        assert dict() == strip_environ(environ)

        # wait for the results of the POST to come back,
        # awesome hack-tacular
        while 'post_fill_in_password' not in http_results:
            io_loop.call_later(0.01, lambda: io_loop.stop())
            io_loop.start()

        assert 'get_click_submit' in http_results
        assert 'post_click_submit' in http_results
        assert 'post_fill_in_password' in http_results

        assert 200 == http_results['get_click_submit'].code
        assert 200 == http_results['post_click_submit'].code
        assert 200 == http_results['post_fill_in_password'].code

        final_done_html = str(http_results['post_fill_in_password'].body)
        assert "Done!" in final_done_html
        assert "Environment variable FOO_PASSWORD is set." in final_done_html

        local_state_file = LocalStateFile.load_for_directory(project.directory_path)
        assert local_state_file.get_value(['variables', 'FOO_PASSWORD']) is None
Beispiel #4
0
 def prepare_some_env_var(dirname):
     project = project_no_dedicated_env(dirname)
     environ = minimal_environ(FOO='bar')
     result = prepare_without_interaction(project, environ=environ)
     assert result
     assert dict(FOO='bar', PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
     assert dict(FOO='bar') == strip_environ(environ)
Beispiel #5
0
    def start_local_redis(dirname):
        project = project_no_dedicated_env(dirname)
        result = _prepare_printing_errors(project, environ=minimal_environ())
        assert result
        assert 'REDIS_URL' in result.environ

        local_state_file = LocalStateFile.load_for_directory(dirname)
        state = local_state_file.get_service_run_state("REDIS_URL")
        assert 'port' in state
        port = state['port']

        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(
                        result.environ)
        assert len(can_connect_args_list) >= 2

        pidfile = os.path.join(dirname, "services/REDIS_URL/redis.pid")
        logfile = os.path.join(dirname, "services/REDIS_URL/redis.log")
        assert os.path.exists(pidfile)
        assert os.path.exists(logfile)

        assert real_can_connect_to_socket(host='localhost', port=port)

        # be sure we generate the config html that would use the old one
        requirement = _redis_requirement()
        status = requirement.check_status(result.environ, local_state_file,
                                          'default', UserConfigOverrides())
        html = RedisProvider().config_html(requirement, result.environ,
                                           local_state_file,
                                           UserConfigOverrides(), status)
        assert 'Use the redis-server we started earlier' in html

        # now try again, and we should re-use the exact same server
        pidfile_mtime = os.path.getmtime(pidfile)
        with codecs.open(pidfile, 'r', 'utf-8') as file:
            pidfile_content = file.read()
        result2 = _prepare_printing_errors(project, environ=minimal_environ())
        assert result2

        # port should be the same, and set in the environment
        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(
                        result2.environ)

        # no new pid file
        assert pidfile_mtime == os.path.getmtime(pidfile)
        with codecs.open(pidfile, 'r', 'utf-8') as file:
            pidfile_content2 = file.read()
        assert pidfile_content == pidfile_content2

        # now clean it up
        status = unprepare(project, result2)
        assert status

        assert not os.path.exists(pidfile)
        assert not real_can_connect_to_socket(host='localhost', port=port)

        local_state_file.load()
        assert dict() == local_state_file.get_service_run_state("REDIS_URL")
Beispiel #6
0
 def prepare_empty(dirname):
     project = project_no_dedicated_env(dirname)
     environ = minimal_environ()
     result = prepare_without_interaction(project, environ=environ)
     assert result
     assert dict(PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
     assert dict() == strip_environ(environ)
     assert result.command_exec_info is None
Beispiel #7
0
 def prepare_empty(dirname):
     project = project_no_dedicated_env(dirname)
     environ = minimal_environ()
     result = prepare_without_interaction(project, environ=environ)
     assert result
     assert dict(PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
     assert dict() == strip_environ(environ)
     assert result.command_exec_info is None
Beispiel #8
0
    def start_local_redis(dirname):
        project = project_no_dedicated_env(dirname)
        result = _prepare_printing_errors(project, environ=minimal_environ())
        assert result
        assert 'REDIS_URL' in result.environ

        local_state_file = LocalStateFile.load_for_directory(dirname)
        state = local_state_file.get_service_run_state("REDIS_URL")
        assert 'port' in state
        port = state['port']

        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
        assert len(can_connect_args_list) >= 2

        pidfile = os.path.join(dirname, "services/REDIS_URL/redis.pid")
        logfile = os.path.join(dirname, "services/REDIS_URL/redis.log")
        assert os.path.exists(pidfile)
        assert os.path.exists(logfile)

        assert real_can_connect_to_socket(host='localhost', port=port)

        # be sure we generate the config html that would use the old one
        requirement = _redis_requirement()
        status = requirement.check_status(result.environ, local_state_file, 'default', UserConfigOverrides())
        html = RedisProvider().config_html(requirement, result.environ, local_state_file, UserConfigOverrides(), status)
        assert 'Use the redis-server we started earlier' in html

        # now try again, and we should re-use the exact same server
        pidfile_mtime = os.path.getmtime(pidfile)
        with codecs.open(pidfile, 'r', 'utf-8') as file:
            pidfile_content = file.read()
        result2 = _prepare_printing_errors(project, environ=minimal_environ())
        assert result2

        # port should be the same, and set in the environment
        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(result2.environ)

        # no new pid file
        assert pidfile_mtime == os.path.getmtime(pidfile)
        with codecs.open(pidfile, 'r', 'utf-8') as file:
            pidfile_content2 = file.read()
        assert pidfile_content == pidfile_content2

        # now clean it up
        status = unprepare(project, result2)
        assert status

        assert not os.path.exists(pidfile)
        assert not real_can_connect_to_socket(host='localhost', port=port)

        local_state_file.load()
        assert dict() == local_state_file.get_service_run_state("REDIS_URL")
Beispiel #9
0
    def start_local_redis(dirname):
        project = project_no_dedicated_env(dirname)
        result = test_redis_provider._prepare_printing_errors(project, environ=minimal_environ())
        assert result

        local_state_file = LocalStateFile.load_for_directory(dirname)
        state = local_state_file.get_service_run_state('REDIS_URL')
        assert 'port' in state
        port = state['port']

        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
        assert len(can_connect_args_list) >= 2

        pidfile = os.path.join(dirname, "services/REDIS_URL/redis.pid")
        logfile = os.path.join(dirname, "services/REDIS_URL/redis.log")
        assert os.path.exists(pidfile)
        assert os.path.exists(logfile)

        assert real_can_connect_to_socket(host='localhost', port=port)

        # now clean it up
        code = _parse_args_and_run_subcommand(['conda-kapsel', 'remove-service', 'REDIS_URL', '--directory', dirname])
        assert code == 0

        assert not os.path.exists(pidfile)
        assert not os.path.exists(os.path.join(dirname, "services"))
        assert not real_can_connect_to_socket(host='localhost', port=port)

        local_state_file.load()
        assert dict() == local_state_file.get_service_run_state("REDIS_URL")
Beispiel #10
0
 def prepare_redis_url(dirname):
     project = project_no_dedicated_env(dirname)
     result = _prepare_printing_errors(project, environ=minimal_environ())
     assert result
     assert dict(REDIS_URL="redis://localhost:6379",
                 PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
     assert dict(host='localhost', port=6379, timeout_seconds=0.5) == can_connect_args
Beispiel #11
0
    def prepare_then_update_environ(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(FOO='bar')
        result = prepare_without_interaction(project, environ=environ)
        assert result

        other = minimal_environ(BAR='baz')
        result.update_environ(other)
        assert dict(FOO='bar', BAR='baz', PROJECT_DIR=dirname) == strip_environ(other)
Beispiel #12
0
 def prepare_redis_url(dirname):
     project = project_no_dedicated_env(dirname)
     result = _prepare_printing_errors(project, environ=minimal_environ())
     assert result
     assert dict(REDIS_URL="redis://localhost:6379",
                 PROJECT_DIR=project.directory_path) == strip_environ(
                     result.environ)
     assert dict(host='localhost', port=6379,
                 timeout_seconds=0.5) == can_connect_args
Beispiel #13
0
    def prepare_then_update_environ(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(FOO='bar')
        result = prepare_without_interaction(project, environ=environ)
        assert result

        other = minimal_environ(BAR='baz')
        result.update_environ(other)
        assert dict(FOO='bar', BAR='baz', PROJECT_DIR=dirname) == strip_environ(other)
Beispiel #14
0
    def check(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(BAR='bar')
        result = prepare_with_browser_ui(project, environ=environ, keep_going_until_success=False)
        assert not result
        assert dict(BAR='bar') == strip_environ(environ)

        assert [('Icon file %s does not exist.' % os.path.join(dirname, 'foo.png')), 'Unable to load the project.'
                ] == result.errors
Beispiel #15
0
    def check(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(BAR='bar')
        result = prepare_with_browser_ui(project, environ=environ, keep_going_until_success=False)
        assert not result
        assert dict(BAR='bar') == strip_environ(environ)

        assert [('Icon file %s does not exist.' % os.path.join(dirname, 'foo.png')), 'Unable to load the project.'
                ] == result.errors
Beispiel #16
0
    def prepare_with_browser(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(BAR='bar')
        result = prepare_with_browser_ui(project, environ=environ, keep_going_until_success=False, io_loop=io_loop)
        assert not result
        assert dict(BAR='bar') == strip_environ(environ)

        # wait for the results of the POST to come back,
        # awesome hack-tacular
        while 'post' not in http_results:
            io_loop.call_later(0.01, lambda: io_loop.stop())
            io_loop.start()

        assert 'get' in http_results
        assert 'post' in http_results

        assert 200 == http_results['get'].code
        assert 200 == http_results['post'].code
Beispiel #17
0
    def prepare_with_browser(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(BAR='bar')
        result = prepare_with_browser_ui(project, environ=environ, keep_going_until_success=False, io_loop=io_loop)
        assert not result
        assert dict(BAR='bar') == strip_environ(environ)

        # wait for the results of the POST to come back,
        # awesome hack-tacular
        while 'post' not in http_results:
            io_loop.call_later(0.01, lambda: io_loop.stop())
            io_loop.start()

        assert 'get' in http_results
        assert 'post' in http_results

        assert 200 == http_results['get'].code
        assert 200 == http_results['post'].code
Beispiel #18
0
    def prepare_some_env_var_keep_going(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(BAR='bar')
        stage = prepare_in_stages(project, environ=environ, keep_going_until_success=True)

        # there's an initial stage to set the conda env
        next_stage = stage.execute()
        assert not stage.failed
        assert stage.environ['PROJECT_DIR'] == dirname
        stage = next_stage

        for i in range(1, 10):
            next_stage = stage.execute()
            assert next_stage is not None
            assert stage.failed
            assert stage.environ['PROJECT_DIR'] == dirname
            stage = next_stage
        assert dict(BAR='bar') == strip_environ(environ)
Beispiel #19
0
    def prepare_some_env_var_keep_going(dirname):
        project = project_no_dedicated_env(dirname)
        environ = minimal_environ(BAR='bar')
        stage = prepare_in_stages(project, environ=environ, keep_going_until_success=True)

        # there's an initial stage to set the conda env
        next_stage = stage.execute()
        assert not stage.failed
        assert stage.environ['PROJECT_DIR'] == dirname
        stage = next_stage

        for i in range(1, 10):
            next_stage = stage.execute()
            assert next_stage is not None
            assert stage.failed
            assert stage.environ['PROJECT_DIR'] == dirname
            stage = next_stage
        assert dict(BAR='bar') == strip_environ(environ)
Beispiel #20
0
 def prepare_system_environ(dirname):
     project = project_no_dedicated_env(dirname)
     os_environ_copy = deepcopy(os.environ)
     result = prepare_without_interaction(project)
     assert project.directory_path == strip_environ(result.environ)['PROJECT_DIR']
     # os.environ wasn't modified
     assert os_environ_copy == os.environ
     # result.environ inherits everything in os.environ
     for key in os_environ_copy:
         if key == 'PATH' and platform.system() == 'Windows' and result.environ[key] != os.environ[key]:
             print("prepare changed PATH on Windows and ideally it would not.")
         else:
             if key == 'PATH' and result.environ[key] != os.environ[key]:
                 original = os.environ[key].split(os.pathsep)
                 updated = result.environ[key].split(os.pathsep)
                 print("ORIGINAL PATH: " + repr(original))
                 print("UPDATED PATH: " + repr(updated))
                 assert original == updated
             assert result.environ.get(key) == os.environ.get(key)
Beispiel #21
0
 def prepare_system_environ(dirname):
     project = project_no_dedicated_env(dirname)
     os_environ_copy = deepcopy(os.environ)
     result = prepare_without_interaction(project)
     assert project.directory_path == strip_environ(result.environ)['PROJECT_DIR']
     # os.environ wasn't modified
     assert os_environ_copy == os.environ
     # result.environ inherits everything in os.environ
     for key in os_environ_copy:
         if key == 'PATH' and platform.system() == 'Windows' and result.environ[key] != os.environ[key]:
             print("prepare changed PATH on Windows and ideally it would not.")
         else:
             if key == 'PATH' and result.environ[key] != os.environ[key]:
                 original = os.environ[key].split(os.pathsep)
                 updated = result.environ[key].split(os.pathsep)
                 print("ORIGINAL PATH: " + repr(original))
                 print("UPDATED PATH: " + repr(updated))
                 assert original == updated
             assert result.environ.get(key) == os.environ.get(key)
Beispiel #22
0
    def start_local_redis(dirname):
        project = project_no_dedicated_env(dirname)
        result = _prepare_printing_errors(project, environ=minimal_environ())
        assert result

        local_state_file = LocalStateFile.load_for_directory(dirname)
        state = local_state_file.get_service_run_state('REDIS_URL')
        assert 'port' in state
        port = state['port']

        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(
                        result.environ)
        assert len(can_connect_args_list) >= 2

        servicedir = os.path.join(dirname, "services")
        redisdir = os.path.join(servicedir, "REDIS_URL")

        pidfile = os.path.join(redisdir, "redis.pid")
        logfile = os.path.join(redisdir, "redis.log")
        assert os.path.exists(pidfile)
        assert os.path.exists(logfile)

        assert real_can_connect_to_socket(host='localhost', port=port)

        # now clean it up
        status = unprepare(project, result)
        assert status

        assert not os.path.exists(pidfile)
        assert not os.path.exists(logfile)
        assert not os.path.exists(redisdir)
        assert not os.path.exists(servicedir)
        assert not real_can_connect_to_socket(host='localhost', port=port)

        local_state_file.load()
        assert dict() == local_state_file.get_service_run_state("REDIS_URL")
Beispiel #23
0
    def start_local_redis(dirname):
        project = project_no_dedicated_env(dirname)
        result = _prepare_printing_errors(project, environ=minimal_environ())
        assert result

        local_state_file = LocalStateFile.load_for_directory(dirname)
        state = local_state_file.get_service_run_state('REDIS_URL')
        assert 'port' in state
        port = state['port']

        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
        assert len(can_connect_args_list) >= 2

        servicedir = os.path.join(dirname, "services")
        redisdir = os.path.join(servicedir, "REDIS_URL")

        pidfile = os.path.join(redisdir, "redis.pid")
        logfile = os.path.join(redisdir, "redis.log")
        assert os.path.exists(pidfile)
        assert os.path.exists(logfile)

        assert real_can_connect_to_socket(host='localhost', port=port)

        # now clean it up
        status = unprepare(project, result)
        assert status

        assert not os.path.exists(pidfile)
        assert not os.path.exists(logfile)
        assert not os.path.exists(redisdir)
        assert not os.path.exists(servicedir)
        assert not real_can_connect_to_socket(host='localhost', port=port)

        local_state_file.load()
        assert dict() == local_state_file.get_service_run_state("REDIS_URL")
Beispiel #24
0
    def start_local_redis(dirname):
        project = project_no_dedicated_env(dirname)
        result = test_redis_provider._prepare_printing_errors(
            project, environ=minimal_environ())
        assert result

        local_state_file = LocalStateFile.load_for_directory(dirname)
        state = local_state_file.get_service_run_state('REDIS_URL')
        assert 'port' in state
        port = state['port']

        assert dict(REDIS_URL=("redis://localhost:" + str(port)),
                    PROJECT_DIR=project.directory_path) == strip_environ(
                        result.environ)
        assert len(can_connect_args_list) >= 2

        pidfile = os.path.join(dirname, "services/REDIS_URL/redis.pid")
        logfile = os.path.join(dirname, "services/REDIS_URL/redis.log")
        assert os.path.exists(pidfile)
        assert os.path.exists(logfile)

        assert real_can_connect_to_socket(host='localhost', port=port)

        # now clean it up
        code = _parse_args_and_run_subcommand([
            'conda-kapsel', 'remove-service', 'REDIS_URL', '--directory',
            dirname
        ])
        assert code == 0

        assert not os.path.exists(pidfile)
        assert not os.path.exists(os.path.join(dirname, "services"))
        assert not real_can_connect_to_socket(host='localhost', port=port)

        local_state_file.load()
        assert dict() == local_state_file.get_service_run_state("REDIS_URL")
Beispiel #25
0
    def prepare_after_setting_scope(dirname):
        local_state = LocalStateFile.load_for_directory(dirname)
        requirement = _redis_requirement()
        provider = RedisProvider()
        environ = minimal_environ()
        config = provider.read_config(requirement, environ, local_state,
                                      'default', UserConfigOverrides())
        assert config['source'] == 'find_all'
        provider.set_config_values_as_strings(requirement, environ,
                                              local_state, 'default',
                                              UserConfigOverrides(),
                                              dict(source='find_project'))
        config = provider.read_config(requirement, environ, local_state,
                                      'default', UserConfigOverrides())
        assert config['source'] == 'find_project'
        provider.set_config_values_as_strings(requirement, environ,
                                              local_state, 'default',
                                              UserConfigOverrides(),
                                              dict(source='find_all'))
        config = provider.read_config(requirement, environ, local_state,
                                      'default', UserConfigOverrides())
        assert config['source'] == 'find_all'
        provider.set_config_values_as_strings(requirement, environ,
                                              local_state, 'default',
                                              UserConfigOverrides(),
                                              dict(source='environ'))
        config = provider.read_config(requirement, environ, local_state,
                                      'default', UserConfigOverrides())
        assert config['source'] == 'find_all'  # default if no env var set
        provider.set_config_values_as_strings(requirement, environ,
                                              local_state, 'default',
                                              UserConfigOverrides(),
                                              dict(source='environ'))
        environ_with_redis_url = environ.copy()
        environ_with_redis_url['REDIS_URL'] = 'blah'
        config = provider.read_config(requirement, environ_with_redis_url,
                                      local_state, 'default',
                                      UserConfigOverrides())
        assert config['source'] == 'environ'  # default when the env var IS set

        # use local variable when env var not set
        provider.set_config_values_as_strings(
            requirement, environ, local_state, 'default',
            UserConfigOverrides(), dict(source='variables', value='foo'))
        config = provider.read_config(requirement, environ, local_state,
                                      'default', UserConfigOverrides())
        assert config['source'] == 'variables'
        assert config['value'] == 'foo'

        # use local variable when env var _is_ set
        provider.set_config_values_as_strings(
            requirement, environ_with_redis_url, local_state, 'default',
            UserConfigOverrides(), dict(source='variables', value='foo'))
        config = provider.read_config(requirement, environ, local_state,
                                      'default', UserConfigOverrides())
        assert config['source'] == 'variables'
        assert config['value'] == 'foo'

        # set to use system, which should override using the local state
        provider.set_config_values_as_strings(requirement, environ,
                                              local_state, 'default',
                                              UserConfigOverrides(),
                                              dict(source='find_system'))
        config = provider.read_config(requirement, environ, local_state,
                                      'default', UserConfigOverrides())
        assert config['source'] == 'find_system'

        project = project_no_dedicated_env(dirname)
        result = _prepare_printing_errors(project, environ=minimal_environ())
        assert result
        assert dict(REDIS_URL="redis://localhost:6379",
                    PROJECT_DIR=project.directory_path) == strip_environ(
                        result.environ)
        assert dict(host='localhost', port=6379,
                    timeout_seconds=0.5) == can_connect_args
Beispiel #26
0
    def prepare_after_setting_scope(dirname):
        local_state = LocalStateFile.load_for_directory(dirname)
        requirement = _redis_requirement()
        provider = RedisProvider()
        environ = minimal_environ()
        config = provider.read_config(requirement, environ, local_state, 'default', UserConfigOverrides())
        assert config['source'] == 'find_all'
        provider.set_config_values_as_strings(requirement,
                                              environ,
                                              local_state,
                                              'default',
                                              UserConfigOverrides(),
                                              dict(source='find_project'))
        config = provider.read_config(requirement, environ, local_state, 'default', UserConfigOverrides())
        assert config['source'] == 'find_project'
        provider.set_config_values_as_strings(requirement,
                                              environ,
                                              local_state,
                                              'default',
                                              UserConfigOverrides(),
                                              dict(source='find_all'))
        config = provider.read_config(requirement, environ, local_state, 'default', UserConfigOverrides())
        assert config['source'] == 'find_all'
        provider.set_config_values_as_strings(requirement,
                                              environ,
                                              local_state,
                                              'default',
                                              UserConfigOverrides(),
                                              dict(source='environ'))
        config = provider.read_config(requirement, environ, local_state, 'default', UserConfigOverrides())
        assert config['source'] == 'find_all'  # default if no env var set
        provider.set_config_values_as_strings(requirement,
                                              environ,
                                              local_state,
                                              'default',
                                              UserConfigOverrides(),
                                              dict(source='environ'))
        environ_with_redis_url = environ.copy()
        environ_with_redis_url['REDIS_URL'] = 'blah'
        config = provider.read_config(requirement, environ_with_redis_url, local_state, 'default',
                                      UserConfigOverrides())
        assert config['source'] == 'environ'  # default when the env var IS set

        # use local variable when env var not set
        provider.set_config_values_as_strings(requirement,
                                              environ,
                                              local_state,
                                              'default',
                                              UserConfigOverrides(),
                                              dict(source='variables',
                                                   value='foo'))
        config = provider.read_config(requirement, environ, local_state, 'default', UserConfigOverrides())
        assert config['source'] == 'variables'
        assert config['value'] == 'foo'

        # use local variable when env var _is_ set
        provider.set_config_values_as_strings(requirement,
                                              environ_with_redis_url,
                                              local_state,
                                              'default',
                                              UserConfigOverrides(),
                                              dict(source='variables',
                                                   value='foo'))
        config = provider.read_config(requirement, environ, local_state, 'default', UserConfigOverrides())
        assert config['source'] == 'variables'
        assert config['value'] == 'foo'

        # set to use system, which should override using the local state
        provider.set_config_values_as_strings(requirement,
                                              environ,
                                              local_state,
                                              'default',
                                              UserConfigOverrides(),
                                              dict(source='find_system'))
        config = provider.read_config(requirement, environ, local_state, 'default', UserConfigOverrides())
        assert config['source'] == 'find_system'

        project = project_no_dedicated_env(dirname)
        result = _prepare_printing_errors(project, environ=minimal_environ())
        assert result
        assert dict(REDIS_URL="redis://localhost:6379",
                    PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
        assert dict(host='localhost', port=6379, timeout_seconds=0.5) == can_connect_args
Beispiel #27
0
 def final_result_check(dirname, result):
     assert result
     expected = dict(MYDOWNLOAD=os.path.join(dirname, 'existing_data'), PROJECT_DIR=dirname)
     assert expected == strip_environ(result.environ)
Beispiel #28
0
 def prepare_some_env_var(dirname):
     project = project_no_dedicated_env(dirname)
     environ = minimal_environ(BAR='bar')
     result = prepare_without_interaction(project, environ=environ)
     assert not result
     assert dict(BAR='bar') == strip_environ(environ)
Beispiel #29
0
 def prepare_some_env_var(dirname):
     project = project_no_dedicated_env(dirname)
     environ = minimal_environ(BAR='bar')
     result = prepare_without_interaction(project, environ=environ)
     assert not result
     assert dict(BAR='bar') == strip_environ(environ)