Skip to content

Commit 74248cd

Browse files
committed
Updates to unit tests
1 parent 261210c commit 74248cd

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ version = 2
2727
2828
response = diffbot.request(url, token, api, version=2)
2929
```
30+
31+
Testing
32+
------------
33+
34+
Unit and integration tests are configured to run using nose. From the project directory, simply run:
35+
36+
$ nosetests

test.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/__init__.py

Whitespace-only changes.
File renamed without changes.

tests/unit_test.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import urlparse
3+
import unittest
4+
import simplejson
5+
import logging
6+
import requests
7+
from mock import Mock, patch
8+
9+
from client import DiffbotClient
10+
11+
12+
logger = logging.getLogger(__name__)
13+
14+
15+
def fake_get(url, params):
16+
path = urlparse.urlparse(url).path
17+
path_tuple = os.path.split(path)
18+
api = path_tuple[len(path_tuple) - 1]
19+
resource_file = os.path.normpath('tests/test_fixtures/%s.json' % api)
20+
with open(resource_file, mode='rb') as file:
21+
json = file.read()
22+
r = requests.Response()
23+
r.status_code = 200
24+
r._content = json
25+
return r
26+
27+
28+
class DiffbotClientUnitTest(unittest.TestCase):
29+
30+
def setUp(self):
31+
self.patcher = patch('client.requests.get', fake_get)
32+
self.patcher.start()
33+
self.client = DiffbotClient()
34+
35+
def tearDown(self):
36+
self.patcher.stop()
37+
38+
def test_request_for_article(self):
39+
url = "http://shichuan.github.io/javascript-patterns/"
40+
token = "3c66f28f72ea40c1b02e6a4cc195b07e"
41+
api = "article"
42+
version = 2
43+
response = self.client.request(url, token, api, version=version)
44+
self.assertIn('text', response)
45+
self.assertEqual(response['meta']['title'], 'JavaScript Patterns')
46+
47+
48+
if __name__ == '__main__':
49+
unittest.main()

0 commit comments

Comments
 (0)