Exemplo n.º 1
0
def test_create_config_add_token(utils):
    cfg = helpers.create_config(utils.config('basic_config'), 'MY_TOKEN')
    assert cfg['github']['token'] == 'MY_TOKEN'

    cfg = helpers.create_config(utils.config('config_without_token'),
                                'MY_TOKEN')
    assert cfg['github']['token'] == 'MY_TOKEN'
Exemplo n.º 2
0
def test_extract_repos(utils):
    cfg = helpers.create_config(utils.config('repos'))
    repos = helpers.extract_repos(cfg)
    assert len(repos) == 3
    assert 'user/repo' in repos
    assert 'user/repo3' in repos
    assert 'user2/repo' in repos
Exemplo n.º 3
0
 def create_app(config=None, github=None):
     cfg = config or create_config(token=os.getenv('GITHUB_TOKEN', None),
                                   config_filename=os.getenv(
                                       'LABELORD_CONFIG', None))
     gh = github or GitHub('')  # dummy, but will be checked later
     gh.token = cfg.get('github', 'token', fallback='')
     return LabelordWeb(cfg, gh, import_name=__name__)
Exemplo n.º 4
0
 def reload_config(self):
     config_filename = os.environ.get('LABELORD_CONFIG', None)
     self.labelord_config = create_config(token=os.getenv(
         'GITHUB_TOKEN', None),
                                          config_filename=config_filename)
     self._check_config()
     self.github.token = self.labelord_config.get('github', 'token')
Exemplo n.º 5
0
def test_extract_repos_no_repo(utils, capsys):
    cfg = helpers.create_config(utils.config('no_repo'))
    with pytest.raises(SystemExit) as e:
        helpers.extract_repos(cfg)
    assert e.value.code == 7
    out, err = capsys.readouterr()
    assert out == ''
    assert err == 'No repositories specification has been found\n'
Exemplo n.º 6
0
def cli(ctx, config, token):
    ctx.obj['config'] = create_config(config, token)
    ctx.obj['config'].optionxform = str
    if token is not None:
        ctx.obj['config'].read_dict({'github': {'token': token}})
    if ctx.obj['config'].has_option('github', 'token'):
        session = ctx.obj.get('session', requests.Session())
        ctx.obj['GitHub'] = GitHub(ctx.obj['config'].get('github', 'token'),
                                   session)
Exemplo n.º 7
0
def test_create_config(utils):
    cfg = helpers.create_config(utils.config('basic_config'))
    assert len(cfg.sections()) == 4
    assert 'github' in cfg
    assert 'labels' in cfg
    assert 'repos' in cfg
    assert 'others' in cfg
    assert cfg['github']['token'] == 'MY_SECRET_TOKEN'
    assert cfg['github']['webhook_secret'] == 'WEBHOOK_SECRET_TOKEN'
    assert cfg['labels']['Test'] == 'FF0000'
    assert cfg.getboolean('repos', 'user/repo') is True
    assert cfg.getboolean('repos', 'user/repo2') is False
    assert cfg['others']['template-repo'] == 'user/repo'
Exemplo n.º 8
0
def test_create_config_nonexisting_cfg(utils):
    cfg = helpers.create_config(utils.config('nonexisting_config'))
    assert len(cfg.sections()) == 0