|
1 | 1 | # coding: utf-8 |
2 | | -from . import io |
3 | 2 | import pytest |
4 | 3 | import requests |
5 | 4 | import os |
6 | 5 | from urllib.parse import quote_plus |
7 | 6 |
|
| 7 | +from bigpython.webscrap import http |
| 8 | + |
8 | 9 | def test_http_download(): |
9 | | - res = io.http_download('http://google.com') |
| 10 | + res = http.download('http://google.com') |
10 | 11 | assert res.status_code == 200 |
11 | 12 |
|
12 | 13 | with pytest.raises(requests.ConnectionError): |
13 | | - io.http_download('http://no-such-domain.com') |
| 14 | + http.download('http://no-such-domain.com') |
14 | 15 |
|
15 | 16 | with pytest.raises(requests.HTTPError): |
16 | | - io.http_download('http://google.com/nosuchpath') |
| 17 | + http.download('http://google.com/nosuchpath') |
17 | 18 |
|
18 | 19 | def test_unquote_url(): |
19 | 20 | url = 'https://ko.wikipedia.org/wiki/%EC%95%A8%EB%9F%B0_%ED%8A%9C%EB%A7%81' |
20 | | - url_unquoted = io.unquote_url(url) |
| 21 | + url_unquoted = http.unquote_url(url) |
21 | 22 | basename = os.path.basename(url_unquoted) |
22 | 23 | assert basename == '앨런_튜링' |
23 | 24 |
|
24 | 25 | url_quote_plus = quote_plus(url_unquoted) |
25 | | - url_unquoted = io.unquote_url(url_quote_plus) |
| 26 | + url_unquoted = http.unquote_url(url_quote_plus) |
26 | 27 | basename = os.path.basename(url_unquoted) |
27 | 28 | assert basename == '앨런_튜링' |
28 | 29 |
|
29 | | -def test_snapshot_webpage(): |
| 30 | +def test_http_download(): |
30 | 31 | url = 'https://ko.wikipedia.org/wiki/%EC%95%A8%EB%9F%B0_%ED%8A%9C%EB%A7%81' |
31 | | - filename = io.snapshot_webpage(url, '앨런튜링_위키.html') |
| 32 | + filename = http.download(url, '앨런튜링_위키.html') |
32 | 33 | assert os.path.exists(filename) |
33 | 34 | # cleanup |
34 | 35 | os.unlink(filename) |
35 | 36 |
|
36 | 37 | with pytest.raises(requests.ConnectionError): |
37 | | - io.snapshot_webpage('http://no-such-domain.com', 'no.html') |
| 38 | + http.download('http://no-such-domain.com', 'no.html') |
38 | 39 |
|
39 | 40 | with pytest.raises(requests.HTTPError): |
40 | | - io.http_download('http://google.com/nosuchpath') |
| 41 | + http.download('http://google.com/404', 'no.html') |
0 commit comments