async def test_get_comment(opsdroid):
    """Test a comment create event creates a message and parses it."""
    opsdroid = amock.CoroutineMock()
    connector = ConnectorGitHub({
        "name": "github",
        "token": "test"
    },
                                opsdroid=opsdroid)
    with open(
            os.path.join(os.path.dirname(__file__), "responses",
                         "github_comment_payload.json"),
            "r",
    ) as f:
        mock_request = amock.CoroutineMock()
        mock_request.post = amock.CoroutineMock(
            return_value={"payload": f.read()})
        connector.opsdroid = amock.CoroutineMock()
        connector.opsdroid.parse = amock.CoroutineMock()
        await connector.github_message_handler(mock_request)

        message = connector.opsdroid.parse.call_args[0][0]

        assert message.connector.name == "github"
        assert message.text == "hello"
        assert message.target == "opsdroid/opsdroid#237"
        assert connector.opsdroid.parse.called
Exemple #2
0
async def test_get_no_action(opsdroid):
    """Test a status event doesn't create a message and parse it."""
    opsdroid = amock.CoroutineMock()
    connector = ConnectorGitHub({"name": "github", "token": "test"}, opsdroid=opsdroid)

    with open(
        os.path.join(
            os.path.dirname(__file__), "responses", "github_status_payload.json"
        ),
        "r",
    ) as f:
        mock_request = amock.CoroutineMock()
        mock_request.post = amock.CoroutineMock(return_value={"payload": f.read()})
        connector.opsdroid = amock.CoroutineMock()
        connector.opsdroid.parse = amock.CoroutineMock()
        await connector.github_message_handler(mock_request)
        assert not connector.opsdroid.parse.called