diff --git a/.gitignore b/.gitignore
index b5a19b1..ec16573 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,3 +68,4 @@ RemoteSystemsTempFiles
.metadata
.settings
*.prefs
+.vscode/
diff --git a/plugins/googles.py b/plugins/google.py
similarity index 95%
rename from plugins/googles.py
rename to plugins/google.py
index 557d186..c0892b1 100644
--- a/plugins/googles.py
+++ b/plugins/google.py
@@ -36,6 +36,6 @@ class Plugin:
def __init__(self, app, conf):#
global app_emailharvester, config
#config = conf
- app.register_plugin('googles', {'search': search})
+ app.register_plugin('google', {'search': search})
app_emailharvester = app
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/test_emailharvester.py b/tests/test_emailharvester.py
new file mode 100644
index 0000000..7670ada
--- /dev/null
+++ b/tests/test_emailharvester.py
@@ -0,0 +1,103 @@
+import unittest
+from unittest.mock import MagicMock, patch, Mock
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+import EmailHarvester
+
+class TestEmailHarvester(unittest.TestCase):
+ def setUp(self):
+ self.userAgent = 'test-agent'
+ self.proxy = None
+ self.emailHarvester = EmailHarvester.EmailHarvester(self.userAgent, self.proxy)
+
+ def test_register_plugin(self):
+ mock_function = MagicMock()
+
+ self.emailHarvester.register_plugin('test_method', {'function': mock_function})
+
+ self.assertIn('test_method', self.emailHarvester.plugins)
+ self.assertEqual({'function': mock_function}, self.emailHarvester.plugins['test_method'])
+
+ def test_get_plugins(self):
+ mock_function1 = MagicMock()
+ self.emailHarvester.register_plugin('test_method1', {'function1': mock_function1})
+
+ mock_function2 = MagicMock()
+ self.emailHarvester.register_plugin('test_method2', {'function2': mock_function2})
+
+ self.assertEqual(self.emailHarvester.get_plugins(), self.emailHarvester.plugins)
+
+ @patch('builtins.print')
+ def test_show_message(self, mock_print):
+ test_message = "Test message"
+ self.emailHarvester.show_message(test_message)
+ mock_print.assert_called_once_with(test_message)
+
+ def test_init_search(self):
+ url = 'http://example.com/search?q={word}&start={counter}'
+ word = 'test'
+ limit = 100
+ counterInit = 0
+ counterStep = 10
+ engineName = 'Test-Engine'
+
+ self.emailHarvester.init_search(url, word, limit, counterInit, counterStep, engineName)
+
+ self.assertEqual(url, self.emailHarvester.url)
+ self.assertEqual(word, self.emailHarvester.word)
+ self.assertEqual(limit, self.emailHarvester.limit)
+ self.assertEqual(counterInit, self.emailHarvester.counter)
+ self.assertEqual(counterStep, self.emailHarvester.step)
+ self.assertEqual(engineName, self.emailHarvester.activeEngine)
+ self.assertEqual("",self.emailHarvester.results)
+ self.assertEqual("", self.emailHarvester.totalresults)
+
+ @patch('requests.get')
+ def test_do_search(self, mock_get):
+ url = "http://example.com/search?q={word}&start={counter}"
+ word = "test"
+ response_content = "Search results content"
+ mock_response = Mock()
+ mock_response.content = response_content.encode('utf-8')
+ mock_response.encoding = 'utf-8'
+ mock_get.return_value = mock_response
+
+ self.emailHarvester.init_search(url, word, 1, 0, 1, "ExampleEngine")
+ self.emailHarvester.do_search()
+
+ expected_url = url.format(counter = '0', word = word)
+ mock_get.assert_called_once_with(expected_url, headers={'User-Agent': self.userAgent})
+ self.assertEqual(response_content, self.emailHarvester.results)
+ self.assertEqual(response_content, self.emailHarvester.totalresults)
+
+ @patch('time.sleep', return_value = None)
+ @patch('requests.get')
+ @patch('builtins.print')
+ def test_process(self, mock_print, mock_get, mock_sleep):
+ url = "http://example.com/search?q={word}&start={counter}"
+ word = "test"
+ response_content = "Search results content"
+ mock_response = Mock()
+ mock_response.content = response_content.encode('utf-8')
+ mock_response.encoding = 'utf-8'
+ mock_get.return_value = mock_response
+
+ self.emailHarvester.init_search(url, word, 20, 0, 10, "ExampleEngine")
+ self.emailHarvester.process()
+
+ self.assertEqual(2, mock_get.call_count)
+ self.assertEqual(20, self.emailHarvester.counter)
+ self.assertEqual(response_content * 2, self.emailHarvester.totalresults)
+
+ def test_get_emails(self):
+ self.emailHarvester.totalresults = "Contact us at info@example.com and support@example.com"
+ self.emailHarvester.word = "example.com"
+ emails = self.emailHarvester.get_emails()
+ expected_emails = ["info@example.com", "support@example.com"]
+ self.assertEqual(set(expected_emails), set(emails))
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_myparser.py b/tests/test_myparser.py
new file mode 100644
index 0000000..585ffd5
--- /dev/null
+++ b/tests/test_myparser.py
@@ -0,0 +1,40 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+import EmailHarvester
+
+class TestMyParser(unittest.TestCase):
+ def setUp(self):
+ self.testParser = EmailHarvester.myparser()
+
+ def test_extract(self):
+ self.testParser.extract("some results", "example.com")
+ self.assertEqual("some results", self.testParser.results)
+ self.assertEqual("example.com", self.testParser.word)
+
+
+ def test_genericClean(self):
+ self.testParser.extract("test%2femail", "example.com")
+ self.testParser.genericClean()
+ expected_result = "test email"
+ self.assertEqual(expected_result, self.testParser.results)
+
+ def test_emails(self):
+ self.testParser.extract("Contact us at info@example.com and support@example.com", "example.com")
+ emails = self.testParser.emails()
+ expected_emails = ["info@example.com", "support@example.com"]
+ self.assertEqual(set(expected_emails), set(emails))
+
+ def test_unique(self):
+ self.testParser.temp = ["duplicate@example.com", "unique@example.com", "duplicate@example.com"]
+ unique_emails = self.testParser.unique()
+ expected_unique_emails = ["duplicate@example.com", "unique@example.com"]
+ self.assertEqual(set(expected_unique_emails), set(unique_emails))
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/__init__.py b/tests/test_plugins/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/test_plugins/test_ask.py b/tests/test_plugins/test_ask.py
new file mode 100644
index 0000000..8ee1e40
--- /dev/null
+++ b/tests/test_plugins/test_ask.py
@@ -0,0 +1,68 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.ask import Plugin, search, AskSearch
+
+class TestAskPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('ask', {'search': search})
+
+ @patch('plugins.ask.config', new_callable=dict)
+ @patch('plugins.ask.requests.get')
+ @patch('plugins.ask.app_emailharvester')
+ def test_search(self, mock_app_emailharvester, mock_requests_get, mock_config):
+ # Setup mock configuration
+ mock_config['proxy'] = None
+ mock_config['useragent'] = 'test-agent'
+
+ # Mock parser methods
+ mock_app_emailharvester.parser = MagicMock()
+ mock_app_emailharvester.parser.extract = MagicMock()
+ mock_app_emailharvester.parser.emails = MagicMock(return_value=['john_doe@email.com'])
+
+ # Mock the HTTP response from requests.get
+ mock_response = MagicMock()
+ mock_response.content.decode.return_value = "response content"
+ mock_response.encoding = 'utf-8'
+ mock_requests_get.return_value = mock_response
+
+ domain = "email.com"
+ limit = 10
+
+ # Execute the search function
+ result = search(domain, limit)
+
+ #---
+
+ expected_url_template = 'http://www.ask.com/web?q=%40{word}&page={page}'
+
+ # Extract called URLs from requests.get
+ urls_called = [call[0][0] for call in mock_requests_get.call_args_list]
+
+ # Generate expected URLs
+ expected_urls = [expected_url_template.format(word=domain, page=i+1) for i in range(limit // 10)]
+
+ # Verify that each expected URL was called
+ for expected_url in expected_urls:
+ self.assertIn(expected_url, urls_called, f"{expected_url} was not called")
+
+ #---
+
+ # Verify that the parser methods were called correctly
+ mock_app_emailharvester.parser.extract.assert_called_once_with("response content", domain)
+ mock_app_emailharvester.parser.emails.assert_called_once()
+
+ # Check the result of the search function
+ self.assertEqual(['john_doe@email.com'], result)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_baidu.py b/tests/test_plugins/test_baidu.py
new file mode 100644
index 0000000..3bdce55
--- /dev/null
+++ b/tests/test_plugins/test_baidu.py
@@ -0,0 +1,41 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.baidu import Plugin, search
+
+class TestBaiduPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('baidu', {'search': search})
+
+ @patch('plugins.baidu.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(return_value = ['john_doe@email.com'])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_url = 'http://www.baidu.com/search/s?wd="%40{word}"&pn={counter}'
+
+ mock_app_emailharvester.init_search(expected_url, domain, limit, 0, 10, 'Baidu')
+ mock_app_emailharvester.process.assert_called_once()
+ mock_app_emailharvester.get_emails.assert_called_once()
+
+ self.assertEqual(['john_doe@email.com'], result)
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_bing.py b/tests/test_plugins/test_bing.py
new file mode 100644
index 0000000..cb6db06
--- /dev/null
+++ b/tests/test_plugins/test_bing.py
@@ -0,0 +1,38 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.bing import Plugin, search
+
+class TestBingPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('bing', {'search': search})
+
+ @patch('plugins.bing.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(return_value = ['john_doe@email.com'])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_url = 'http://www.bing.com/search?q=%40{word}&count=50&first={counter}'
+
+ mock_app_emailharvester.init_search(expected_url, domain, limit, 0, 50, 'Bing')
+ mock_app_emailharvester.process.assert_called_once()
+ mock_app_emailharvester.get_emails.assert_called_once()
+
+ self.assertEqual(['john_doe@email.com'], result)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_dogpile.py b/tests/test_plugins/test_dogpile.py
new file mode 100644
index 0000000..ba0b656
--- /dev/null
+++ b/tests/test_plugins/test_dogpile.py
@@ -0,0 +1,38 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.dogpile import Plugin, search
+
+class TestDogpilePlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('dogpile', {'search': search})
+
+ @patch('plugins.dogpile.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(return_value = ['john_doe@email.com'])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_url = 'http://www.dogpile.com/search/web?qsi={counter}&q="%40{word}"'
+
+ mock_app_emailharvester.init_search(expected_url, domain, limit, 1, 10, 'Dogpile')
+ mock_app_emailharvester.process.assert_called_once()
+ mock_app_emailharvester.get_emails.assert_called_once()
+
+ self.assertEqual(['john_doe@email.com'], result)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_exalead.py b/tests/test_plugins/test_exalead.py
new file mode 100644
index 0000000..bc0e49e
--- /dev/null
+++ b/tests/test_plugins/test_exalead.py
@@ -0,0 +1,43 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.exalead import Plugin, search
+
+
+class TestExaleadPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('exalead', {'search': search})
+
+ @patch('plugins.exalead.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(return_value = ['john_doe@email.com'])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_url = 'http://www.exalead.com/search/web/results/?q=%40{word}&elements_per_page=10&start_index={counter}'
+
+ mock_app_emailharvester.init_search(expected_url, domain, limit, 0, 50, 'Exalead')
+ mock_app_emailharvester.process.assert_called_once()
+ mock_app_emailharvester.get_emails.assert_called_once()
+
+ self.assertEqual(['john_doe@email.com'], result)
+
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_github.py b/tests/test_plugins/test_github.py
new file mode 100644
index 0000000..8e56fe6
--- /dev/null
+++ b/tests/test_plugins/test_github.py
@@ -0,0 +1,50 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.github import Plugin, search
+
+class TestGitHubPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('github', {'search': search})
+
+ @patch('plugins.github.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.show_message = MagicMock()
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(side_effect=[
+ ['22@email.com', 'john.doe@email.com'],
+ [],
+ ['2212@email.com'],
+ [],
+ []
+ ])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_calls = [
+ unittest.mock.call('http://search.yahoo.com/search?p=site%3Agithub.com+%40{word}&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=0&fr=yfp-t-152&xargs=0&pstart=1&b={counter}', domain, limit, 1, 100, 'Yahoo + Github'),
+ unittest.mock.call('http://www.bing.com/search?q=site%3Agithub.com+%40{word}&count=50&first={counter}', domain, limit, 0, 50, 'Bing + Github'),
+ unittest.mock.call('https://www.google.com/search?num=100&start={counter}&hl=en&q=site%3Agithub.com+"%40{word}"', domain, limit, 0, 100, 'Google + Github'),
+ unittest.mock.call('http://www.baidu.com/search/s?wd=site%3Agithub.com+"%40{word}"&pn={counter}', domain, limit, 0, 10, 'Baidu + Github'),
+ unittest.mock.call('http://www.exalead.com/search/web/results/?q=site%3Agithub.com+%40{word}&elements_per_page=10&start_index={counter}', domain, limit, 0, 50, 'Exalead + Github')
+ ]
+
+ mock_app_emailharvester.init_search.assert_has_calls(expected_calls)
+
+ self.assertEqual(['22@email.com', 'john.doe@email.com', '2212@email.com'], result)
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_google.py b/tests/test_plugins/test_google.py
new file mode 100644
index 0000000..86162ae
--- /dev/null
+++ b/tests/test_plugins/test_google.py
@@ -0,0 +1,38 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.google import Plugin, search
+class TestGooglePlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('google', {'search': search})
+
+ @patch('plugins.google.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(return_value = ['john_doe@email.com'])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_url = 'https://www.google.com/search?num=100&start={counter}&hl=en&q="%40{word}"'
+
+ mock_app_emailharvester.init_search(expected_url, domain, limit, 0, 100, 'Google')
+ mock_app_emailharvester.process.assert_called_once()
+ mock_app_emailharvester.get_emails.assert_called_once()
+
+ self.assertEqual(['john_doe@email.com'], result)
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_googleplus.py b/tests/test_plugins/test_googleplus.py
new file mode 100644
index 0000000..c65c00c
--- /dev/null
+++ b/tests/test_plugins/test_googleplus.py
@@ -0,0 +1,38 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.googleplus import Plugin, search
+
+class TestGooglePlusPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('googleplus', {'search': search})
+
+ @patch('plugins.googleplus.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(return_value = ['john_doe@email.com'])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_url = 'https://www.google.com/search?num=100&start={counter}&hl=en&q=site%3Aplus.google.com+intext:"Works at"+-inurl:photos+-inurl:about+-inurl:posts+-inurl:plusones+%40{word}'
+
+ mock_app_emailharvester.init_search(expected_url, domain, limit, 0, 100, 'Google+')
+ mock_app_emailharvester.process.assert_called_once()
+ mock_app_emailharvester.get_emails.assert_called_once()
+
+ self.assertEqual(['john_doe@email.com'], result)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_instagram.py b/tests/test_plugins/test_instagram.py
new file mode 100644
index 0000000..41a5169
--- /dev/null
+++ b/tests/test_plugins/test_instagram.py
@@ -0,0 +1,50 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.instagram import Plugin, search
+
+class TestInstagramPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('instagram', {'search': search})
+
+ @patch('plugins.instagram.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.show_message = MagicMock()
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(side_effect=[
+ ['22@email.com', 'john.doe@email.com'],
+ [],
+ ['2212@email.com'],
+ [],
+ []
+ ])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_calls = [
+ unittest.mock.call('http://search.yahoo.com/search?p=site%3Ainstagram.com+%40{word}&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=0&fr=yfp-t-152&xargs=0&pstart=1&b={counter}', domain, limit, 1, 100, 'Yahoo + Instagram'),
+ unittest.mock.call('http://www.bing.com/search?q=site%3Ainstagram.com+%40{word}&count=50&first={counter}', domain, limit, 0, 50, 'Bing + Instagram'),
+ unittest.mock.call('https://www.google.com/search?num=100&start={counter}&hl=en&q=site%3Ainstagram.com+"%40{word}"', domain, limit, 0, 100, 'Google + Instagram'),
+ unittest.mock.call('http://www.baidu.com/search/s?wd=site%3Ainstagram.com+"%40{word}"&pn={counter}', domain, limit, 0, 10, 'Baidu + Instagram'),
+ unittest.mock.call('http://www.exalead.com/search/web/results/?q=site%3Ainstagram.com+%40{word}&elements_per_page=10&start_index={counter}', domain, limit, 0, 50, 'Exalead + Instagram')
+ ]
+
+ mock_app_emailharvester.init_search.assert_has_calls(expected_calls)
+
+ self.assertEqual(['22@email.com', 'john.doe@email.com', '2212@email.com'], result)
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_linkedin.py b/tests/test_plugins/test_linkedin.py
new file mode 100644
index 0000000..302f511
--- /dev/null
+++ b/tests/test_plugins/test_linkedin.py
@@ -0,0 +1,49 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.linkedin import Plugin, search
+
+class TestLinkedInPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('linkedin', {'search': search})
+
+ @patch('plugins.linkedin.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.show_message = MagicMock()
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(side_effect=[
+ ['22@email.com', 'john.doe@email.com'],
+ [],
+ ['2212@email.com'],
+ [],
+ []
+ ])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_calls = [
+ unittest.mock.call('http://search.yahoo.com/search?p=site%3Alinkedin.com+%40{word}&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=0&fr=yfp-t-152&xargs=0&pstart=1&b={counter}', domain, limit, 1, 100, 'Yahoo + Linkedin'),
+ unittest.mock.call('http://www.bing.com/search?q=site%3Alinkedin.com+%40{word}&count=50&first={counter}', domain, limit, 0, 50, 'Bing + Linkedin'),
+ unittest.mock.call('https://www.google.com/search?num=100&start={counter}&hl=en&q=site%3Alinkedin.com+"%40{word}"', domain, limit, 0, 100, 'Google + Linkedin'),
+ unittest.mock.call('http://www.baidu.com/search/s?wd=site%3Alinkedin.com+"%40{word}"&pn={counter}', domain, limit, 0, 10, 'Baidu + Linkedin'),
+ unittest.mock.call('http://www.exalead.com/search/web/results/?q=site%3Alinkedin.com+%40{word}&elements_per_page=10&start_index={counter}', domain, limit, 0, 50, 'Exalead + Linkedin')
+ ]
+
+ mock_app_emailharvester.init_search.assert_has_calls(expected_calls)
+
+ self.assertEqual(['22@email.com', 'john.doe@email.com', '2212@email.com'], result)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_reddit.py b/tests/test_plugins/test_reddit.py
new file mode 100644
index 0000000..3986b59
--- /dev/null
+++ b/tests/test_plugins/test_reddit.py
@@ -0,0 +1,49 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.reddit import Plugin, search
+
+class TestRedditPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('reddit', {'search': search})
+
+ @patch('plugins.reddit.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.show_message = MagicMock()
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(side_effect=[
+ ['22@email.com', 'john.doe@email.com'],
+ [],
+ ['2212@email.com'],
+ [],
+ []
+ ])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_calls = [
+ unittest.mock.call('http://search.yahoo.com/search?p=site%3Areddit.com+%40{word}&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=0&fr=yfp-t-152&xargs=0&pstart=1&b={counter}', domain, limit, 1, 100, 'Yahoo + Reddit'),
+ unittest.mock.call('http://www.bing.com/search?q=site%3Areddit.com+%40{word}&count=50&first={counter}', domain, limit, 0, 50, 'Bing + Reddit'),
+ unittest.mock.call('https://www.google.com/search?num=100&start={counter}&hl=en&q=site%3Areddit.com+"%40{word}"', domain, limit, 0, 100, 'Google + Reddit'),
+ unittest.mock.call('http://www.baidu.com/search/s?wd=site%3Areddit.com+"%40{word}"&pn={counter}', domain, limit, 0, 10, 'Baidu + Reddit'),
+ unittest.mock.call('http://www.exalead.com/search/web/results/?q=site%3Areddit.com+%40{word}&elements_per_page=10&start_index={counter}', domain, limit, 0, 50, 'Exalead + Reddit')
+ ]
+
+ mock_app_emailharvester.init_search.assert_has_calls(expected_calls)
+
+ self.assertEqual(['22@email.com', 'john.doe@email.com', '2212@email.com'], result)
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_twitter.py b/tests/test_plugins/test_twitter.py
new file mode 100644
index 0000000..45eed67
--- /dev/null
+++ b/tests/test_plugins/test_twitter.py
@@ -0,0 +1,50 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.twitter import Plugin, search
+
+class TestTwitterPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('twitter', {'search':search})
+
+ @patch('plugins.twitter.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.show_message = MagicMock()
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(side_effect=[
+ ['22@email.com', 'john.doe@email.com'],
+ [],
+ ['2212@email.com'],
+ [],
+ []
+ ])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_calls = [
+ unittest.mock.call('http://search.yahoo.com/search?p=site%3Atwitter.com+intitle:"on Twitter"+%40{word}&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=0&fr=yfp-t-152&xargs=0&pstart=1&b={counter}', domain, limit, 1, 100, 'Yahoo + Twitter'),
+ unittest.mock.call('http://www.bing.com/search?q=site%3Atwitter.com+intitle:"on Twitter"+%40{word}&count=50&first={counter}', domain, limit, 0, 50, 'Bing + Twitter'),
+ unittest.mock.call('https://www.google.com/search?num=100&start={counter}&hl=en&q=site%3Atwitter.com+intitle:"on Twitter"+"%40{word}"', domain, limit, 0, 100, 'Google + Twitter'),
+ unittest.mock.call('http://www.baidu.com/search/s?wd=site%3Atwitter.com+intitle:"on Twitter"+"%40{word}"&pn={counter}', domain, limit, 0, 10, 'Baidu + Twitter'),
+ unittest.mock.call('http://www.exalead.com/search/web/results/?q=site%3Atwitter.com+intitle:"on Twitter"+%40{word}&elements_per_page=10&start_index={counter}', domain, limit, 0, 50, 'Exalead + Twitter')
+ ]
+
+ mock_app_emailharvester.init_search.assert_has_calls(expected_calls)
+
+ self.assertEqual(['22@email.com', 'john.doe@email.com', '2212@email.com'], result)
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_yahoo.py b/tests/test_plugins/test_yahoo.py
new file mode 100644
index 0000000..6982827
--- /dev/null
+++ b/tests/test_plugins/test_yahoo.py
@@ -0,0 +1,40 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.yahoo import Plugin, search
+
+class TestYahooPlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('yahoo', {'search': search})
+
+ @patch('plugins.yahoo.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(return_value = ['john_doe@email.com'])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_url = "http://search.yahoo.com/search?p=%40{word}&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=0&fr=yfp-t-152&xargs=0&pstart=1&b={counter}"
+
+ mock_app_emailharvester.init_search(expected_url, domain, limit, 1, 100, 'Yahoo')
+ mock_app_emailharvester.process.assert_called_once()
+ mock_app_emailharvester.get_emails.assert_called_once()
+
+ self.assertEqual(['john_doe@email.com'], result)
+
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
diff --git a/tests/test_plugins/test_youtube.py b/tests/test_plugins/test_youtube.py
new file mode 100644
index 0000000..0b9cf3d
--- /dev/null
+++ b/tests/test_plugins/test_youtube.py
@@ -0,0 +1,50 @@
+import unittest
+from unittest.mock import MagicMock, patch
+import sys
+import os
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
+
+from plugins.youtube import Plugin, search
+
+class TestYoutubePlugin(unittest.TestCase):
+ def setUp(self):
+ self.app_mock = MagicMock()
+ self.config = {'useragent':'test-agent', 'proxy': None}
+ self.plugin = Plugin(self.app_mock, self.config)
+
+ def test_plugin_init(self):
+ self.app_mock.register_plugin.assert_called_once_with('youtube', {'search': search})
+
+ @patch('plugins.youtube.app_emailharvester')
+ def test_search(self, mock_app_emailharvester):
+ mock_app_emailharvester.show_message = MagicMock()
+ mock_app_emailharvester.init_search = MagicMock()
+ mock_app_emailharvester.process = MagicMock()
+ mock_app_emailharvester.get_emails = MagicMock(side_effect=[
+ ['22@email.com', 'john.doe@email.com'],
+ [],
+ ['2212@email.com'],
+ [],
+ []
+ ])
+
+ domain = "email.com"
+ limit = 10
+ result = search(domain,limit)
+
+ expected_calls = [
+ unittest.mock.call("http://search.yahoo.com/search?p=site%3Ayoutube.com+%40{word}&n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=0&fr=yfp-t-152&xargs=0&pstart=1&b={counter}", domain, limit, 1, 100, 'Yahoo + Youtube'),
+ unittest.mock.call("http://www.bing.com/search?q=site%3Ayoutube.com+%40{word}&count=50&first={counter}", domain, limit, 0, 50, 'Bing + Youtube'),
+ unittest.mock.call('https://www.google.com/search?num=100&start={counter}&hl=en&q=site%3Ayoutube.com+"%40{word}"', domain, limit, 0, 100, 'Google + Youtube'),
+ unittest.mock.call('http://www.baidu.com/search/s?wd=site%3Ayoutube.com+"%40{word}"&pn={counter}', domain, limit, 0, 10, 'Baidu + Youtube'),
+ unittest.mock.call("http://www.exalead.com/search/web/results/?q=site%3Ayoutube.com+%40{word}&elements_per_page=10&start_index={counter}", domain, limit, 0, 50, 'Exalead + Youtube')
+ ]
+
+ mock_app_emailharvester.init_search.assert_has_calls(expected_calls)
+
+ self.assertEqual(['22@email.com', 'john.doe@email.com', '2212@email.com'], result)
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file