Skip to content

Commit

Permalink
Added tests for http error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
chintal committed Sep 30, 2015
1 parent 7ba0b52 commit b1bdd2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions tendril/utils/www.py
Expand Up @@ -351,10 +351,10 @@ def urlopen(url):
time.sleep(0.5)
retries -= 1
else:
retries = 0
raise
except URLError as e:
logger.error("URL Error : " + str(e.errno) + " " + str(e.reason))
retries = 0
raise

while retries > 0:
try:
Expand All @@ -373,10 +373,10 @@ def urlopen(url):
time.sleep(0.5)
retries -= 1
else:
retries = 0
raise
except URLError as e:
logger.error("URL Error : " + str(e.errno) + " " + str(e.reason))
retries = 0
raise
return None


Expand Down
9 changes: 8 additions & 1 deletion tests/test_utils_www.py
Expand Up @@ -25,6 +25,8 @@
import six
from tendril.utils import www
from hashlib import md5
import pytest
from six.moves.urllib.error import HTTPError, URLError
www.DUMP_REDIR_CACHE_ON_EXIT = False


Expand All @@ -50,7 +52,6 @@ def test_redirect_cache_301():
assert result.status == 301
newtarget = www.get_actual_url('https://jigsaw.w3.org/HTTP/300/301.html')
assert newtarget == 'https://jigsaw.w3.org/HTTP/300/Overview.html'
print www.redirect_cache
result = www.urlopen('https://jigsaw.w3.org/HTTP/300/301.html')
assert hasattr(result, 'status') == False or result.status == 200

Expand Down Expand Up @@ -86,3 +87,9 @@ def test_cached_fetcher():
assert soup is not None
assert fs.exists(filepath)


def test_www_errors():
with pytest.raises(HTTPError):
www.get_soup('http://httpstat.us/404')
with pytest.raises(URLError):
www.get_soup('httpd://httpstat.us/404')

0 comments on commit b1bdd2d

Please sign in to comment.