def test_default_uses_path(config_file):
    cfg = Config.default(path=config_file, environment={})
    assert cfg.apiUrl == 'file api url'
    assert cfg.ciBuildId == 'file ci build id'
    assert cfg.branchName == 'file branch name'
    assert cfg.project == 'file project'
    assert cfg.apiKey == 'file api key'
    assert cfg.enableSoftAssert == True
def test_default_uses_defaults(config_env, mocker):
    mocker.patch('os.path.isfile').return_value = False
    del config_env['VRT_CIBUILDID']
    del config_env['VRT_APIURL']

    cfg = Config.default(environment=config_env)
    assert cfg.apiUrl == Config.apiUrl
    assert cfg.ciBuildId is None
def test_default_uses_environment(config_env, mocker):
    mocker.patch('os.path.isfile').return_value = False

    cfg = Config.default(environment=config_env)
    assert cfg.apiUrl == 'env api url'
    assert cfg.ciBuildId == 'env ci build id'
    assert cfg.branchName == 'env branch name'
    assert cfg.project == 'env project'
    assert cfg.apiKey == 'env api key'
    assert cfg.enableSoftAssert == False
def test_default_uses_default_path(mocker, config_file):
    config_file_data = open(config_file).read()
    mocker.patch('builtins.open', mocker.mock_open(read_data=config_file_data))
    mocker.patch('os.path.isfile').return_value = True

    cfg = Config.default(environment={})
    assert cfg.apiUrl == 'file api url'
    assert cfg.ciBuildId == 'file ci build id'
    assert cfg.branchName == 'file branch name'
    assert cfg.project == 'file project'
    assert cfg.apiKey == 'file api key'
    assert cfg.enableSoftAssert == True
def test_default_raises_on_missing_settings(mocker, config_env, missing_field):
    mocker.patch('os.path.isfile').return_value = False
    del config_env[ENV_MAPPING[missing_field]]

    with pytest.raises(MissingConfigurationError):
        Config.default(environment=config_env)
def test_default_raises_on_invalid_path():
    with pytest.raises(IOError):
        Config.default(path='/does/not/exist/vrt.json')
def test_default_prefers_environment(config_env, config_file):
    del config_env['VRT_PROJECT']
    cfg = Config.default(path=config_file, environment=config_env)
    assert cfg.ciBuildId == 'env ci build id'
    assert cfg.project == 'file project'