@@ -238,12 +238,215 @@ def test_approved(_):
238238 assert state .get_status () == 'approved'
239239
240240
241- #def test_tried():
242- # """
243- # Test that a pull request that has been tried shows up as tried
244- # """
245- #
246- #
241+ @unittest .mock .patch ('homu.pull_req_state.assert_authorized' ,
242+ side_effect = return_true )
243+ def test_homu_state_approval (_ ):
244+ state = new_state (head_sha = 'abcdef' )
245+ event = create_event ({
246+ 'eventType' : 'IssueComment' ,
247+ 'author' : {
248+ 'login' : 'bors' ,
249+ },
250+ 'body' : '''
251+ Commit abcdef has been approved
252+
253+ <!-- homu: {"type":"Approved","sha":"012345","approver":"ferris"} -->
254+ ''' , # noqa
255+ 'publishedAt' : '1985-04-21T00:00:00Z' ,
256+ })
257+ result = state .process_event (event )
258+ assert result .changed is True
259+ assert len (result .comments ) == 0
260+ assert state .get_status () == 'approved'
261+ assert state .approved_by == 'ferris'
262+
263+ # Nobody but bors can use homu state
264+ state = new_state (head_sha = 'abcdef' )
265+ event = create_event ({
266+ 'eventType' : 'IssueComment' ,
267+ 'author' : {
268+ 'login' : 'ferris' ,
269+ },
270+ 'body' : '''
271+ Commit abcdef has been approved
272+
273+ <!-- homu: {"type":"Approved","sha":"012345","approver":"ferris"} -->
274+ ''' , # noqa
275+ 'publishedAt' : '1985-04-21T00:00:00Z' ,
276+ })
277+ result = state .process_event (event )
278+ assert result .changed is False
279+ assert len (result .comments ) == 0
280+ assert state .get_status () == ''
281+ assert state .approved_by == ''
282+
283+
284+ @unittest .mock .patch ('homu.pull_req_state.assert_authorized' ,
285+ side_effect = return_true )
286+ def test_tried (_ ):
287+ """
288+ Test that a pull request that has been tried shows up as tried
289+ """
290+
291+ state = new_state ()
292+ result = state .process_event (create_event ({
293+ 'eventType' : 'IssueComment' ,
294+ 'author' : {
295+ 'login' : 'bors' ,
296+ },
297+ 'body' : '''
298+ :hourglass: Trying commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
299+ <!-- homu: {"type":"TryBuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
300+ ''' , # noqa
301+ 'publishedAt' : '1985-04-21T00:00:00Z' ,
302+ }))
303+
304+ assert result .changed is True
305+ assert state .try_ is True
306+ assert state .get_status () == 'pending'
307+
308+ result = state .process_event (create_event ({
309+ 'eventType' : 'IssueComment' ,
310+ 'author' : {
311+ 'login' : 'bors' ,
312+ },
313+ 'body' : '''
314+ :sunny: Try build successful - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
315+ <!-- homu: {"type":"TryBuildCompleted","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
316+ ''' , # noqa
317+ 'publishedAt' : '1985-04-21T00:01:00Z' ,
318+ }))
319+
320+ assert result .changed is True
321+ assert state .try_ is True
322+ assert state .get_status () == 'success'
323+
324+
325+ @unittest .mock .patch ('homu.pull_req_state.assert_authorized' ,
326+ side_effect = return_true )
327+ def test_try_failed (_ ):
328+ """
329+ Test that a pull request that has been tried shows up as tried
330+ """
331+
332+ state = new_state ()
333+ result = state .process_event (create_event ({
334+ 'eventType' : 'IssueComment' ,
335+ 'author' : {
336+ 'login' : 'bors' ,
337+ },
338+ 'body' : '''
339+ :hourglass: Trying commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
340+ <!-- homu: {"type":"TryBuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
341+ ''' , # noqa
342+ 'publishedAt' : '1985-04-21T00:00:00Z' ,
343+ }))
344+
345+ assert result .changed is True
346+ assert state .try_ is True
347+ assert state .get_status () == 'pending'
348+
349+ result = state .process_event (create_event ({
350+ 'eventType' : 'IssueComment' ,
351+ 'author' : {
352+ 'login' : 'bors' ,
353+ },
354+ 'body' : '''
355+ :sunny: Try build successful - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
356+ <!-- homu: {"type":"TryBuildFailed","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
357+ ''' , # noqa
358+ 'publishedAt' : '1985-04-21T00:01:00Z' ,
359+ }))
360+
361+ assert result .changed is True
362+ assert state .try_ is True
363+ assert state .get_status () == 'failure'
364+
365+
366+ @unittest .mock .patch ('homu.pull_req_state.assert_authorized' ,
367+ side_effect = return_true )
368+ def test_build (_ ):
369+ """
370+ Test that a pull request that has been built shows up as built. This is
371+ maybe a bad test because a PR that has been built and succeeds will likely
372+ be merged and removed.
373+ """
374+
375+ state = new_state ()
376+ result = state .process_event (create_event ({
377+ 'eventType' : 'IssueComment' ,
378+ 'author' : {
379+ 'login' : 'bors' ,
380+ },
381+ 'body' : '''
382+ :hourglass: Building commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
383+ <!-- homu: {"type":"BuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
384+ ''' , # noqa
385+ 'publishedAt' : '1985-04-21T00:00:00Z' ,
386+ }))
387+
388+ assert result .changed is True
389+ assert state .try_ is False
390+ assert state .get_status () == 'pending'
391+
392+ result = state .process_event (create_event ({
393+ 'eventType' : 'IssueComment' ,
394+ 'author' : {
395+ 'login' : 'bors' ,
396+ },
397+ 'body' : '''
398+ :sunny: Build successful - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
399+ <!-- homu: {"type":"BuildCompleted","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
400+ ''' , # noqa
401+ 'publishedAt' : '1985-04-21T00:01:00Z' ,
402+ }))
403+
404+ assert result .changed is True
405+ assert state .try_ is False
406+ assert state .get_status () == 'success'
407+
408+
409+ @unittest .mock .patch ('homu.pull_req_state.assert_authorized' ,
410+ side_effect = return_true )
411+ def test_build_failed (_ ):
412+ """
413+ Test that a pull request that has been built and failed shows up that way.
414+ """
415+
416+ state = new_state ()
417+ result = state .process_event (create_event ({
418+ 'eventType' : 'IssueComment' ,
419+ 'author' : {
420+ 'login' : 'bors' ,
421+ },
422+ 'body' : '''
423+ :hourglass: Building commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
424+ <!-- homu: {"type":"BuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
425+ ''' , # noqa
426+ 'publishedAt' : '1985-04-21T00:00:00Z' ,
427+ }))
428+
429+ assert result .changed is True
430+ assert state .try_ is True
431+ assert state .get_status () == 'pending'
432+
433+ result = state .process_event (create_event ({
434+ 'eventType' : 'IssueComment' ,
435+ 'author' : {
436+ 'login' : 'bors' ,
437+ },
438+ 'body' : '''
439+ :sunny: Build failed - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
440+ <!-- homu: {"type":"BuildFailed","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
441+ ''' , # noqa
442+ 'publishedAt' : '1985-04-21T00:01:00Z' ,
443+ }))
444+
445+ assert result .changed is True
446+ assert state .try_ is True
447+ assert state .get_status () == 'failure'
448+
449+
247450#def test_tried_and_approved():
248451# """
249452# Test that a pull request that has been approved AND tried shows up as
0 commit comments