-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
executable file
·55 lines (44 loc) · 1.55 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import unittest
from pytm import Api
import urllib2
import datetime
import json
class TestApi(unittest.TestCase):
def setUp(self):
self.api = Api()
def tearDown(self):
self.api = None
def test_get(self):
r = self.api.get("Search/General.json")
self.assertIsInstance(r, urllib2.addinfourl)
self.assertRaises(urllib2.HTTPError,
self.api.get,"Search/GeneralJason")
def test_search(self):
response = self.api.search()
self.assertEqual(response,
'{"TotalCount":0,"Page":1,"PageSize":0,"List":[],"FoundCategories":[]}')
def test_search_motors_used(self):
response = self.api.search_motors_used()
self.assertIsNotNone(response)
def test_categories(self):
response = self.api.categories("0001-1484")
self.assertIsNotNone(response)
def test_categories_updated(self):
last_updated = self.api.categories_updated()
self.assertIsInstance(last_updated, datetime.datetime)
def test_latest(self):
r1 = self.api.latest()
self.assertIsNotNone(r1)
r2 = self.api.latest(page=2)
self.assertIsNotNone(r2)
r3 = self.api.latest(rows=1)
self.assertIsNotNone(r3)
r4 = self.api.latest(region=1)
self.assertIsNotNone(r4)
r5 = self.api.latest(page=2,rows=1,region=1,file_format="json")
self.assertIsNotNone(r5)
latest = json.loads(r5)
self.assertTrue("List" in latest)
if __name__ == '__main__':
unittest.main()