@@ -36,10 +36,10 @@ def test_method_not_allowed(client):
3636
3737
3838def test_headers_not_correct (client , caplog ):
39- response = client .post ("/github-webhook" )
39+ response = client .post ("/github-webhook" , headers = { 'User-Agent' : 'foo' } )
4040 assert response .status_code == 401
4141 assert caplog .messages == [
42- "User-Agent is werkzeug/2.2.2 " ,
42+ "User-Agent is foo " ,
4343 "Content is not JSON" ,
4444 "No GitHub Event received!" ,
4545 ]
@@ -66,8 +66,8 @@ def test_started_job_not_stored(client, caplog):
6666 assert response .status_code == 200
6767 assert caplog .messages == [
6868 "Job 2 is in_progress but not stored!" ,
69- ' action=in_progress repository=foo/foo job_id=2 workflow=CI requestor=testerbot time_to_start=0 '
70- ' runner_name= runner_public=false repository_private=false' ,
69+ " action=in_progress repository=foo/foo job_id=2 workflow=CI requestor=testerbot "
70+ " runner_name= runner_public=false repository_private=false" ,
7171 ]
7272
7373
@@ -79,7 +79,7 @@ def test_finished_job_not_stored(client, caplog):
7979 assert response .status_code == 200
8080 assert caplog .messages == [
8181 "Job 3 is completed but not stored!" ,
82- ' action=completed repository=foo/foo job_id=3 workflow=CI requestor=testerbot time_to_finish=0 conclusion=' ,
82+ " action=completed repository=foo/foo job_id=3 workflow=CI requestor=testerbot time_to_finish=0 conclusion=" ,
8383 ]
8484
8585
@@ -93,7 +93,7 @@ def test_unknown_action(client, caplog):
9393 response = client .post ("/github-webhook" , headers = HEADERS , json = body_failed )
9494 assert response .status_code == 200
9595 assert caplog .messages == [
96- ' action=queued repository=foo/foo job_id=4 workflow=CI requestor=testerbot' ,
96+ " action=queued repository=foo/foo job_id=4 workflow=CI requestor=testerbot" ,
9797 "Unknown action failed, removing from memory" ,
9898 ]
9999
@@ -105,7 +105,7 @@ def test_queued_job(client, caplog):
105105 response = client .post ("/github-webhook" , headers = HEADERS , json = body_queued )
106106 assert response .status_code == 200
107107 assert caplog .messages == [
108- ' action=queued repository=foo/foo job_id=1 workflow=CI requestor=testerbot'
108+ " action=queued repository=foo/foo job_id=1 workflow=CI requestor=testerbot"
109109 ]
110110
111111
@@ -117,7 +117,8 @@ def test_logging_flow(client, caplog):
117117 response = client .post ("/github-webhook" , headers = HEADERS , json = body_queued )
118118 assert response .status_code == 200
119119 assert (
120- caplog .messages [0 ] == 'action=queued repository=foo/foo job_id=5 workflow=CI requestor=testerbot'
120+ caplog .messages [0 ]
121+ == "action=queued repository=foo/foo job_id=5 workflow=CI requestor=testerbot"
121122 )
122123
123124 body_started = BODY .copy ()
@@ -127,9 +128,8 @@ def test_logging_flow(client, caplog):
127128 assert response .status_code == 200
128129 assert (
129130 caplog .messages [1 ]
130- == 'action=in_progress repository=foo/foo job_id=5 workflow=CI requestor=testerbot time_to_start=5 '
131- 'runner_name= runner_public=false repository_private=false'
132-
131+ == "action=in_progress repository=foo/foo job_id=5 workflow=CI requestor=testerbot "
132+ "runner_name= runner_public=false repository_private=false time_to_start=5"
133133 )
134134
135135 body_completed = BODY .copy ()
@@ -140,6 +140,33 @@ def test_logging_flow(client, caplog):
140140 assert response .status_code == 200
141141 assert (
142142 caplog .messages [2 ]
143- == 'action=completed repository=foo/foo job_id=5 workflow=CI requestor=testerbot '
144- 'time_to_finish=295 conclusion=success'
143+ == "action=completed repository=foo/foo job_id=5 workflow=CI requestor=testerbot "
144+ "time_to_finish=295 conclusion=success"
145+ )
146+
147+
148+ def test_logging_flow_queued_after_in_progress (client , caplog ):
149+ body_queued = BODY .copy ()
150+ body_queued ["action" ] = "queued"
151+ body_queued ["workflow_job" ]["id" ] = 6
152+ body_queued ["workflow_job" ]["started_at" ] = "2023-02-17T06:57:48Z"
153+
154+ response = client .post ("/github-webhook" , headers = HEADERS , json = body_queued )
155+ assert response .status_code == 200
156+ assert (
157+ caplog .messages [0 ]
158+ == "action=queued repository=foo/foo job_id=6 workflow=CI requestor=testerbot"
159+ )
160+
161+ body_started = BODY .copy ()
162+ body_started ["action" ] = "in_progress"
163+ body_started ["workflow_job" ]["started_at" ] = "2023-02-17T06:57:46Z"
164+ response = client .post ("/github-webhook" , headers = HEADERS , json = body_started )
165+
166+ assert response .status_code == 200
167+ assert caplog .messages [1 ] == "Job 6 was in progress before being queued"
168+ assert (
169+ caplog .messages [2 ]
170+ == "action=in_progress repository=foo/foo job_id=6 workflow=CI"
171+ " requestor=testerbot runner_name= runner_public=false repository_private=false"
145172 )
0 commit comments