Skip to content

Conversation

@DEVANSH-GAJJAR
Copy link

@DEVANSH-GAJJAR DEVANSH-GAJJAR commented Jan 6, 2026

Description

This PR implements the list_folders_v2 method in fossology/folders.py to extend support for the Fossology API v2.

Currently, the wrapper defaults to v1 endpoints. This implementation allows users to fetch folder lists using the new v2 structure by dynamically adjusting the API base URL.

Changes

  • Added list_folders_v2 method to the Folders class.
  • Implemented URL logic to switch from .../api/v1 to .../api/v2 dynamically.
  • Added response parsing to handle the V2 JSON list format and return Folder objects.

Related Issue

Relates to #140

Testing & Verification

  • Static Analysis: Verified syntax validity (py_compile) and successful import (from fossology.folders import Folders).
  • Unit Tests: I encountered some local environment issues setting up the pytest mock server infrastructure.
    • Note to Reviewers: I have opened this PR to get feedback on the implementation logic first. I am happy to add the responses mock test once I resolve the local setup or with guidance on the preferred testing pattern for v2.

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation (docstrings) accordingly.
  • I have read the CONTRIBUTING document.

@deveaud-m
Copy link
Collaborator

@DEVANSH-GAJJAR welcome to Fossology Python and thanks for starting this PR.

I would like to avoid duplicating all the methods just to support v2 because I think most of the content will be similar, only some endpoints will only be available for one version or the other.

I started doing a little bit of refactoring in preparation to supporting v2 in this PR: https://github.com/fossology/fossology-python/pull/162/files#diff-df2ec7af328aecf9da4e6ef7c9d4a7515e50c73a692d5857c8fc20f970bd3068R133.

The targeted version shall be given during instanciation of the Fossology class using the version parameter.

If the response diverge between v1 and v2, we should use a slightly adapted object factory, e.g.:

# fossology/obj.py
class FolderFactory:
    @staticmethod
    def from_json(version, data):
        if version == "v2":
            return Folder.from_json_v2(data)
        return Folder.from_json(data)
...
class Folders:
    """Class dedicated to all "folders" related endpoints"""

    def list_folders(self):
        response = self.session.get(f"{self.api}/folders")
        if response.status_code == 200:
            folders_list = list()
            response_list = response.json()
            for folder in response_list:
				if self.version == "v2":
                	sub_folder = FolderFactory.from_json_v2(self.version, folder)
				else:
					sub_folder = FolderFactory.from_json(self.version, folder)
                folders_list.append(sub_folder)
            return folders_list
        else:
            description = f"Unable to get a list of folders for {self.user.name}"
            raise FossologyApiError(description, response)

Could you give it a shot once you rebased on top of #162?

@DEVANSH-GAJJAR
Copy link
Author

DEVANSH-GAJJAR commented Jan 20, 2026

Hi there @deveaud-m ,
could you please trigger the CI checks or let me know if any further changes are needed from my side?

@deveaud-m
Copy link
Collaborator

Hi there @deveaud-m , could you please trigger the CI checks or let me know if any further changes are needed from my side?

@DEVANSH-GAJJAR Unfortunately some tests are failing, I suppose the logic of the endpoint changed between v1 and v2.

Are you able to test the endpoints locally on your machine? This should help get the tests correctly.

Let me know if you need help and if I shall take over this PR.

@DEVANSH-GAJJAR
Copy link
Author

Thanks for checking and for the suggestion.

You’re right — the behavior differs between v1 and v2. I’ve identified that the current CI failures are due to missing mocks for the /api/v2/folders endpoints rather than an issue with the endpoint logic itself. I’m testing this locally and updating the tests/mocks accordingly. I’ll push the fixes shortly.

Thanks a lot for offering help — I’d like to take care of this and will reach out if I need assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants