def test_loading(self): with TempFile() as gp: open(gp, 'w').write(self.yaml_grand_parent) self.yaml_parent = """ base: - %s %s """ % (gp, self.yaml_parent) with TempFile() as p: open(p, 'w').write(self.yaml_parent) self.yaml_string = """ base: [%s] %s """ % (p, self.yaml_string) with TempFile() as cfg: open(cfg, 'w').write(self.yaml_string) config = load_configuration(cfg) http = config.globals.get_value('http') eq_(http['client_timeout'], 1) eq_(http['headers']['bar'], 'qux') eq_(http['headers']['foo'], 'bar') eq_(http['headers']['baz'], 'quux') eq_(http['method'], 'GET') config_files = config.config_files() eq_(set(config_files.keys()), set([gp, p, cfg])) assert abs(config_files[gp] - time.time()) < 10 assert abs(config_files[p] - time.time()) < 10 assert abs(config_files[cfg] - time.time()) < 10
def test_loading(self): with TempFile() as gp: open(gp, 'wb').write(self.yaml_grand_parent.encode('utf-8')) self.yaml_parent = """ base: - %s %s """ % (gp, self.yaml_parent) with TempFile() as p: open(p, 'wb').write(self.yaml_parent.encode("utf-8")) self.yaml_string = """ base: [%s] %s """ % (p, self.yaml_string) with TempFile() as cfg: open(cfg, 'wb').write(self.yaml_string.encode("utf-8")) config = load_configuration(cfg) http = config.globals.get_value('http') assert http['client_timeout'] == 1 assert http['headers']['bar'] == 'qux' assert http['headers']['foo'] == 'bar' assert http['headers']['baz'] == 'quux' assert http['method'] == 'GET' config_files = config.config_files() assert set(config_files.keys()) == set([gp, p, cfg]) assert abs(config_files[gp] - time.time()) < 10 assert abs(config_files[p] - time.time()) < 10 assert abs(config_files[cfg] - time.time()) < 10
def test_loading(self): with TempFile() as gp: open(gp, 'w').write(self.yaml_grand_parent) self.yaml_parent = """ base: - %s %s """ % (gp, self.yaml_parent) with TempFile() as p: open(p, 'w').write(self.yaml_parent) self.yaml_string = """ base: [%s] %s """ % (p, self.yaml_string) with TempFile() as cfg: open(cfg, 'w').write(self.yaml_string) config = load_configuration(cfg) http = config.globals.get_value('http') eq_(http['client_timeout'], 1) eq_(http['headers']['bar'], 'qux') eq_(http['headers']['foo'], 'bar') eq_(http['headers']['baz'], 'quux') eq_(http['method'], 'GET')
def test_loading_broken(self): with TempFile() as fname: with open(fname, 'wb') as f: f.write(b"POLYGON((") polygon = load_polygons(fname) assert polygon.is_valid bbox, polygon = build_multipolygon(polygon, simplify=True)
def test_load_empty_geojson_ogr(self): with TempFile() as tf: with open(tf, 'wb') as f: f.write(b'{"type": "FeatureCollection", "features": []}') conf = {'datasource': tf, 'where': '0 != 1', 'srs': 'EPSG:4326'} with pytest.raises(EmptyGeometryError): load_coverage(conf)
def test_loading_polygon(self): with TempFile() as fname: with open(fname, 'w') as f: f.write(VALID_POLYGON1) polygon = load_polygons(fname) bbox, polygon = build_multipolygon(polygon, simplify=True) eq_(polygon.type, 'Polygon')
def test_load_broken(self): with TempFile(no_create=True) as tmp: with open(tmp, 'w') as f: f.write('##invaliddata') f.write(pickle.dumps({("view", "cache", "grid"): [(0, 1), (2, 4)]})) store = ProgressStore(tmp) assert store.status == {}
def test_geojson(self, geojson, geometry): with TempFile() as fname: with open(fname, 'w') as f: f.write(geojson) polygon = load_geojson(fname) bbox, polygon = build_multipolygon(polygon, simplify=True) assert polygon.is_valid assert polygon.type in ('Polygon', 'MultiPolygon'), polygon.type assert polygon.equals(geometry)
def test_wkt(self): with TempFile() as fname: with open(fname, 'wb') as f: f.write(VALID_POLYGON1) f.write(b"\n") f.write(VALID_POLYGON1) geoms = load_datasource(fname) eq_(len(geoms), 2)
def test_loading_broken_yaml(self): with TempFile() as f: open(f, 'w').write('\tbroken:foo') try: load_services(f) except ConfigurationError: pass else: assert False, 'expected configuration error'
def test_loading_skip_non_polygon(self): with TempFile() as fname: with open(fname, 'wb') as f: f.write(b"POINT(0 0)\n") f.write(VALID_POLYGON1) polygon = load_polygons(fname) bbox, polygon = build_multipolygon(polygon, simplify=True) assert polygon.is_valid eq_(polygon.type, 'Polygon')
def test_with_warnings(object): with TempFile() as f: open(f, 'w').write(""" services: unknown: """) load_configuration(f) # defaults to ignore_warnings=True assert_raises(ConfigurationError, load_configuration, f, ignore_warnings=False)
def test_loading_multipolygon(self): with TempFile() as fname: with open(fname, 'wb') as f: f.write(VALID_POLYGON1) f.write(b'\n') f.write(VALID_POLYGON2) polygon = load_polygons(fname) bbox, polygon = build_multipolygon(polygon, simplify=True) assert polygon.is_valid eq_(polygon.type, 'MultiPolygon')
def test_expire_tiles_file(self): with TempFile() as fname: with open(fname, 'wb') as f: f.write(b"4/2/5\n") f.write(b"4/2/6\n") f.write(b"error\n") f.write(b"4/2/1\n") # rest of file is ignored geoms = load_expire_tiles(fname) assert len(geoms) == 2
def test_with_warnings(object): with TempFile() as f: open(f, 'wb').write(b""" services: unknown: """) load_configuration(f) # defaults to ignore_warnings=True with pytest.raises(ConfigurationError): load_configuration(f, ignore_warnings=False)
def test_https_invalid_cert(self): # load 'wrong' root cert with TempFile() as tmp: with open(tmp, 'wb') as f: f.write(GOOGLE_ROOT_CERT) self.client = HTTPClient('https://untrusted-root.badssl.com/', ssl_ca_certs=tmp) try: self.client.open('https://untrusted-root.badssl.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_geojson(self): with TempFile() as fname: with open(fname, 'wb') as f: f.write(b'''{"type": "FeatureCollection", "features": [ {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[0, 0], [10, 0], [10, 10], [0, 0]]]} }, {"type": "Feature", "geometry": {"type": "MultiPolygon", "coordinates": [[[[0, 0], [10, 0], [10, 10], [0, 0]]], [[[0, 0], [10, 0], [10, 10], [0, 0]]], [[[0, 0], [10, 0], [10, 10], [0, 0]]]]} }, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [0, 0]} } ]}''') geoms = load_datasource(fname) assert len(geoms) == 4
def test_loading_intersecting_polygons(self): # check that the self intersection is eliminated # otherwise the geometry will be invalid with TempFile() as fname: with open(fname, 'w') as f: f.write(INTERSECTING_POLYGONS) polygon = load_polygons(fname) bbox, polygon = build_multipolygon(polygon, simplify=True) assert polygon.is_valid assert polygon.type == 'Polygon' assert polygon.equals(shapely.geometry.Polygon([(0, 0), (15, 0), (15, 10), (0, 10)]))
def test_https_valid_ca_cert_file(self): # verify with fixed ca_certs file cert_file = '/etc/ssl/certs/ca-certificates.crt' if os.path.exists(cert_file): self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=cert_file) self.client.open('https://www.google.com/') else: with TempFile() as tmp: with open(tmp, 'wb') as f: f.write(GOOGLE_ROOT_CERT) self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=tmp) self.client.open('https://www.google.com/')
def test_https_invalid_cert(self): try: import ssl ssl except ImportError: raise SkipTest() with TempFile() as tmp: self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=tmp) try: self.client.open('https://www.google.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_load_store(self): with TempFile(no_create=True) as tmp: with open(tmp, 'w') as f: f.write(pickle.dumps({("view", "cache", "grid"): [(0, 1), (2, 4)]})) store = ProgressStore(tmp) assert store.get(('view', 'cache', 'grid')) == [(0, 1), (2, 4)] assert store.get(('view', 'cache', 'grid2')) == None store.add(('view', 'cache', 'grid'), []) store.add(('view', 'cache', 'grid2'), [(0, 1)]) store.write() store = ProgressStore(tmp) assert store.get(('view', 'cache', 'grid')) == [] assert store.get(('view', 'cache', 'grid2')) == [(0, 1)]
def test_https_valid_cert(self): try: import ssl ssl except ImportError: raise SkipTest() cert_file = '/etc/ssl/certs/ca-certificates.crt' if os.path.exists(cert_file): self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=cert_file) self.client.open('https://www.google.com/') else: with TempFile() as tmp: with open(tmp, 'wb') as f: f.write(GOOGLE_ROOT_CERT) self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=tmp) self.client.open('https://www.google.com/')
def test_from_mtime(self): with TempFile() as tmp: os.utime(tmp, (12376512, 12376512)) assert before_timestamp_from_options({"mtime": tmp}) == 12376512
def test_load_empty_geojson(self): with TempFile() as tf: with open(tf, 'wb') as f: f.write(b'{"type": "FeatureCollection", "features": []}') conf = {'datasource': tf, 'srs': 'EPSG:4326'} assert_raises(EmptyGeometryError, load_coverage, conf)
def test_loading(self): with TempFile() as tf: with open(tf, 'wb') as f: f.write(self.yaml_string) services = load_services(tf) assert 'service' in services[0].names
def test_loading(self): with TempFile() as f: open(f, 'w').write(self.yaml_string) services = load_services(f) assert 'service' in services[0].names
def test_from_mtime(self): with TempFile() as tmp: os.utime(tmp, (12376512, 12376512)) eq_(before_timestamp_from_options({'mtime': tmp}), 12376512)
def test_loading_broken(self): with TempFile() as fname: with open(fname, 'wb') as f: f.write(b"POLYGON((") with pytest.raises(ReadingError): load_polygons(fname)