mirror of
https://github.com/laramies/theHarvester.git
synced 2026-09-13 13:17:41 +02:00
#1492 run black . and isort .
This commit is contained in:
@@ -1,34 +1,23 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from requests import Response
|
||||
|
||||
from theHarvester.discovery import githubcode
|
||||
from theHarvester.discovery.constants import MissingKey
|
||||
from theHarvester.lib.core import Core
|
||||
from unittest.mock import MagicMock
|
||||
from requests import Response
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
|
||||
pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestSearchGithubCode:
|
||||
|
||||
class OkResponse:
|
||||
response = Response()
|
||||
json = {
|
||||
"items": [
|
||||
{
|
||||
"text_matches": [
|
||||
{
|
||||
"fragment": "test1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"text_matches": [
|
||||
{
|
||||
"fragment": "test2"
|
||||
}
|
||||
]
|
||||
}
|
||||
{"text_matches": [{"fragment": "test1"}]},
|
||||
{"text_matches": [{"fragment": "test2"}]},
|
||||
]
|
||||
}
|
||||
response.status_code = 200
|
||||
@@ -48,19 +37,9 @@ class TestSearchGithubCode:
|
||||
response = Response()
|
||||
json = {
|
||||
"items": [
|
||||
{
|
||||
"fail": True
|
||||
},
|
||||
{
|
||||
"text_matches": []
|
||||
},
|
||||
{
|
||||
"text_matches": [
|
||||
{
|
||||
"weird": "result"
|
||||
}
|
||||
]
|
||||
}
|
||||
{"fail": True},
|
||||
{"text_matches": []},
|
||||
{"text_matches": [{"weird": "result"}]},
|
||||
]
|
||||
}
|
||||
response.json = MagicMock(return_value=json)
|
||||
@@ -74,27 +53,31 @@ class TestSearchGithubCode:
|
||||
async def test_fragments_from_response(self) -> None:
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = await test_class_instance.fragments_from_response(self.OkResponse.response.json())
|
||||
print('test_result: ', test_result)
|
||||
test_result = await test_class_instance.fragments_from_response(
|
||||
self.OkResponse.response.json()
|
||||
)
|
||||
print("test_result: ", test_result)
|
||||
assert test_result == ["test1", "test2"]
|
||||
|
||||
async def test_invalid_fragments_from_response(self) -> None:
|
||||
Core.github_key = MagicMock(return_value="lol")
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = await test_class_instance.fragments_from_response(self.MalformedResponse.response.json())
|
||||
test_result = await test_class_instance.fragments_from_response(
|
||||
self.MalformedResponse.response.json()
|
||||
)
|
||||
assert test_result == []
|
||||
|
||||
async def test_next_page(self) -> None:
|
||||
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 == await test_class_instance.next_page_or_end(test_result))
|
||||
assert 2 == await test_class_instance.next_page_or_end(test_result)
|
||||
|
||||
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 None is await test_class_instance.next_page_or_end(test_result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
pytest.main()
|
||||
|
||||
Reference in New Issue
Block a user