33from datetime import datetime
44from unittest import mock
55
6+ import pytest
67from fastapi .testclient import TestClient
78
89from jbi .app import app
@@ -26,7 +27,7 @@ def test_whiteboard_tags(anon_client):
2627
2728
2829def test_jira_projects (anon_client , mocked_jira ):
29- mocked_jira .projects .return_value = [{"key" : "Firefox" }, {"key" : "Fenix" }]
30+ mocked_jira .permitted_projects .return_value = [{"key" : "Firefox" }, {"key" : "Fenix" }]
3031
3132 resp = anon_client .get ("/jira_projects/" )
3233 infos = resp .json ()
@@ -247,52 +248,6 @@ def test_read_heartbeat_bugzilla_services_fails(anon_client, mocked_bugzilla):
247248 }
248249
249250
250- def test_read_heartbeat_success (
251- anon_client , mocked_jira , mocked_bugzilla , bugzilla_webhook_factory
252- ):
253- """/__heartbeat__ returns 200 when checks succeed."""
254- mocked_bugzilla .logged_in .return_value = True
255- mocked_bugzilla .list_webhooks .return_value = [bugzilla_webhook_factory ()]
256- mocked_jira .get_server_info .return_value = {}
257- mocked_jira .projects .return_value = [
258- {
259- "key" : "DevTest" ,
260- "issueTypes" : [
261- {"name" : "Task" },
262- {"name" : "Bug" },
263- ],
264- }
265- ]
266- mocked_jira .get_project_components .return_value = [{"name" : "Main" }]
267- mocked_jira .permitted_projects .return_value = [{"id" : "12345" , "key" : "DevTest" }]
268-
269- mocked_jira .get_project_components .return_value = [{"name" : "Main" }]
270- mocked_jira .permitted_projects .return_value = [{"id" : "12345" , "key" : "DevTest" }]
271- mocked_jira .get_project .return_value = {
272- "issueTypes" : [
273- {"name" : "Task" },
274- {"name" : "Bug" },
275- ]
276- }
277-
278- resp = anon_client .get ("/__heartbeat__" )
279-
280- assert resp .status_code == 200
281- assert resp .json () == {
282- "jira" : {
283- "up" : True ,
284- "all_projects_are_visible" : True ,
285- "all_projects_have_permissions" : True ,
286- "all_project_custom_components_exist" : True ,
287- "all_projects_issue_types_exist" : True ,
288- },
289- "bugzilla" : {
290- "up" : True ,
291- "all_webhooks_enabled" : True ,
292- },
293- }
294-
295-
296251def test_jira_heartbeat_visible_projects (anon_client , mocked_jira ):
297252 """/__heartbeat__ fails if configured projects don't match."""
298253 mocked_jira .get_server_info .return_value = {}
@@ -349,35 +304,50 @@ def test_jira_heartbeat_unknown_issue_types(anon_client, mocked_jira):
349304 assert not resp .json ()["jira" ]["all_projects_issue_types_exist" ]
350305
351306
352- def test_head_heartbeat_success (
353- anon_client , mocked_jira , mocked_bugzilla , bugzilla_webhook_factory
307+ @pytest .mark .parametrize ("method" , ["HEAD" , "GET" ])
308+ def test_read_heartbeat_success (
309+ anon_client , method , mocked_jira , mocked_bugzilla , bugzilla_webhook_factory
354310):
355- """/__heartbeat__ support head requests """
311+ """/__heartbeat__ returns 200 when checks succeed. """
356312 mocked_bugzilla .logged_in .return_value = True
357313 mocked_bugzilla .list_webhooks .return_value = [bugzilla_webhook_factory ()]
358314 mocked_jira .get_server_info .return_value = {}
359- mocked_jira .projects .return_value = [
360- {
361- "key" : "DevTest" ,
362- "issueTypes" : [
363- {"name" : "Task" },
364- {"name" : "Bug" },
365- ],
366- }
367- ]
315+ mocked_jira .paginated_projects .return_value = {
316+ "values" : [
317+ {
318+ "key" : "DevTest" ,
319+ "issueTypes" : [
320+ {"name" : "Task" },
321+ {"name" : "Bug" },
322+ ],
323+ }
324+ ]
325+ }
368326 mocked_jira .get_project_components .return_value = [{"name" : "Main" }]
369- mocked_jira .permitted_projects .return_value = [{"id" : "12345" , " key" : "DevTest" }]
327+ mocked_jira .permitted_projects .return_value = [{"key" : "DevTest" }]
370328
371- resp = anon_client .head ( "/ __heartbeat__" )
329+ resp = anon_client .request ( method , " __heartbeat__" )
372330
373331 assert resp .status_code == 200
332+ if method == "GET" :
333+ assert resp .json () == {
334+ "jira" : {
335+ "up" : True ,
336+ "all_projects_are_visible" : True ,
337+ "all_projects_have_permissions" : True ,
338+ "all_project_custom_components_exist" : True ,
339+ "all_projects_issue_types_exist" : True ,
340+ },
341+ "bugzilla" : {
342+ "up" : True ,
343+ "all_webhooks_enabled" : True ,
344+ },
345+ }
374346
375347
376- def test_lbheartbeat (anon_client ):
348+ @pytest .mark .parametrize ("method" , ["HEAD" , "GET" ])
349+ def test_lbheartbeat (anon_client , method ):
377350 """/__lbheartbeat__ always returns 200"""
378351
379- resp = anon_client .get ("/__lbheartbeat__" )
380- assert resp .status_code == 200
381-
382- resp = anon_client .head ("/__lbheartbeat__" )
352+ resp = anon_client .request (method , "__lbheartbeat__" )
383353 assert resp .status_code == 200
0 commit comments