Skip to content

Commit 11a2fdd

Browse files
committed
Added new unit tests
1 parent f7d73fe commit 11a2fdd

File tree

8 files changed

+2324
-195
lines changed

8 files changed

+2324
-195
lines changed

client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def request(self, url, token, api, fields=[], version=2):
1111
"""
1212
params = {"url": url, "token": token}
1313
response = requests.get(self.compose_url(api, version), params=params)
14+
print response.content
1415
obj = response.json()
1516
obj = self.select_fields_from_response(obj, fields)
1617
return obj

test_requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mock==1.0.1
22
nose==1.3.0
33
requests==2.1.0
4-
simplejson==3.3.1
5-
httmock==1.1.1
4+
simplejson==3.3.1

tests/test_fixtures/analyze.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"title": "Welcome to Twitter.",
3+
"images": [],
4+
"type": "image",
5+
"resolved_url": "https://twitter.com/",
6+
"human_language": "en",
7+
"url": "https://www.twitter.com/"
8+
}

tests/test_fixtures/article.json

Lines changed: 18 additions & 189 deletions
Large diffs are not rendered by default.

tests/test_fixtures/frontpage.json

Lines changed: 2223 additions & 0 deletions
Large diffs are not rendered by default.

tests/test_fixtures/image.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{"title": "Google", "images": [
2+
{
3+
"pixelHeight": 95,
4+
"caption": "Google",
5+
"pixelWidth": 269,
6+
"url": "https:\/\/www.google.com\/images\/srpr\/logo9w.png",
7+
"xpath": "\/HTML\/BODY\/CENTER\/DIV[@id='lga']\/IMG[@id='hplogo']",
8+
"size": 8228
9+
}
10+
], "date_created": "Fri, 17 Jan 2014 11:33:14 PST", "type": "image", "url": "https:\/\/www.google.com\/"}

tests/test_fixtures/product.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "product",
3+
"products": [
4+
{
5+
"title": "iRobot 650 Roomba Vacuuming Robot",
6+
"description": "The new iRobot Roomba 650 Vacuum Cleaning Robot provides a superior level of cleaning with less work for you. With AeroVac Technology and a new brush design, Roomba 650 is better equipped to handle fibers like hair, pet fur, lint and carpet fuzz. Materials: Vacuum Cleaning Robot Dimensions: 17 inches long x 18 inches wide x 5 inches high Weight: 11 pounds Included parts: One (1)Roomba 650 Vacuum Cleaning Robot With AeroVac Bin, one (1) Self-Charging Home Base, one (1) Battery Charger, one (1) Extra AeroVac Filter, one (1) Auto Virtual Wall and one (1) Brush Cleaning Tool Power source: Battery Model: iRobot Roomba 650",
7+
"offerPrice": "$399.99",
8+
"productId": "15268099",
9+
"media": [
10+
{
11+
"height": 320,
12+
"width": 320,
13+
"primary": true,
14+
"link": "http://ak1.ostkcdn.com/images/products/7886009/cc8883ce-f6a0-44a7-836b-b55b4f9ce1ef_320.jpg",
15+
"caption": "The new iRobot Roomba 650 Vacuum Cleaning Robot provides a superior level of cleaning with less work for you. With AeroVac Technology and a new brush design, Roomba 650 is better equipped to handle fibers like hair, pet fur, lint and carpet fuzz.",
16+
"type": "image",
17+
"xpath": "/HTML/BODY/DIV[@id='product-page']/DIV[@id='bd']/DIV[@id='pageContainer']/DIV[@id='productWrap']/DIV[@id='prod_leftCol']/DIV[@id='prod_main']/DIV[@id='prod_mainLeft']/DIV[@id='proImageContainer']/DIV[@id='proImageHero']/DIV[@class='proImageStack']/DIV[@class='proImageCenter']/IMG"
18+
}
19+
]
20+
}
21+
],
22+
"url": "http://www.overstock.com/Home-Garden/iRobot-650-Roomba-Vacuuming-Robot/7886009/product.html"
23+
}

tests/unit_test.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,50 @@ def setUp(self):
3535
def tearDown(self):
3636
self.patcher.stop()
3737

38-
def test_request_for_article(self):
39-
url = "http://shichuan.github.io/javascript-patterns/"
38+
def test_article_api(self):
39+
url = "http://www.xconomy.com/san-francisco/2012/07/25/diffbot-is-using-computer-vision-to-reinvent-the-semantic-web/"
4040
token = "3c66f28f72ea40c1b02e6a4cc195b07e"
4141
api = "article"
4242
version = 2
4343
response = self.client.request(url, token, api, version=version)
44-
self.assertIn('text', response)
45-
self.assertEqual(response['meta']['title'], 'JavaScript Patterns')
44+
self.assertIn('title', response)
45+
self.assertEqual(response['title'], "Diffbot Is Using Computer Vision to Reinvent the Semantic Web")
46+
47+
def test_frontpage_api(self):
48+
url = "http://www.huffingtonpost.com/"
49+
token = "3c66f28f72ea40c1b02e6a4cc195b07e"
50+
api = "frontpage"
51+
version = 2
52+
response = self.client.request(url, token, api, version=version)
53+
self.assertEqual(response['tagName'], "dml")
54+
self.assertIn('childNodes', response)
55+
56+
def test_product_api(self):
57+
url = "http://www.overstock.com/Home-Garden/iRobot-650-Roomba-Vacuuming-Robot/7886009/product.html"
58+
token = "3c66f28f72ea40c1b02e6a4cc195b07e"
59+
api = "product"
60+
version = 2
61+
response = self.client.request(url, token, api, version=version)
62+
self.assertEqual(response['type'], "product")
63+
self.assertEqual(response['products'][0]['title'], "iRobot 650 Roomba Vacuuming Robot")
64+
65+
def test_image_api(self):
66+
url = "http://www.google.com/"
67+
token = "3c66f28f72ea40c1b02e6a4cc195b07e"
68+
api = "image"
69+
version = 2
70+
response = self.client.request(url, token, api, version=version)
71+
self.assertEqual(response['title'], "Google")
72+
self.assertEqual(response['images'][0]['url'], "https://www.google.com/images/srpr/logo9w.png")
73+
74+
def test_analyze_api(self):
75+
url = "http://www.twitter.com/"
76+
token = "3c66f28f72ea40c1b02e6a4cc195b07e"
77+
api = "analyze"
78+
version = 2
79+
response = self.client.request(url, token, api, version=version)
80+
self.assertEqual(response['type'], "image")
81+
self.assertEqual(response['title'], "Welcome to Twitter.")
4682

4783

4884
if __name__ == '__main__':

0 commit comments

Comments
 (0)