Skip to content

Commit

Permalink
Issue #2: Search on Google (tests).
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Sep 20, 2018
1 parent f7e2f9e commit 2398a27
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion dirhunt/tests/test_sources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import unittest
from urllib.error import URLError

import requests_mock

from dirhunt.sources import Robots, VirusTotal
from dirhunt.sources import Robots, VirusTotal, Google
from dirhunt.sources.google import STOP_AFTER
from dirhunt.sources.robots import DirhuntRobotFileParser
from dirhunt.sources.virustotal import VT_URL, ABUSE
from dirhunt.tests._compat import patch, call
Expand Down Expand Up @@ -74,3 +77,25 @@ def test_abuse(self, m):
with patch.object(VirusTotal, 'add_error') as mock_add_error:
VirusTotal(lambda x: x, lambda x: x).callback(domain)
mock_add_error.assert_called()


class TestGoogle(unittest.TestCase):

@patch.object(Google, 'add_result')
def test_search(self, m1):
domain = 'domain'
urls = ['http://domain/path1', 'http://domain/path2']

with patch('dirhunt.sources.google.search', side_effect=lambda x, stop: iter(urls)) as m2:
Google(lambda x: x, None).callback(domain)
m2.assert_called_once_with('site:{}'.format(domain), stop=STOP_AFTER)
m1.assert_has_calls([call(url) for url in urls])

@patch.object(Google, 'add_error')
def test_failure(self, m1):
def search_iter(*args):
raise URLError('Test')

with patch('dirhunt.sources.google.search', return_value=map(search_iter, [0])):
Google(lambda x: x, lambda x: x).callback('domain')
m1.assert_called_once()

0 comments on commit 2398a27

Please sign in to comment.