3333 },
3434}
3535
36+ HOOK_ENDPOINT = "/github-webhook"
37+
3638
3739def test_method_not_allowed (client ):
38- assert client .get ("/github-webhook" ).status_code == 401
40+ assert client .get (HOOK_ENDPOINT ).status_code == 401
3941
4042
4143def test_headers_not_correct (client , caplog ):
42- response = client .post ("/github-webhook" , headers = {'User-Agent' : 'foo' })
44+ response = client .post (HOOK_ENDPOINT , headers = {'User-Agent' : 'foo' })
4345 assert response .status_code == 401
4446 assert caplog .messages == [
4547 "User-Agent is foo" ,
@@ -49,14 +51,14 @@ def test_headers_not_correct(client, caplog):
4951
5052
5153def test_no_body_bad_request (client ):
52- response = client .post ("/github-webhook" , headers = HEADERS )
54+ response = client .post (HOOK_ENDPOINT , headers = HEADERS )
5355 assert response .status_code == 400
5456
5557
5658def test_unknown_event (client , caplog ):
5759 headers = HEADERS .copy ()
5860 headers [GithubHeaders .EVENT .value ] = "foo"
59- response = client .post ("/github-webhook" , headers = headers , json = {})
61+ response = client .post (HOOK_ENDPOINT , headers = headers , json = {})
6062 assert response .status_code == 405
6163 assert caplog .messages == ["Unknown event type foo, can't handle" ]
6264
@@ -65,7 +67,7 @@ def test_started_job_not_stored(client, caplog):
6567 body_started = BODY .copy ()
6668 body_started ["action" ] = "in_progress"
6769 body_started ["workflow_job" ]["id" ] = 2
68- response = client .post ("/github-webhook" , headers = HEADERS , json = body_started )
70+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_started )
6971 assert response .status_code == 200
7072 assert caplog .messages == [
7173 "Job 2 is in_progress but not stored!" ,
@@ -79,7 +81,7 @@ def test_finished_job_not_stored(client, caplog):
7981 body_finished = BODY .copy ()
8082 body_finished ["action" ] = "completed"
8183 body_finished ["workflow_job" ]["id" ] = 3
82- response = client .post ("/github-webhook" , headers = HEADERS , json = body_finished )
84+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_finished )
8385 assert response .status_code == 200
8486 assert caplog .messages == [
8587 "Job 3 is completed but not stored!" ,
@@ -92,10 +94,10 @@ def test_unknown_action(client, caplog):
9294 body_started = BODY .copy ()
9395 body_started ["action" ] = "queued"
9496 body_started ["workflow_job" ]["id" ] = 4
95- response = client .post ("/github-webhook" , headers = HEADERS , json = body_started )
97+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_started )
9698 body_failed = body_started .copy ()
9799 body_failed ["action" ] = "failed"
98- response = client .post ("/github-webhook" , headers = HEADERS , json = body_failed )
100+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_failed )
99101 assert response .status_code == 200
100102 assert caplog .messages == [
101103 "action=queued repository=foo/foo branch=new-feature-branch job_id=4 run_id=10 "
@@ -108,7 +110,7 @@ def test_queued_job(client, caplog):
108110 body_queued = BODY .copy ()
109111 body_queued ["action" ] = "queued"
110112 body_queued ["workflow_job" ]["id" ] = 1
111- response = client .post ("/github-webhook" , headers = HEADERS , json = body_queued )
113+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_queued )
112114 assert response .status_code == 200
113115 assert caplog .messages == [
114116 "action=queued repository=foo/foo branch=new-feature-branch job_id=1 run_id=10 "
@@ -121,7 +123,7 @@ def test_logging_flow(client, caplog):
121123 body_queued ["action" ] = "queued"
122124 body_queued ["workflow_job" ]["id" ] = 5
123125
124- response = client .post ("/github-webhook" , headers = HEADERS , json = body_queued )
126+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_queued )
125127 assert response .status_code == 200
126128 assert (
127129 caplog .messages [0 ]
@@ -132,7 +134,7 @@ def test_logging_flow(client, caplog):
132134 body_started = BODY .copy ()
133135 body_started ["action" ] = "in_progress"
134136 body_started ["workflow_job" ]["started_at" ] = "2023-01-27T14:00:05Z"
135- response = client .post ("/github-webhook" , headers = HEADERS , json = body_started )
137+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_started )
136138 assert response .status_code == 200
137139 assert (
138140 caplog .messages [1 ]
@@ -145,7 +147,7 @@ def test_logging_flow(client, caplog):
145147 body_completed ["action" ] = "completed"
146148 body_completed ["workflow_job" ]["conclusion" ] = "success"
147149 body_completed ["workflow_job" ]["completed_at" ] = "2023-01-27T14:05:00Z"
148- response = client .post ("/github-webhook" , headers = HEADERS , json = body_completed )
150+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_completed )
149151 assert response .status_code == 200
150152 assert (
151153 caplog .messages [2 ]
@@ -161,7 +163,7 @@ def test_logging_flow_queued_after_in_progress(client, caplog):
161163 body_queued ["workflow_job" ]["id" ] = 6
162164 body_queued ["workflow_job" ]["started_at" ] = "2023-02-17T06:57:48Z"
163165
164- response = client .post ("/github-webhook" , headers = HEADERS , json = body_queued )
166+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_queued )
165167 assert response .status_code == 200
166168 assert (
167169 caplog .messages [0 ]
@@ -172,7 +174,7 @@ def test_logging_flow_queued_after_in_progress(client, caplog):
172174 body_started = BODY .copy ()
173175 body_started ["action" ] = "in_progress"
174176 body_started ["workflow_job" ]["started_at" ] = "2023-02-17T06:57:46Z"
175- response = client .post ("/github-webhook" , headers = HEADERS , json = body_started )
177+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body_started )
176178
177179 assert response .status_code == 200
178180 assert caplog .messages [1 ] == "Job 6 was in progress before being queued"
@@ -190,7 +192,7 @@ def test_line_break_in_job_name(client, caplog):
190192 body ["workflow_job" ][
191193 "name"
192194 ] = "Build and push images (actions-runner-dind, NPROC=2\n , runner-images/devops/actions-runner-dind, l..."
193- response = client .post ("/github-webhook" , headers = HEADERS , json = body )
195+ response = client .post (HOOK_ENDPOINT , headers = HEADERS , json = body )
194196 assert response .status_code == 200
195197 assert caplog .messages == [
196198 'action=queued repository=foo/foo branch=new-feature-branch job_id=6 run_id=10 job_name="Build and push '
0 commit comments