Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sw360/sw360_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,9 @@ def get_health_status(self) -> Optional[Dict[str, Any]]:
:rtype: JSON health status object
:raises SW360Error: if there is a negative HTTP response
"""
resp = self.api_get(self.url + "resource/api/health/")
return resp
try:
# SW360 >= 19.0 has changed the endpoint path
return self.api_get(self.url + "resource/api/health/")
except SW360Error:
# try to fallback to old endpoint for SW360 <= 18.x
return self.api_get(self.url + "resource/health/")
27 changes: 27 additions & 0 deletions tests/test_sw360_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ def test_get_health_status(self) -> None:
if status: # only for mypy
self.assertTrue("status" in status)

@responses.activate
def test_get_health_status_pre_v19_fallback(self) -> None:
lib = SW360(self.MYURL, self.MYTOKEN, False)
self._add_login_response()
actual = lib.login_api()
self.assertTrue(actual)

responses.add(
method=responses.GET,
url=self.MYURL + "resource/api/health/",
body='{"status":404,"error":"Not Found","path":"/resource/api/health/"}',
status=404,
)

responses.add(
method=responses.GET,
url=self.MYURL + "resource/health/",
body='{"status": "UP"}',
status=200,
content_type="application/json",
)

status = lib.get_health_status()
self.assertIsNotNone(status)
if status:
self.assertTrue("status" in status)


if __name__ == "__main__":
unittest.main()
Loading