コード例 #1
0
def test_approve(monkeypatch):
    msg = Fake({
        "_client": {
            "host": "stackexchange.com",
        },
        "id": 88888888,
        "owner": {
            "name": "ArtOfCode",
            "id": 121520
        },
        "room": {
            "id": 11540,
            "name": "Continuous Integration",
            "_client": None
        },
        "content_source": '!!/approve 8888',
    })
    msg.room._client = msg._client

    # Prevent from attempting to check privileges with Metasmoke
    monkeypatch.setattr(GlobalVars, "code_privileged_users", [])
    assert chatcommands.approve(
        8888, original_msg=msg).startswith("You need code privileges")

    monkeypatch.setattr(GlobalVars, "code_privileged_users",
                        [('stackexchange.com', 121520)])
    with monkeypatch.context() as m:
        # Oh no GitHub is down
        m.setattr("requests.get", lambda *args, **kwargs: None)
        assert chatcommands.approve(
            8888, original_msg=msg) == "Cannot connect to GitHub API"
    assert chatcommands.approve(
        2518, original_msg=msg).startswith("PR #2518 is not created by me")
コード例 #2
0
def test_approve(monkeypatch):
    msg = Fake({
        "_client": {
            "host": "stackexchange.com",
        },
        "id": 88888888,
        "owner": {"name": "ArtOfCode", "id": 121520},
        "room": {"id": 11540, "name": "Continuous Integration", "_client": None},
        "content_source": '!!/approve 8888',
    })
    msg.room._client = msg._client

    # Prevent from attempting to check privileges with Metasmoke
    monkeypatch.setattr(GlobalVars, "code_privileged_users", [])
    assert chatcommands.approve(8888, original_msg=msg).startswith("You need code privileges")

    monkeypatch.setattr(GlobalVars, "code_privileged_users", [('stackexchange.com', 121520)])
    with monkeypatch.context() as m:
        # Oh no GitHub is down
        original_get = requests.get
        m.setattr("requests.get", lambda *args, **kwargs: None)
        assert chatcommands.approve(8888, original_msg=msg) == "Cannot connect to GitHub API"
        m.setattr("requests.get", original_get)
    assert chatcommands.approve(2518, original_msg=msg)[:8] in {"PR #2518", "Cannot c"}