-
Notifications
You must be signed in to change notification settings - Fork 13
test: mock v2 init endpoints for list_users_v2 #157
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?
test: mock v2 init endpoints for list_users_v2 #157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@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