Skip to content

Commit fa63f42

Browse files
committed
fix(health): fallback for SW360 <= 18.x
Extend 31323ca with fallback code so the library also continues to work with SW360 18.x.
1 parent ecf10dc commit fa63f42

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎sw360/sw360_api.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,9 @@ def get_health_status(self) -> Optional[Dict[str, Any]]:
160160
:rtype: JSON health status object
161161
:raises SW360Error: if there is a negative HTTP response
162162
"""
163-
resp = self.api_get(self.url + "resource/api/health/")
164-
return resp
163+
try:
164+
# SW360 >= 19.0 has changed the endpoint path
165+
return self.api_get(self.url + "resource/api/health/")
166+
except SW360Error:
167+
# try to fallback to old endpoint for SW360 <= 18.x
168+
return self.api_get(self.url + "resource/health/")

‎tests/test_sw360_health.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,33 @@ def test_get_health_status(self) -> None:
6262
if status: # only for mypy
6363
self.assertTrue("status" in status)
6464

65+
@responses.activate
66+
def test_get_health_status_pre_v19_fallback(self) -> None:
67+
lib = SW360(self.MYURL, self.MYTOKEN, False)
68+
self._add_login_response()
69+
actual = lib.login_api()
70+
self.assertTrue(actual)
71+
72+
responses.add(
73+
method=responses.GET,
74+
url=self.MYURL + "resource/api/health/",
75+
body='{"status":404,"error":"Not Found","path":"/resource/api/health/"}',
76+
status=404,
77+
)
78+
79+
responses.add(
80+
method=responses.GET,
81+
url=self.MYURL + "resource/health/",
82+
body='{"status": "UP"}',
83+
status=200,
84+
content_type="application/json",
85+
)
86+
87+
status = lib.get_health_status()
88+
self.assertIsNotNone(status)
89+
if status:
90+
self.assertTrue("status" in status)
91+
6592

6693
if __name__ == "__main__":
6794
unittest.main()

0 commit comments

Comments
 (0)