Skip to content

Commit

Permalink
Fix url validation. fixes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbuddha committed Mar 12, 2013
1 parent 9790ebd commit 8730486
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions server_test.py
Expand Up @@ -73,6 +73,7 @@
}
url_fail = 'http://doesnotwork.example.com'
url_redir = 'http://example.com'
uri_ = '/home/user/file'
#url_timeout = 'http://...'


Expand All @@ -88,6 +89,9 @@ def test_url_1(self):
def test_url_2(self):
self.assertFalse(server.url_fails(url_redir))

def test_url_3(self):
self.assertFalse(server.url_fails(uri_))


class DBHelperTest(unittest.TestCase):
def setUp(self):
Expand Down
15 changes: 6 additions & 9 deletions utils.py
Expand Up @@ -52,14 +52,11 @@ def json_dump(obj):


def url_fails(url):
if validate_url(url):
try:
try:
if validate_url(url):
obj = requests.head(url, allow_redirects=True)
if obj.status_code == 200:
return False
else:
return True
except (requests.ConnectionError, AssertionError):
return True
else:
assert obj.status_code == 200
except (requests.ConnectionError, AssertionError):
return True
else:
return False

0 comments on commit 8730486

Please sign in to comment.