Skip to content

Commit

Permalink
Make HTTP errors raise an exception.
Browse files Browse the repository at this point in the history
This way we don't blindly continue and get more obscure errors later.
  • Loading branch information
dopplershift committed Oct 30, 2015
1 parent 6f7de13 commit f9c917d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions siphon/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, catalog_url):

# get catalog.xml file
resp = session.get(self.catalog_url)
resp.raise_for_status()

# If we were given an HTML link, warn about it and try to fix to xml
if 'html' in resp.headers['content-type']:
Expand All @@ -61,6 +62,7 @@ def __init__(self, catalog_url):
new_url))
self.catalog_url = new_url
resp = session.get(self.catalog_url)
resp.raise_for_status()

# begin parsing the xml doc
root = ET.fromstring(resp.text)
Expand Down
17 changes: 17 additions & 0 deletions siphon/tests/fixtures/radarserver_ds_denied
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [Siphon (0.3.1+20.gdd8f139.dirty)]
method: GET
uri: http://thredds-aws.unidata.ucar.edu/thredds/radarServer/nexrad/level2/S3/dataset.xml
response:
body: {string: ''}
headers:
Date: ['Thu, 29 Oct 2015 14:35:24 GMT']
Server: [Apache-Coyote/1.1]
status: {code: 403, message: Forbidden}
version: 1
17 changes: 17 additions & 0 deletions siphon/tests/fixtures/radarserver_toplevel_denied
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [Siphon (0.3.1+20.gdd8f139.dirty)]
method: GET
uri: http://thredds-aws.unidata.ucar.edu/thredds/radarServer/catalog.xml
response:
body: {string: ''}
headers:
Date: ['Thu, 29 Oct 2015 14:35:24 GMT']
Server: [Apache-Coyote/1.1]
status: {code: 403, message: Forbidden}
version: 1
12 changes: 12 additions & 0 deletions siphon/tests/test_radarsever.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
get_radarserver_datasets)

from nose.tools import eq_, raises
from requests import HTTPError

recorder = siphon.testing.get_recorder(__file__)

Expand Down Expand Up @@ -120,3 +121,14 @@ def test_catalog_access(self):
ds = get_radarserver_datasets('http://thredds.ucar.edu/thredds/')
url = ds['NEXRAD Level III Radar from IDD'].follow().catalog_url
assert RadarServer(url)

class TestUnauthorizedErrors(object):
@recorder.use_cassette('radarserver_toplevel_denied')
@raises(HTTPError)
def test_get_rs_datasets_denied_throws(self):
ds = get_radarserver_datasets('http://thredds-aws.unidata.ucar.edu/thredds/')

@raises(HTTPError)
@recorder.use_cassette('radarserver_ds_denied')
def test_rs_constructor_throws(self):
RadarServer('http://thredds-aws.unidata.ucar.edu/thredds/radarServer/nexrad/level2/S3/')

0 comments on commit f9c917d

Please sign in to comment.