Skip to content

Commit

Permalink
Add async pagination helper and update pytest settings
Browse files Browse the repository at this point in the history
Introduce the `next_page_or_end` method in `githubcode.py` to handle pagination. Additionally, modify the test case and upgrade pytest settings in `pyproject.toml` to the latest versions, ensuring compatibility and updated configurations.
  • Loading branch information
L1ghtn1ng committed Oct 27, 2024
1 parent c18012d commit 13a0cdd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ include = ["theHarvester*"]
"*" = ["*.txt", "*.yaml"]

[tool.pytest.ini_options]
minversion = "7.1.1"
addopts = "--no-header --asyncio-mode=auto"
minversion = "8.3.3"
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
addopts = "--no-header"
testpaths = [
"tests",
"tests/discovery/",
Expand Down
3 changes: 1 addition & 2 deletions tests/discovery/test_githubcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ async def test_last_page(self) -> None:
Core.github_key = MagicMock(return_value="lol")
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
test_result = githubcode.SuccessResult(list(), None, None)
assert None is await test_class_instance.next_page_or_end(test_result)

assert await test_class_instance.next_page_or_end(test_result) is None
if __name__ == "__main__":
pytest.main()
7 changes: 7 additions & 0 deletions theHarvester/discovery/githubcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ async def handle_response(self, response: tuple[str, dict, int, Any]) -> ErrorRe
print(f'Error handling response: {e}')
return ErrorResult(500, str(e))

@staticmethod
async def next_page_or_end(result: SuccessResult) -> int | None:
if result.next_page is not None:
return result.next_page
else:
return result.last_page

async def do_search(self, page: int) -> tuple[str, dict, int, Any]:
try:
url = f'{self.base_url}&page={page}' if page else self.base_url
Expand Down

0 comments on commit 13a0cdd

Please sign in to comment.