From 19391b9d8f17c93c86c1f5ed4ef73344192bf9f4 Mon Sep 17 00:00:00 2001 From: NotoriousRebel Date: Thu, 13 Feb 2020 16:03:02 -0500 Subject: [PATCH] Updated github tests most are passing. --- tests/discovery/test_githubcode.py | 15 ++++++++------- theHarvester/discovery/githubcode.py | 4 +++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/discovery/test_githubcode.py b/tests/discovery/test_githubcode.py index 78ad60d0..24644256 100644 --- a/tests/discovery/test_githubcode.py +++ b/tests/discovery/test_githubcode.py @@ -74,35 +74,36 @@ class TestSearchGithubCode: async def test_fragments_from_response(self): Core.github_key = MagicMock(return_value="lol") test_class_instance = githubcode.SearchGithubCode(word="test", limit=500) - test_result = test_class_instance.fragments_from_response(self.OkResponse.response) + test_result = await test_class_instance.fragments_from_response(self.OkResponse.response.json()) + print('test_result: ', test_result) assert test_result == ["test1", "test2"] @pytest.mark.asyncio async def test_invalid_fragments_from_response(self): Core.github_key = MagicMock(return_value="lol") test_class_instance = githubcode.SearchGithubCode(word="test", limit=500) - test_result = test_class_instance.fragments_from_response(self.MalformedResponse.response) + test_result = await test_class_instance.fragments_from_response(self.MalformedResponse.response.json()) assert test_result == [] @pytest.mark.asyncio async def test_handle_response_ok(self): Core.github_key = MagicMock(return_value="lol") test_class_instance = githubcode.SearchGithubCode(word="test", limit=500) - test_result = test_class_instance.handle_response(self.OkResponse.response) + test_result = await test_class_instance.handle_response() assert isinstance(test_result, SuccessResult) @pytest.mark.asyncio async def test_handle_response_retry(self): Core.github_key = MagicMock(return_value="lol") test_class_instance = githubcode.SearchGithubCode(word="test", limit=500) - test_result = test_class_instance.handle_response(self.RetryResponse.response) + test_result = await test_class_instance.handle_response(self.RetryResponse.response.json()) assert isinstance(test_result, RetryResult) @pytest.mark.asyncio async def test_handle_response_fail(self): Core.github_key = MagicMock(return_value="lol") test_class_instance = githubcode.SearchGithubCode(word="test", limit=500) - test_result = test_class_instance.handle_response(self.FailureResponse.response) + test_result = await test_class_instance.handle_response(self.FailureResponse.response.json()) assert isinstance(test_result, ErrorResult) @pytest.mark.asyncio @@ -110,14 +111,14 @@ class TestSearchGithubCode: Core.github_key = MagicMock(return_value="lol") test_class_instance = githubcode.SearchGithubCode(word="test", limit=500) test_result = githubcode.SuccessResult(list(), next_page=2, last_page=4) - assert(2 == test_class_instance.next_page_or_end(test_result)) + assert(2 == await test_class_instance.next_page_or_end(test_result)) @pytest.mark.asyncio async def test_last_page(self): 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 test_class_instance.next_page_or_end(test_result)) + assert(None is await test_class_instance.next_page_or_end(test_result)) if __name__ == '__main__': pytest.main() diff --git a/theHarvester/discovery/githubcode.py b/theHarvester/discovery/githubcode.py index cf21dae5..f081b452 100644 --- a/theHarvester/discovery/githubcode.py +++ b/theHarvester/discovery/githubcode.py @@ -7,6 +7,7 @@ import aiohttp import urllib.parse as urlparse import random + class RetryResult(NamedTuple): time: float @@ -94,8 +95,9 @@ class SearchGithubCode: async with sess.get(url, proxy=random.choice(Core.proxy_list())) as resp: return await resp.text(), await resp.json(), resp.status, resp.links else: - async with sess.get(url, ) as resp: + async with sess.get(url) as resp: return await resp.text(), await resp.json(), resp.status, resp.links + @staticmethod async def next_page_or_end(result: SuccessResult) -> Optional[int]: if result.next_page is not None: