def test_get_url_text_404(self): HTTPretty.register_uri(HTTPretty.GET, 'http://www.test.com', body='', status=404 ) dw = mini.DownloadWorker('http://www.test.com', '.', 'reg', 0, 3, 1, 1) dw.get_url_text()
def test_create_download_url(self): dw = mini.DownloadWorker('http://www.test.com', '.', 'reg', 0, 3, 1, 1) test_fuc = dw.create_download_url test_dic = { r'http://xxx': 'http://xxx', r'//xxx': 'http://xxx', r'xxx': 'http://www.test.com/xxx', } for k in test_dic: self.assertEqual(test_fuc(k), test_dic[k])
def test_download_file(self): dw = mini.DownloadWorker('http://no.url.me', '.', 'reg', 0, 3, 1, 1) to = dw.url_to_localfile(self.fm) def del_file(to): if os.path.exists(to): os.remove(to) del_file(to) dw.download_file(self.fm) self.assertTrue(os.path.exists(dw.url_to_localfile(self.fm))) dw.download_file(self.fm) self.assertTrue(os.path.exists(dw.url_to_localfile(self.fm))) del_file(to)
def test_get_url_text(self): HTTPretty.register_uri(HTTPretty.GET, 'http://www.test.com', body='xxx') dw = mini.DownloadWorker('http://www.test.com', '.', 'reg', 0, 3, 1, 1) self.assertEqual(dw.get_url_text(), 'xxx')
def test_get_url_text_wrong_url(self): dw = mini.DownloadWorker('http://wrong.url.me', '.', 'reg', 0, 3, 1, 1) dw.get_url_text()