def test_event_and_action_functions_called(app, mocker):
    github_app = GitHubApp(app)
    event_function = MagicMock()
    event_action_function = MagicMock()
    other_event_function = MagicMock()
    github_app._hook_mappings = {
        'foo': [event_function],
        'foo.bar': [event_action_function],
        'bar': [other_event_function]
    }
    mocker.patch('flask_githubapp.core.GitHubApp._verify_webhook')
    with app.test_client() as client:
        resp = client.post('/',
                           data=json.dumps({
                               'installation': {
                                   'id': 2
                               },
                               'action': 'bar'
                           }),
                           headers={
                               'X-GitHub-Event': 'foo',
                               'Content-Type': 'application/json'
                           })
        assert resp.status_code == 200
        event_function.assert_called_once_with()
        event_action_function.assert_called_once_with()
        other_event_function.assert_not_called()
Beispiel #2
0
def test_view_returns_map_of_called_functions_and_returned_data(app, mocker):
    github_app = GitHubApp(app)

    def event_function():
        return 'foo'

    def event_action_function():
        return 'bar'

    def other_event_function():
        return 'baz'

    github_app._hook_mappings = {
        'foo': [event_function],
        'foo.bar': [event_action_function],
        'bar': [other_event_function]
    }
    mocker.patch('flask_githubapp.core.GitHubApp._verify_webhook')
    with app.test_client() as client:
        resp = client.post('/',
                           data=json.dumps({
                               'installation': {
                                   'id': 2
                               },
                               'action': 'bar'
                           }),
                           headers={
                               'X-GitHub-Event': 'foo',
                               'Content-Type': 'application/json'
                           })
        assert resp.status_code == 200
        assert resp.json == {
            'status': 'HIT',
            'calls': {
                'event_function': 'foo',
                'event_action_function': 'bar',
            }
        }