From 26c151dd3f40d8e0520fc3128fee25f285b98758 Mon Sep 17 00:00:00 2001 From: Cameron Ruatta Date: Sat, 15 Jun 2019 21:46:56 -0700 Subject: [PATCH] Adding tests --- tests/discovery/__init__.py | 0 tests/discovery/test_githubcode.py | 44 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/discovery/__init__.py create mode 100644 tests/discovery/test_githubcode.py diff --git a/tests/discovery/__init__.py b/tests/discovery/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/discovery/test_githubcode.py b/tests/discovery/test_githubcode.py new file mode 100644 index 00000000..275b9100 --- /dev/null +++ b/tests/discovery/test_githubcode.py @@ -0,0 +1,44 @@ +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() +