Skip to content

Commit

Permalink
feat: fix remaining type hint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
t-graf committed Dec 8, 2023
1 parent 97367d2 commit 9d3798d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
5 changes: 3 additions & 2 deletions sw360/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sw360/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions tests/test_sw360_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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"])
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/test_sw360_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_sw360_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 9d3798d

Please sign in to comment.