diff --git a/sw360/sw360_api.py b/sw360/sw360_api.py index 925813e..795f4cf 100644 --- a/sw360/sw360_api.py +++ b/sw360/sw360_api.py @@ -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/") diff --git a/tests/test_sw360_health.py b/tests/test_sw360_health.py index e6a080a..6e6723d 100644 --- a/tests/test_sw360_health.py +++ b/tests/test_sw360_health.py @@ -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()