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'