From 37430a37d831095e3f0cbacc6c10abc0ffac25b1 Mon Sep 17 00:00:00 2001 From: 72004 Date: Sun, 18 Oct 2026 16:41:49 +0500 Subject: [PATCH 1/3] fix(folders): don't send "None" as the folder description create_folder() put f"{description}" into the folderDescription header, so a folder created without a description was stored with the literal description "None". Only send the header when a description is given, and add a mocked test for it. Signed-off-by: 72004 Assisted-by: Claude --- fossology/folders.py | 3 ++- tests/test_folders.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/fossology/folders.py b/fossology/folders.py index 76f18bf..00e64ec 100644 --- a/fossology/folders.py +++ b/fossology/folders.py @@ -98,8 +98,9 @@ def create_folder( headers = { "parentFolder": f"{parent.id}", "folderName": f"{name}", - "folderDescription": f"{description}", } + if description: + headers["folderDescription"] = description if group: headers["groupName"] = group diff --git a/tests/test_folders.py b/tests/test_folders.py index 35a5822..40c3a00 100644 --- a/tests/test_folders.py +++ b/tests/test_folders.py @@ -5,6 +5,7 @@ import time import pytest +import requests import responses from fossology import Fossology @@ -22,6 +23,41 @@ def test_list_folders_error(foss_server: str, foss: Fossology): assert f"Unable to get a list of folders for {foss.user.name}" in str(excinfo.value) +def _offline_foss(url: str) -> Fossology: + foss = Fossology.__new__(Fossology) + foss.api = f"{url}/api/v1" + foss.version = "v1" + foss.folders = [] + foss.session = requests.Session() + return foss + + +@responses.activate +def test_create_folder_without_description(): + url = "https://fossology.example.com/repo" + foss = _offline_foss(url) + responses.add( + responses.POST, + f"{url}/api/v1/folders", + json={"code": 201, "message": 42, "type": "INFO"}, + status=201, + ) + responses.add( + responses.GET, + f"{url}/api/v1/folders/42", + json={"id": 42, "name": "NoDesc", "description": "", "parent": 1}, + status=200, + ) + parent = Folder(1, "Software Repository", "Top folder", None) + + foss.create_folder(parent, "NoDesc") + + headers = responses.calls[0].request.headers + assert headers["folderName"] == "NoDesc" + # an unset description must not be sent as the literal string "None" + assert "folderDescription" not in headers + + def test_create_folder_nogroup(foss: Fossology): name = "FossPythonTest" desc = "Created via the Fossology Python API" From 976d2b5d25be6cc974934e72f4a38aaa4a6d8944 Mon Sep 17 00:00:00 2001 From: 72004 Date: Mon, 19 Oct 2026 22:12:40 +0500 Subject: [PATCH 2/3] test(folders): check folder without description on a real instance Replace the mocked test with one that uses the foss fixture, so the description stored by a running Fossology server is checked. It fails without the fix (the description is stored as 'None'). Assisted-by: Claude Signed-off-by: 72004 --- tests/test_folders.py | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/tests/test_folders.py b/tests/test_folders.py index 40c3a00..6bb6c29 100644 --- a/tests/test_folders.py +++ b/tests/test_folders.py @@ -5,7 +5,6 @@ import time import pytest -import requests import responses from fossology import Fossology @@ -23,39 +22,15 @@ def test_list_folders_error(foss_server: str, foss: Fossology): assert f"Unable to get a list of folders for {foss.user.name}" in str(excinfo.value) -def _offline_foss(url: str) -> Fossology: - foss = Fossology.__new__(Fossology) - foss.api = f"{url}/api/v1" - foss.version = "v1" - foss.folders = [] - foss.session = requests.Session() - return foss - - -@responses.activate -def test_create_folder_without_description(): - url = "https://fossology.example.com/repo" - foss = _offline_foss(url) - responses.add( - responses.POST, - f"{url}/api/v1/folders", - json={"code": 201, "message": 42, "type": "INFO"}, - status=201, - ) - responses.add( - responses.GET, - f"{url}/api/v1/folders/42", - json={"id": 42, "name": "NoDesc", "description": "", "parent": 1}, - status=200, - ) - parent = Folder(1, "Software Repository", "Top folder", None) - - foss.create_folder(parent, "NoDesc") +def test_create_folder_without_description(foss: Fossology): + name = "FossPythonTestNoDesc" + test_folder = foss.create_folder(foss.rootFolder, name) + assert test_folder.name == name + # an unset description must not be stored as the literal string "None" + assert test_folder.description == "" - headers = responses.calls[0].request.headers - assert headers["folderName"] == "NoDesc" - # an unset description must not be sent as the literal string "None" - assert "folderDescription" not in headers + # Cleanup + foss.delete_folder(test_folder) def test_create_folder_nogroup(foss: Fossology): From 92d71de22a05f3c674d6acdaac98f2d5432e177d Mon Sep 17 00:00:00 2001 From: 72004 Date: Tue, 27 Oct 2026 00:56:43 +0500 Subject: [PATCH 3/3] test(uploads): use upload ids that cannot exist in permission tests secrets.randbelow(192) can pick the id of an upload created earlier in the run, so the 'does not exist' test sometimes got a real upload back. Signed-off-by: 72004 Assisted-by: Claude --- tests/test_upload_permissions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_upload_permissions.py b/tests/test_upload_permissions.py index d1f3722..e7c9eb2 100644 --- a/tests/test_upload_permissions.py +++ b/tests/test_upload_permissions.py @@ -41,7 +41,7 @@ def test_get_upload_permissions_if_upload_does_not_exists_raise_api_error( upload = Upload( 1, "non-existing-folder", - secrets.randbelow(1092), + 1_000_000 + secrets.randbelow(1000), "non-existing upload", "none", "2023-08-07", @@ -91,7 +91,7 @@ def test_change_upload_permissions_if_upload_does_not_exists_raise_api_error( upload = Upload( 1, "non-existing-folder", - secrets.randbelow(192), + 1_000_000 + secrets.randbelow(1000), "non-existing upload", "none", "2023-08-07",