@@ -1237,3 +1237,55 @@ def test_with_dirs_no_intersection(self):
1237
1237
)
1238
1238
self .assertEqual (set (["pnkfelix" , "nrc" ]), chosen_reviewers )
1239
1239
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