Skip to content

Conversation

@abdollahShahid
Copy link
Contributor

@abdollahShahid abdollahShahid commented Jan 3, 2026

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

  • Added test_list_users_v2 with full v2 constructor mock coverage
  • Mocked:
    • GET /api/v2/health
    • GET /api/v2/info
    • GET /api/v2/users/self
    • GET /api/v2/folders/{rootFolderId}
    • GET /api/v2/users

Testing

  • poetry run pytest tests/test_users.py -k list_users_v2 -vv

Checklist

  • Code follows existing style
  • Test passes locally
  • No breaking changes introduced
  • PR is ready for review

Related to #140

Copilot AI review requested due to automatic review settings January 3, 2026 14:01
Copy link

Copilot AI left a 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 with blocks 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.

abdollahShahid and others added 3 commits January 3, 2026 19:06
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>
@abdollahShahid
Copy link
Contributor Author

@deveaud-m kindly review this

@deveaud-m
Copy link
Collaborator

@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. heath_info and api_info_v2 like foss_user in conftest.py. In case the responses differen between v1 and v2, we amend the version number to the fixture.

We should also abstract the testcases using parametrization, e.g.:

@pytest.mark.parametrize("version, api_info", [
    ("v1", api_info_v1),
    ("v2", api_info_v2),
    ...	
])
def test_list_users(version, api_info, foss_user, foss_user_agents):
    ...
	responses.add(..., json=api_info)
	...
	foss = Fossology(foss_server, "test-token", version=version)
	users_from_api = foss.list_users()
	assert users_from_api

Does it make sense?

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