-
Notifications
You must be signed in to change notification settings - Fork 13
feat(folders): implement list_folders_v2 for API v2 support (#140) #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@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 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? |
da9d0b1 to
b0ba553
Compare
|
Hi there @deveaud-m , |
@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. |
|
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. |
Description
This PR implements the
list_folders_v2method infossology/folders.pyto 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
list_folders_v2method to theFoldersclass..../api/v1to.../api/v2dynamically.Folderobjects.Related Issue
Relates to #140
Testing & Verification
py_compile) and successful import (from fossology.folders import Folders).pytestmock server infrastructure.responsesmock test once I resolve the local setup or with guidance on the preferred testing pattern for v2.Checklist