mirror of
https://github.com/laramies/theHarvester.git
synced 2024-11-14 19:45:53 +08:00
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
|
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
|
||
|
|
||
|
|
||
|
class TestSearchGithubCode:
|
||
|
|
||
|
def test_missing_key(self):
|
||
|
with pytest.raises(MissingKey):
|
||
|
githubcode.SearchGithubCode(word="test", limit=500)
|
||
|
|
||
|
|
||
|
def test_fragments_from_response(self):
|
||
|
Core.github_key = MagicMock(return_value="lol")
|
||
|
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||
|
response = Response()
|
||
|
json = {
|
||
|
"items": [
|
||
|
{
|
||
|
"text_matches": [
|
||
|
{
|
||
|
"fragment": "test1"
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"text_matches": [
|
||
|
{
|
||
|
"fragment": "test2"
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
response.json = MagicMock(return_value=json)
|
||
|
test_result = test_class_instance.fragments_from_response(response)
|
||
|
assert test_result == ["test1", "test2"]
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
pytest.main()
|
||
|
|