test: mock v2 init endpoints for list_users_v2#157
test: mock v2 init endpoints for list_users_v2#157abdollahShahid wants to merge 4 commits intofossology:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a dedicated unit test for the v2 API list_users() method that mocks all initialization endpoints required by the Fossology(version="v2") constructor. Additionally, it includes code quality improvements: fixing indentation of assert statements in exception tests and simplifying variable usage by directly using fixture values instead of intermediate variables.
- Added comprehensive mocking for v2 API initialization (
/health,/info,/users/self,/folders,/folders/{id}) - Fixed indentation of assert statements in three existing tests (moved outside
withblocks as per pytest conventions) - Simplified code by eliminating unnecessary intermediate variables in test functions
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
@deveaud-m kindly review this |
|
@abdollahShahid thanks for the PR and for jumping right a way into v2 testing. Mocking the API responses is a breaking change in the current testing concept since primarily this Python module was used to validate the Fossology API using a locally running server. But nowadays the Fossology project implements its own API tests, so let's move on with using mocks, this should help stabilize the testsuite for unreliable jobs runs. Now regarding your testcase: we should define the API responses as fixtures to re-use them all over the testsuite, e.g. We should also abstract the testcases using parametrization, e.g.: Does it make sense? |
Summary
Adds a dedicated test for API v2
list_users()that mocks all Fossology v2 initialization calls (/health,/info,/users/self,/folders/{rootFolderId}) so the test runs without requiring a real server.Why
When running tests with
Fossology(version="v2"), the constructor triggers multiple API requests automatically. Without mocking these, tests fail due to unregistered HTTP calls.What Changed
test_list_users_v2with full v2 constructor mock coverageGET /api/v2/healthGET /api/v2/infoGET /api/v2/users/selfGET /api/v2/folders/{rootFolderId}GET /api/v2/usersTesting
poetry run pytest tests/test_users.py -k list_users_v2 -vvChecklist
Related to #140