diff --git a/.gitignore b/.gitignore index e2d318b..fc6ace4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ Test.tar.gz Test_file.zip test_all_components.json test_all_releases.json +real_instance_tests.py # test coverage htmlcov/ diff --git a/sw360/components.py b/sw360/components.py index d77a9f9..debb676 100644 --- a/sw360/components.py +++ b/sw360/components.py @@ -19,7 +19,8 @@ class ComponentsMixin(BaseMixin): def get_all_components(self, fields=None, page=-1, page_size=-1, - all_details: bool = False, sort: str = "") -> List[Dict[str, Any]]: + all_details: bool = False, + sort: str = "") -> List[Dict[str, Any]] | Optional[Dict[str, Any]]: """Get information of about all components API endpoint: GET /components @@ -67,7 +68,7 @@ def get_all_components(self, fields=None, page=-1, page_size=-1, if page == -1: return resp["_embedded"]["sw360:components"] - return [] + return resp def get_components_by_type(self, component_type: str) -> List[Dict[str, Any]]: """Get information of about all components for certain type diff --git a/sw360/releases.py b/sw360/releases.py index 9d4213d..db7c83a 100644 --- a/sw360/releases.py +++ b/sw360/releases.py @@ -65,7 +65,7 @@ def get_releases_by_name(self, name: str) -> List[Any]: return [] def get_all_releases(self, fields: str = "", all_details: bool = False, page: int = -1, - page_size: int = -1, sort: str = "") -> List[Dict[str, Any]]: + page_size: int = -1, sort: str = "") -> List[Dict[str, Any]] | Optional[Dict[str, Any]]: """Get information of about all releases API endpoint: GET /releases @@ -103,7 +103,7 @@ def get_all_releases(self, fields: str = "", all_details: bool = False, page: in if page == -1 and resp and ("_embedded" in resp) and ("sw360:releases" in resp["_embedded"]): return resp["_embedded"]["sw360:releases"] - return [] + return resp def get_releases_by_external_id(self, ext_id_name: str, ext_id_value: str = "") -> List[Dict[str, Any]]: """Get releases by external id. `ext_id_value` can be left blank to diff --git a/tests/test_sw360_components.py b/tests/test_sw360_components.py index 9754486..7927bc3 100644 --- a/tests/test_sw360_components.py +++ b/tests/test_sw360_components.py @@ -92,7 +92,7 @@ def test_get_all_components_no_result(self): ) components = lib.get_all_components() - self.assertIsNone(components) + self.assertEqual([], components) @responses.activate def test_get_all_components_with_fields(self): @@ -124,7 +124,6 @@ def test_get_all_components_with_fields_and_paging(self): self._add_login_response() actual = lib.login_api() self.assertTrue(actual) - responses.add( method=responses.GET, url=self.MYURL + "resource/api/components?fields=ownerCountry&page=1&page_entries=2", # noqa @@ -134,8 +133,8 @@ def test_get_all_components_with_fields_and_paging(self): adding_headers={"Authorization": "Token " + self.MYTOKEN}, ) - dict = lib.get_all_components("ownerCountry", 1, 2) - components = dict["_embedded"]["sw360:components"] + data = lib.get_all_components("ownerCountry", 1, 2) + components = data["_embedded"]["sw360:components"] self.assertIsNotNone(components) self.assertTrue(len(components) > 0) self.assertEqual("Tethys.Logging", components[0]["name"]) @@ -182,7 +181,7 @@ def test_get_all_components_by_type_no_result(self): ) components = lib.get_components_by_type("OSS") - self.assertIsNone(components) + self.assertEqual([], components) @responses.activate def test_get_component(self): @@ -255,7 +254,7 @@ def test_get_components_by_external_id(self): responses.add( method=responses.GET, url=self.MYURL + "resource/api/components/searchByExternalIds?package-url=pkg:nuget/Tethys.Logging", # noqa - body='[{"name": "Tethys.Logging", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]', # noqa + body='{"_embedded":{"sw360:components" :[{"name": "Tethys.Logging", "componentType": "OSS", "externalIds": {"package-url": "pkg:nuget/Tethys.Logging"}}]}}', # noqa status=200, content_type="application/json", adding_headers={"Authorization": "Token " + self.MYTOKEN}, @@ -671,4 +670,6 @@ def xtest_get_component_real(self): if __name__ == "__main__": - unittest.main() + # unittest.main() + x = Sw360TestComponents() + x.test_get_all_components_with_fields_and_paging() diff --git a/tests/test_sw360_licenses.py b/tests/test_sw360_licenses.py index 4c06ad0..e76baff 100644 --- a/tests/test_sw360_licenses.py +++ b/tests/test_sw360_licenses.py @@ -93,7 +93,7 @@ def test_get_all_licenses_none(self): ) licenses = lib.get_all_licenses() - self.assertIsNone(licenses) + self.assertEqual([], licenses) @responses.activate def test_get_license(self): diff --git a/tests/test_sw360_projects.py b/tests/test_sw360_projects.py index ffd0905..eb8fa45 100644 --- a/tests/test_sw360_projects.py +++ b/tests/test_sw360_projects.py @@ -295,7 +295,7 @@ def test_get_projects_by_name(self): ) projects = lib.get_projects_by_name("My") - self.assertIsNone(projects) + self.assertEqual([], projects) @responses.activate def test_get_projects_by_name_no_result(self): @@ -349,7 +349,7 @@ def test_get_projects_by_external_id_no_result(self): ) projects = lib.get_projects_by_external_id("myid", "9999") - self.assertIsNone(projects) + self.assertEqual([], projects) @responses.activate def test_get_projects_by_group(self): @@ -401,7 +401,7 @@ def test_get_projects_by_group_no_result(self): ) projects = lib.get_projects_by_group("SI") - self.assertIsNone(projects) + self.assertEqual([], projects) @responses.activate def test_get_projects_by_tag(self): @@ -435,7 +435,7 @@ def test_get_projects_by_tag_no_result(self): ) projects = lib.get_projects_by_tag("SI") - self.assertIsNone(projects) + self.assertEqual([], projects) @responses.activate def test_download_license_info(self):