diff options
| author | Adam Tauber <asciimoo@gmail.com> | 2016-01-02 11:14:49 +0100 |
|---|---|---|
| committer | Adam Tauber <asciimoo@gmail.com> | 2016-01-10 19:23:10 +0100 |
| commit | 53979a7bf7669c803c2a493fbf136519f6a293e6 (patch) | |
| tree | 3b79da9408699108ba89b22cedf73cfff1fe59b7 /tests/unit/engines/test_github.py | |
| parent | f9186344b3642fb3d55d2dc46c96c6b25b8ccf41 (diff) | |
[mod] remove buildout/makefile infrastructure
Diffstat (limited to 'tests/unit/engines/test_github.py')
| -rw-r--r-- | tests/unit/engines/test_github.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/unit/engines/test_github.py b/tests/unit/engines/test_github.py new file mode 100644 index 000000000..460be8c3d --- /dev/null +++ b/tests/unit/engines/test_github.py @@ -0,0 +1,61 @@ +from collections import defaultdict +import mock +from searx.engines import github +from searx.testing import SearxTestCase + + +class TestGitHubEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + params = github.request(query, defaultdict(dict)) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('github.com' in params['url']) + self.assertEqual(params['headers']['Accept'], github.accept_header) + + def test_response(self): + self.assertRaises(AttributeError, github.response, None) + self.assertRaises(AttributeError, github.response, []) + self.assertRaises(AttributeError, github.response, '') + self.assertRaises(AttributeError, github.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(github.response(response), []) + + response = mock.Mock(text='{"items": []}') + self.assertEqual(github.response(response), []) + + json = """ + { + "items": [ + { + "name": "title", + "html_url": "url", + "description": "" + } + ] + } + """ + response = mock.Mock(text=json) + results = github.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'title') + self.assertEqual(results[0]['url'], 'url') + self.assertEqual(results[0]['content'], '') + + json = """ + { + "items": [ + { + "name": "title", + "html_url": "url", + "description": "desc" + } + ] + } + """ + response = mock.Mock(text=json) + results = github.response(response) + self.assertEqual(results[0]['content'], "desc") |