def test_http_error_no_header(): """Test getting an error back without Content-Type.""" endpoint = HTTPEndPoint('http://thredds.ucar.edu/thredds/ncss/grib/NCEP/GFS/' 'Global_0p5deg/GFS_Global_0p5deg_20180223_1200.grib2') query = endpoint.query().variables('u-component_of_wind_isobaric') query.time(datetime(2018, 2, 23, 22, 28, 49)) with pytest.raises(HTTPError): endpoint.get_query(query)
def test_http_error_no_header(): """Test getting an error back without Content-Type.""" endpoint = HTTPEndPoint( 'http://thredds.ucar.edu/thredds/ncss/grib/NCEP/GFS/' 'Global_0p5deg/GFS_Global_0p5deg_20180223_1200.grib2') query = endpoint.query().variables('u-component_of_wind_isobaric') query.time(datetime(2018, 2, 23, 22, 28, 49)) with pytest.raises(HTTPError): endpoint.get_query(query)
def test_trailing_slash(self): """Test setting up and end point with a url with a trailing slash.""" endpoint = HTTPEndPoint(self.server + self.api + '/') q = endpoint.query() q.add_query_parameter(metadata='variableMap') resp = endpoint.get_query(q) assert resp.content
class TestEndPoint(object): def setup(self): self.server = 'http://thredds.ucar.edu/' self.api = 'thredds/metadata/grib/NCEP/GFS/Global_0p5deg/TwoD' self.endpoint = HTTPEndPoint(self.server + self.api) def test_basic(self): q = self.endpoint.query() q.all_times() assert self.endpoint.validate_query(q), 'Invalid query.' @recorder.use_cassette('gfs-metadata-map') def test_trailing_slash(self): endpoint = HTTPEndPoint(self.server + self.api + '/') q = endpoint.query() q.add_query_parameter(metadata='variableMap') resp = endpoint.get_query(q) assert resp.content @recorder.use_cassette('gfs-metadata-map') def test_query(self): q = self.endpoint.query() q.add_query_parameter(metadata='variableMap') resp = self.endpoint.get_query(q) assert resp.content @recorder.use_cassette('gfs-metadata-map-bad') @raises(HTTPError) def test_get_error(self): self.endpoint.get_path('') def test_url_path(self): path = self.endpoint.url_path('foobar.html') eq_(path, self.server + self.api + '/foobar.html')
class TestEndPoint(object): def setup(self): self.server = 'http://thredds.ucar.edu/' self.api = 'thredds/metadata/grib/NCEP/GFS/Global_0p5deg/TwoD' self.endpoint = HTTPEndPoint(self.server + self.api) def test_basic(self): q = self.endpoint.query() q.all_times() assert self.endpoint.validate_query(q), 'Invalid query.' @recorder.use_cassette('gfs-metadata-map') def test_trailing_slash(self): endpoint = HTTPEndPoint(self.server + self.api + '/') q = endpoint.query() q.add_query_parameter(metadata='variableMap') resp = endpoint.get_query(q) assert resp.content @recorder.use_cassette('gfs-metadata-map') def test_query(self): q = self.endpoint.query() q.add_query_parameter(metadata='variableMap') resp = self.endpoint.get_query(q) assert resp.content @recorder.use_cassette('gfs-metadata-map-bad') def test_get_error(self): with pytest.raises(HTTPError): self.endpoint.get_path('') def test_url_path(self): path = self.endpoint.url_path('foobar.html') assert path == self.server + self.api + '/foobar.html'
class TestEndPoint(object): """Test the HTTPEndPoint.""" def setup(self): """Set up tests to point to a common server, api, and end point.""" self.server = 'http://thredds.ucar.edu/' self.api = 'thredds/metadata/grib/NCEP/GFS/Global_0p5deg/TwoD' self.endpoint = HTTPEndPoint(self.server + self.api) def test_basic(self): """Test creating a basic query and validating it.""" q = self.endpoint.query() q.all_times() assert self.endpoint.validate_query(q), 'Invalid query.' @recorder.use_cassette('gfs-metadata-map') def test_trailing_slash(self): """Test setting up and end point with a url with a trailing slash.""" endpoint = HTTPEndPoint(self.server + self.api + '/') q = endpoint.query() q.add_query_parameter(metadata='variableMap') resp = endpoint.get_query(q) assert resp.content @recorder.use_cassette('gfs-metadata-map') def test_query(self): """Test getting a query.""" q = self.endpoint.query() q.add_query_parameter(metadata='variableMap') resp = self.endpoint.get_query(q) assert resp.content @recorder.use_cassette('gfs-metadata-map-bad') def test_get_error(self): """Test that getting a bad path raises an error.""" with pytest.raises(HTTPError): self.endpoint.get_path('') def test_url_path(self): """Test forming a url path from the end point.""" path = self.endpoint.url_path('foobar.html') assert path == self.server + self.api + '/foobar.html'
def test_trailing_slash(self): endpoint = HTTPEndPoint(self.server + self.api + '/') q = endpoint.query() q.add_query_parameter(metadata='variableMap') resp = endpoint.get_query(q) assert resp.content