Skip to content

Commit 4d6bac5

Browse files
committed
add httpretty for test and add A test of DownloadWorker
1 parent e7eea23 commit 4d6bac5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
beautifulsoup4==4.3.2
2+
httpretty==0.8.7

test_mini_spider.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import unittest
1414
import mini_spider_rebuild as mini
1515
import os
16+
from httpretty import HTTPretty, httprettified
1617

1718

1819
class FuncTest(unittest.TestCase):
@@ -51,5 +52,23 @@ def test_download_file(self):
5152
self.assertTrue(os.path.exists(self.to))
5253

5354

55+
class DownloadWorkerTest(unittest.TestCase):
56+
57+
# 初始化工作
58+
def setUp(self):
59+
pass
60+
61+
# 退出清理工作
62+
def tearDown(self):
63+
pass
64+
65+
@httprettified
66+
def test_get_url_text(self):
67+
HTTPretty.register_uri(HTTPretty.GET, 'http://www.test.com',
68+
body='xxx')
69+
dw = mini.DownloadWorker('http://www.test.com', '.', 'reg', 0, 3, 1, 1)
70+
self.assertEqual(dw.get_url_text(), 'xxx')
71+
72+
5473
if __name__ == '__main__':
5574
unittest.main()

0 commit comments

Comments
 (0)