Skip to content

Commit

Permalink
Merge ecc129e into 172c827
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole Thomas committed Sep 11, 2018
2 parents 172c827 + ecc129e commit ca65c59
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tamarack/event_processor.py
Expand Up @@ -62,7 +62,7 @@ def handle_pull_request(event_data, token):
# Assign reviewers on "opened" PRs, as applicable.
if action == 'opened':
# Skip Merge Forward PRs
if 'Merge forward' in event_data.get('pull_request').get('title', ''):
if 'Merge forward' in event_data.get('pull_request', {}).get('title', ''):
LOG.info('PR #%s: Skipping. PR is a merge-forward. Reviewers are not '
'assigned to merge-forward PRs via Tamarack.', pr_num)
return
Expand Down
74 changes: 74 additions & 0 deletions tests/test_event_processor.py
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
'''
Tests for the functions in tamarack.event_processor.py
'''

# Import Python libs
import os
import pytest

# Import Tornado libs
import tornado.testing
import tornado.web

# Import Tamarack libs
import tamarack.event_processor

GITHUB_TEST_TOKEN = os.environ.get('GITHUB_TEST_TOKEN') or ''


class TestHandleEvent(tornado.testing.AsyncTestCase):
'''
TestCase for the handle_event function
'''

@tornado.testing.gen_test
def test_pull_request_event(self):
'''
Tests that a pull request event is handled
'''
event_data = {'number': 1,
'action': 'foo'}
ret = yield tamarack.event_processor.handle_event(event_data, '')
assert ret is None


class TestHandlePullRequest(tornado.testing.AsyncTestCase):
'''
TestCase for the handle_pull_request function
'''

@tornado.testing.gen_test
def test_opened_pr(self):
'''
Tests that an opened pull request calls out to assign reviewers
'''
event_data = {'number': 1,
'action': 'opened',
'pull_request': {}}
# PR #1 doesn't exist, so asserting against an HTTPError here is a fine way to
# go without actually assigning a reviewer to a PR.
with pytest.raises(tornado.web.HTTPError, message='Expecting a 500 Error from GitHub'):
yield tamarack.event_processor.handle_pull_request(event_data, GITHUB_TEST_TOKEN)

@tornado.testing.gen_test
def test_merge_forward(self):
'''
Tests that an opened pull request that contains "Merge forward" in the
title is ignored.
'''
event_data = {'number': 1,
'action': 'opened',
'pull_request': {'title': '[2018.3] Merge forward from 2017.7 to 2018.3'}}
ret = yield tamarack.event_processor.handle_pull_request(event_data, '')
assert ret is None

@tornado.testing.gen_test
def test_unknown_event(self):
'''
Tests that events other than "opened" are ignored.
'''
event_data = {'number': 1,
'action': 'foo'}
ret = yield tamarack.event_processor.handle_pull_request(event_data, '')
assert ret is None

0 comments on commit ca65c59

Please sign in to comment.