def test_single_issue_error(prepare_session, capsys): rules = validate_rules(None, None, make_path("rules.valid.cfg")) process_repository("ghia-anna/awesome", "append", prepare_session, rules, False) out, err = capsys.readouterr() assert "-> ghia-anna/awesome#1 (https://github.com/ghia-anna/awesome/issues/1)" in out assert " ERROR: Could not update issue ghia-anna/awesome#1" in err
def test_reading_issues_error(prepare_session): rules = validate_rules(None, None, make_path("rules.empty.cfg")) with pytest.raises(GhiaError) as e: process_repository("mi-pyt-ghia/kotlalu", "append", prepare_session, rules, False) assert str( e.value) == "Could not list issues for repository mi-pyt-ghia/kotlalu"
def test_apply_rules(prepare_session, capsys): rules = validate_rules(None, None, make_path("rules.valid.cfg")) process_repository("mi-pyt-ghia/kotlaluk", "append", prepare_session, rules, False) out, err = capsys.readouterr() assert len(err) == 0 assert '-> mi-pyt-ghia/kotlaluk#5 (https://github.com/mi-pyt-ghia/kotlaluk/issues/5)\n' \ ' = ghia-anna\n' in out assert '-> mi-pyt-ghia/kotlaluk#7 (https://github.com/mi-pyt-ghia/kotlaluk/issues/7)\n' \ ' = ghia-anna\n' \ ' = ghia-john\n' \ ' + ghia-peter\n' in out assert '-> mi-pyt-ghia/kotlaluk#8 (https://github.com/mi-pyt-ghia/kotlaluk/issues/8)\n' \ ' = ghia-anna\n' \ ' = ghia-peter\n' in out assert '-> mi-pyt-ghia/kotlaluk#24 (https://github.com/mi-pyt-ghia/kotlaluk/issues/24)\n' \ ' = ghia-anna\n' in out assert '-> mi-pyt-ghia/kotlaluk#27 (https://github.com/mi-pyt-ghia/kotlaluk/issues/27)\n' \ ' + ghia-peter\n' in out assert '-> mi-pyt-ghia/kotlaluk#117 (https://github.com/mi-pyt-ghia/kotlaluk/issues/117)\n' \ ' = ghia-anna\n' in out assert '-> mi-pyt-ghia/kotlaluk#118 (https://github.com/mi-pyt-ghia/kotlaluk/issues/118)\n' \ ' = ghia-peter\n' in out assert ' FALLBACK:' in out
def test_reading_issues(prepare_session, capsys): """Tests that all issue pages are read""" rules = validate_rules(None, None, make_path("rules.empty.cfg")) process_repository("mi-pyt-ghia/kotlaluk", "append", prepare_session, rules, False) out, err = capsys.readouterr() assert len(err) == 0 assert "-> mi-pyt-ghia/kotlaluk#1 (https://github.com/mi-pyt-ghia/kotlaluk/issues/1)" in out assert "-> mi-pyt-ghia/kotlaluk#120 (https://github.com/mi-pyt-ghia/kotlaluk/issues/120)" in out
def test_invalid_rules(file): with pytest.raises(BadParameter) as e: validate_rules(ctx, param, make_path(file)) assert str(e.value) == "incorrect configuration format"
def test_rules_with_fallback(): d = validate_rules(ctx, param, make_path("rules.fallback.cfg")) assert d["fallback"] == "Need assignment" assert len(d) == 1
def test_rules_valid(): d = validate_rules(ctx, param, make_path("rules.valid.cfg")) assert "fallback" in d.keys() assert "title" in d["ghia-anna"].keys() assert re.match(d["ghia-john"]["label"][0], "assign-john") assert len(d["ghia-peter"]["any"]) == 2
def test_rules_empty(): d = validate_rules(ctx, param, make_path("rules.empty.cfg")) assert type(d) == dict assert len(d) == 0
def test_auth_with_secret(): auth = validate_auth(ctx, param, make_path("auth.secret.cfg")) assert auth["token"] == "ffffffffffffffffffffffffffffffffffffffff" assert auth["secret"] == "tajneheslo"
def test_auth_basic(): auth = validate_auth(ctx, param, make_path("auth.basic.cfg")) assert auth["token"] == "ffffffffffffffffffffffffffffffffffffffff"
def test_reset_rules(prepare_session, capsys): rules = validate_rules(None, None, make_path("rules.reset.cfg")) process_repository("mi-pyt-ghia/kotlaluk", "change", prepare_session, rules, False) out, err = capsys.readouterr() assert len(err) == 0
# Read auth from GHIA_CONFIG try: BETAMAX_RECORD = os.environ["BETAMAX_RECORD"] if BETAMAX_RECORD == "1": TOKEN = os.environ["GITHUB_TOKEN"] config.default_cassette_options["record_mode"] = "all" else: raise KeyError except Exception: TOKEN = "false_token" # Do not attempt to record sessions with bad fake token config.default_cassette_options["record_mode"] = "none" # Hide the token in the cassettes config.define_cassette_placeholder("<TOKEN>", TOKEN) config.cassette_library_dir = make_path("cassettes") @pytest.fixture def prepare_session(betamax_session): betamax_session.headers.update({'Accept-Encoding': 'identity'}) betamax_session.headers.update({'Authorization': 'token ' + TOKEN}) return betamax_session def test_no_reposlug(): runner = CliRunner() result = runner.invoke(cli, [ '-r', f'{make_path("rules.empty.cfg")}', '-a', f'{make_path("auth.basic.cfg")}' ])