Skip to content

Commit a3b9540

Browse files
committed
fix: delete methods are more resilient for SW360 responses
1 parent 8047b05 commit a3b9540

9 files changed

Lines changed: 41 additions & 15 deletions

File tree

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
# SW360 Base Library for Python
77

8+
## V1.8.1
9+
10+
* `delete_project` now works properly. Before it could have happened the you get a `JSONDecodeError`.
11+
All delete methodds have been checked and made more resilient.
12+
* dependency updates.
13+
814
## V1.8.0
915

1016
* Update `get_all_releases` to include `isNewClearingWithSourceAvailable` parameter:

sw360/components.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# Copyright (c) 2019-2024 Siemens
2+
# Copyright (c) 2019-2025 Siemens
33
# Copyright (c) 2022 BMW CarIT GmbH
44
# All Rights Reserved.
55
# Authors: thomas.graf@siemens.com, gernot.hillier@siemens.com
@@ -313,7 +313,8 @@ def delete_component(self, component_id: str) -> Optional[Dict[str, Any]]:
313313
response = self.api_delete(url)
314314
if response is not None:
315315
if response.ok:
316-
return response.json()
316+
if response.text:
317+
return response.json()
317318
return None
318319

319320
def get_users_of_component(self, component_id: str) -> Optional[Dict[str, Any]]:

sw360/license.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# Copyright (c) 2019-2022 Siemens
2+
# Copyright (c) 2019-2025 Siemens
33
# Copyright (c) 2022 BMW CarIT GmbH
44
# All Rights Reserved.
55
# Authors: thomas.graf@siemens.com, gernot.hillier@siemens.com
@@ -68,6 +68,8 @@ def delete_license(self, license_shortname: str) -> Optional[bool]:
6868
:raises SW360Error: if there is a negative HTTP response
6969
"""
7070

71+
# 2025-01-23: returns 500 - internal server error
72+
7173
if not license_shortname:
7274
raise SW360Error(message="No license shortname provided!")
7375

sw360/project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ def delete_project(self, project_id: str) -> Optional[Dict[str, Any]]:
437437
response = self.api_delete(url)
438438
if response is not None:
439439
if response.ok:
440-
return response.json()
440+
if response.text:
441+
return response.json()
441442
return None
442443

443444
def get_users_of_project(self, project_id: str) -> Optional[Dict[str, Any]]:

sw360/releases.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# Copyright (c) 2019-2024 Siemens
2+
# Copyright (c) 2019-2025 Siemens
33
# Copyright (c) 2022 BMW CarIT GmbH
44
# All Rights Reserved.
55
# Authors: thomas.graf@siemens.com, gernot.hillier@siemens.com
@@ -239,7 +239,8 @@ def delete_release(self, release_id: str) -> Optional[Dict[str, Any]]:
239239
response = self.api_delete(url)
240240
if response is not None:
241241
if response.ok:
242-
return response.json()
242+
if response.text:
243+
return response.json()
243244
return None
244245

245246
def get_users_of_release(self, release_id: str) -> Optional[Dict[str, Any]]:

sw360/vendor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# Copyright (c) 2019-2023 Siemens
2+
# Copyright (c) 2019-2025 Siemens
33
# Copyright (c) 2022 BMW CarIT GmbH
44
# All Rights Reserved.
55
# Authors: thomas.graf@siemens.com, gernot.hillier@siemens.com
@@ -93,7 +93,7 @@ def delete_vendor(self, vendor_id: str) -> Dict[str, Any]:
9393
:raises SW360Error: if there is a negative HTTP response
9494
"""
9595

96-
# 2019-04-03: error 405 - not allowed
96+
# 2019-04-03/2025-01-23: error 405 - not allowed
9797

9898
if not vendor_id:
9999
raise SW360Error(message="No vendor id provided!")
@@ -103,5 +103,7 @@ def delete_vendor(self, vendor_id: str) -> Dict[str, Any]:
103103
response = self.api_delete(url)
104104
if response is not None:
105105
if response.ok:
106-
return response.json()
107-
raise SW360Error(response, url)
106+
if response.text:
107+
return response.json()
108+
109+
return None

tests/test_sw360_components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# Copyright (c) 2020-2024 Siemens
2+
# Copyright (c) 2020-2025 Siemens
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -767,7 +767,7 @@ def test_delete_component(self) -> None:
767767
responses.add(
768768
responses.DELETE,
769769
url=self.MYURL + "resource/api/components/123",
770-
body="4",
770+
body='{\n "resourceId" : "468abcd6e7f849199d9323c9a16b2776",\n "status" : 200\n}',
771771
status=200,
772772
)
773773

tests/test_sw360_projects.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# Copyright (c) 2019-2024 Siemens
2+
# Copyright (c) 2019-2025 Siemens
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -1118,6 +1118,19 @@ def test_delete_project(self) -> None:
11181118

11191119
lib.delete_project("123")
11201120

1121+
@responses.activate
1122+
def test_delete_project_empty_response(self) -> None:
1123+
lib = self.get_logged_in_lib()
1124+
1125+
responses.add(
1126+
responses.DELETE,
1127+
url=self.MYURL + "resource/api/projects/123",
1128+
body="",
1129+
status=200,
1130+
)
1131+
1132+
lib.delete_project("123")
1133+
11211134
@responses.activate
11221135
def test_delete_project_no_id(self) -> None:
11231136
lib = self.get_logged_in_lib()

tests/test_sw360_releases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# Copyright (c) 2023-2024 Siemens
2+
# Copyright (c) 2023-2025 Siemens
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -530,7 +530,7 @@ def test_delete_release(self) -> None:
530530
responses.add(
531531
responses.DELETE,
532532
url=self.MYURL + "resource/api/releases/123",
533-
body="4",
533+
body='{\n "resourceId" : "8ddc6d15e0c4424ea756b8e0b77ad1e9",\n "status" : 200\n}',
534534
status=200,
535535
)
536536

0 commit comments

Comments
 (0)