GitAuto: Add an integration test to is_repo_forked() in services/github/repo_manager.py #533
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #516
Why is this feature needed?
This integration test is required to verify that the function is_repo_forked in services/github/repo_manager.py correctly identifies a forked repository using the GitHub API. It enhances our test coverage and ensures our logic works as expected when interfacing with GitHub.
What and how are we changing? Why this approach?
• Added a new constant, FORKED_REPO = "DeepSeek-R1", in tests/constants.py.
• Created an integration test in tests/services/github/test_repo_manager.py that:
This approach leverages the actual GitHub API, ensuring that our function interacts as expected with the external service while maintaining control over the test environment.
What actions are required from users?
Users (or CI pipelines) must supply a valid GITHUB_TOKEN as an environment variable for this integration test to run. If the token is missing, the test will be skipped.
How does it work? (Technical details)
• The test imports the function is_repo_forked from services/github/repo_manager.py along with the forked repository constant from tests/constants.py.
• It retrieves GITHUB_TOKEN from the environment using os.getenv().
• If no token exists, pytest.skip is invoked to avoid test failure in local environments missing the token.
• With the token present, the test calls is_repo_forked(FORKED_REPO, token=token) and asserts that the returned result is True, ensuring that the repository "DeepSeek-R1" is identified as forked.
• The test uses the GitHub API documentation as a reference for expected behavior.
Is it backwards compatible?
Yes, the changes are fully backwards compatible. The addition of a constant and an integration test does not impact the existing functionality. Moreover, the test is self-contained and conditional, ensuring no disruptions in environments without a GITHUB_TOKEN.
Any other considerations?
• This integration test depends on the network and the availability of the GitHub API.
• Future improvements may consider adding more tests for different repository types (e.g., non-forked repositories) or mocking the GitHub API responses to facilitate testing without external dependencies.
• Ensure that the GITHUB_TOKEN provided has sufficient permissions to access repository details on GitHub.