Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 6586897

Browse files
authored
Merge pull request #148 from davidalber/run-func-tests
Adding tests for run function
2 parents 15408f8 + 5d6b04f commit 6586897

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

highfive/tests/test_newpr.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,3 +1237,55 @@ def test_with_dirs_no_intersection(self):
12371237
)
12381238
self.assertEqual(set(["pnkfelix", "nrc"]), chosen_reviewers)
12391239
self.assertEqual(set([()]), mentions)
1240+
1241+
class TestRun(TestNewPR):
1242+
def setUp(self):
1243+
super(TestRun, self).setUp()
1244+
1245+
self.patchers = {
1246+
'ConfigParser': mock.patch('highfive.newpr.ConfigParser'),
1247+
'new_pr': mock.patch('highfive.newpr.new_pr'),
1248+
'new_comment': mock.patch('highfive.newpr.new_comment'),
1249+
'sys': mock.patch('highfive.newpr.sys')
1250+
}
1251+
self.mocks = {k: v.start() for k,v in self.patchers.iteritems()}
1252+
1253+
self.config_mock = mock.Mock()
1254+
self.config_mock.get.side_effect = (
1255+
'integration-user', 'integration-token'
1256+
)
1257+
self.mocks['ConfigParser'].RawConfigParser.return_value = self.config_mock
1258+
1259+
def tearDown(self):
1260+
super(TestRun, self).tearDown()
1261+
1262+
for patcher in self.patchers.itervalues():
1263+
patcher.stop()
1264+
1265+
def test_newpr(self):
1266+
payload = {'action': 'opened'}
1267+
newpr.run(payload)
1268+
self.assertEqual(self.config_mock.get.call_count, 2)
1269+
self.mocks['new_pr'].assert_called_once_with(
1270+
payload, 'integration-user', 'integration-token'
1271+
)
1272+
self.mocks['new_comment'].assert_not_called()
1273+
self.mocks['sys'].exit.assert_not_called()
1274+
1275+
def test_new_comment(self):
1276+
payload = {'action': 'created'}
1277+
newpr.run(payload)
1278+
self.assertEqual(self.config_mock.get.call_count, 2)
1279+
self.mocks['new_pr'].assert_not_called()
1280+
self.mocks['new_comment'].assert_called_once_with(
1281+
payload, 'integration-user', 'integration-token'
1282+
)
1283+
self.mocks['sys'].exit.assert_not_called()
1284+
1285+
def test_unsupported_payload(self):
1286+
payload = {'action': 'something-not-supported'}
1287+
newpr.run(payload)
1288+
self.assertEqual(self.config_mock.get.call_count, 2)
1289+
self.mocks['new_pr'].assert_not_called()
1290+
self.mocks['new_comment'].assert_not_called()
1291+
self.mocks['sys'].exit.assert_called_once_with(0)

0 commit comments

Comments
 (0)