Skip to content

Commit 0f5f415

Browse files
author
Bryan Sieber
committed
Adding more tests. Updating services
1 parent eaed037 commit 0f5f415

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

infra/config/local_dev.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Environment variables for the local development environment
2+
3+
# Jira API Secrets
4+
JIRA_USERNAME="fake_jira_username"
5+
JIRA_PASSWORD="fake_jira_password"
6+
7+
# Bugzilla API Secrets
8+
BUGZILLA_API_KEY="fake_bugzilla_api_key"

src/jbi/services.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,29 @@
55

66
settings = environment.get_settings()
77

8-
jira = Jira(
9-
url=settings.jira_base_url,
10-
username=settings.jira_username,
11-
password=settings.jira_password,
12-
)
138

14-
bugzilla = rh_bugzilla.Bugzilla(
15-
settings.bugzilla_base_url, api_key=settings.bugzilla_api_key
16-
)
9+
def get_jira():
10+
return Jira(
11+
url=settings.jira_base_url,
12+
username=settings.jira_username,
13+
password=settings.jira_password,
14+
)
15+
16+
17+
def get_bugzilla():
18+
return rh_bugzilla.Bugzilla(
19+
settings.bugzilla_base_url, api_key=settings.bugzilla_api_key
20+
)
1721

1822

1923
def bugzilla_check_health():
24+
bugzilla = get_bugzilla()
2025
health = {"up": bugzilla.logged_in}
2126
return health
2227

2328

2429
def jira_check_health():
30+
jira = get_jira()
2531
server_info = jira.get_server_info(True)
2632
print(server_info)
2733
health = {"up": False}

tests/infra/docker-compose.test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ services:
1212
# Let the init system handle signals for us.
1313
# among other things this helps shutdown be fast
1414
init: true
15+
env_file:
16+
- infra/config/local_dev.env

tests/unit/app/test_monitor.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,52 @@ def test_read_version(anon_client):
1818

1919
def test_read_heartbeat_no_services_fails(anon_client):
2020
"""/__heartbeat__ returns 503 when the services are unavailable."""
21-
resp = anon_client.get("/__heartbeat__")
21+
expected = {
22+
"jira": {
23+
"up": False,
24+
},
25+
"bugzilla": {
26+
"up": False,
27+
},
28+
}
29+
with patch("src.app.monitor.jbi_service_health_map", return_value=expected):
30+
resp = anon_client.get("/__heartbeat__")
31+
assert resp.status_code == 503
32+
data = resp.json()
33+
assert data == expected
34+
35+
36+
def test_read_heartbeat_jira_services_fails(anon_client):
37+
"""/__heartbeat__ returns 503 when the services are unavailable."""
38+
expected = {
39+
"jira": {
40+
"up": False,
41+
},
42+
"bugzilla": {
43+
"up": True,
44+
},
45+
}
46+
with patch("src.app.monitor.jbi_service_health_map", return_value=expected):
47+
resp = anon_client.get("/__heartbeat__")
48+
assert resp.status_code == 503
49+
data = resp.json()
50+
assert data == expected
51+
52+
53+
def test_read_heartbeat_bugzilla_services_fails(anon_client):
54+
"""/__heartbeat__ returns 503 when the services are unavailable."""
55+
expected = {
56+
"jira": {
57+
"up": True,
58+
},
59+
"bugzilla": {
60+
"up": False,
61+
},
62+
}
63+
with patch("src.app.monitor.jbi_service_health_map", return_value=expected):
64+
resp = anon_client.get("/__heartbeat__")
2265
assert resp.status_code == 503
2366
data = resp.json()
24-
expected = {"bugzilla": {"up": False}, "jira": {"up": False}}
2567
assert data == expected
2668

2769

0 commit comments

Comments
 (0)