Exemple #1
0
def test_bisect():
    chatcommunicate.parse_room_config("test/test_rooms.yml")
    msg = Fake({
        "owner": {
            "name": "ArtOfCode",
            "id": 121520,
            "is_moderator": True
        },
        "room": {
            "_client": {
                "host": "stackexchange.com"
            },
            "id": 11540
        },
        "content_source": None
    })
    msg.content_source = "!!/bisect :::essayssos.com:::"
    assert chatcommands.bisect(
        None, original_msg=msg
    ) == r"Matched by `essayssos\.com` on [line 1 of watched_keywords.txt](https://github.com/{}/blob/{}/watched_keywords.txt#L1)".format(
        GlobalVars.bot_repo_slug, GlobalVars.commit.id)
    msg.content_source = "!!/bisect OoOasdfghjklOoO"
    assert chatcommands.bisect(
        None, original_msg=msg
    ) == r"'OoOasdfghjklOoO' is not caught by a blacklist or watchlist item."
def test_bisect(command, test_text, expected_result):
    chatcommunicate.parse_room_config("test/test_rooms.yml")
    msg = Fake({
        "owner": {
            "name": "ArtOfCode",
            "id": 121520,
            "is_moderator": True
        },
        "room": {
            "_client": {
                "host": "stackexchange.com"
            },
            "id": 11540
        },
        "content_source": None
    })

    msg.content_source = "!!/{} {}".format(command, test_text)
    print('command:', command)
    print('test_text:', test_text)
    msg.content = msg.content_source
    # All of the substitution references used in the .format() for the expected result are named. Any which are numbers are
    # part of the expected results.
    expected_result = regex.sub(r"(\{\d+(?:,\d+)?\})", r'{\1}',
                                expected_result)
    formatted_expected_result = expected_result.format(
        test_text=test_text,
        bot_repo_slug=GlobalVars.bot_repo_slug,
        commit_id=GlobalVars.commit.id)
    chat_command = getattr(chatcommands, command)
    result = chat_command(None, original_msg=msg)
    print('formatted_expected_result:', formatted_expected_result)
    print('                   result:', result)
    assert result == formatted_expected_result
def test_bisect():
    chatcommunicate.parse_room_config("test/test_rooms.yml")
    msg = Fake({
        "owner": {
            "name": "ArtOfCode",
            "id": 121520,
            "is_moderator": True
        },
        "room": {
            "_client": {
                "host": "stackexchange.com"
            },
            "id": 11540
        },
        "content_source": None
    })
    msg.content_source = "!!/bisect :::essayssos.com:::"
    assert chatcommands.bisect(None, original_msg=msg) == r"Matched by `essayssos\.com` on [line 1 of watched_keywords.txt](https://github.com/Charcoal-SE/SmokeDetector/blob/{}/watched_keywords.txt#L1)".format(GlobalVars.commit.id)
    msg.content_source = "!!/bisect OoOasdfghjklOoO"
    assert chatcommands.bisect(None, original_msg=msg) == r"'OoOasdfghjklOoO' is not caught by a blacklist or watchlist item."