本文整理汇总了Python中mapproxy.test.http.MockServ类的典型用法代码示例。如果您正苦于以下问题:Python MockServ类的具体用法?Python MockServ怎么用?Python MockServ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockServ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_tile_limited_to
def test_get_tile_limited_to(self):
def auth(service, layers, environ, query_extent, **kw):
eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
eq_(service, 'wmts')
eq_(len(layers), 1)
eq_(query_extent[0], 'EPSG:900913')
assert bbox_equals(query_extent[1], (-20037508.342789244, 0, 0, 20037508.342789244))
return {
'authorized': 'partial',
'limited_to': {
'geometry': [-180, -89, -90, 89],
'srs': 'EPSG:4326',
},
'layers': {
'layer3': {'tile': True},
}
}
serv = MockServ(port=42423)
serv.expects('/1/0/1.png')
serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
with serv:
resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})
eq_(resp.content_type, 'image/png')
img = img_from_buf(resp.body)
img = img.convert('RGBA')
# left part authorized, red
eq_(img.crop((0, 0, 127, 255)).getcolors()[0], (127*255, (255, 0, 0, 255)))
# right part not authorized, transparent
eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
示例2: test_expects_post
def test_expects_post(self):
# TODO POST handling in MockServ is hacky.
# data just gets appended to URL
serv = MockServ()
serv.expects('/test?foo', method='POST')
with serv:
requests.post('http://localhost:%d/test' % serv.port, data=b'foo')
示例3: test_get_tile_default_no_dimension_source
def test_get_tile_default_no_dimension_source(self):
# check if dimensions are ignored
serv = MockServ(42423, bbox_aware_query_comparator=True)
serv.expects(NO_DIMENSION_LAYER_BASE_REQ).returns(TEST_TILE)
with serv:
resp = self.app.get('/wmts/no_dimension_layer/GLOBAL_MERCATOR/default/default/01/0/0.png')
eq_(resp.content_type, 'image/png')
示例4: test_get_tile_limited_to_inside
def test_get_tile_limited_to_inside(self):
def auth(service, layers, environ, **kw):
eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
eq_(service, 'wmts')
eq_(len(layers), 1)
return {
'authorized': 'partial',
'limited_to': {
'geometry': [-180, -89, 180, 89],
'srs': 'EPSG:4326',
},
'layers': {
'layer3': {'tile': True},
}
}
serv = MockServ(port=42423)
serv.expects('/1/0/1.png')
serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
with serv:
resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})
eq_(resp.content_type, 'image/jpeg')
img = img_from_buf(resp.body)
eq_(img.getcolors()[0], (256*256, (255, 0, 0)))
示例5: test_get_tile_kvp_default_no_dimension_source
def test_get_tile_kvp_default_no_dimension_source(self):
# check if dimensions are ignored
serv = MockServ(42423, bbox_aware_query_comparator=True)
serv.expects(NO_DIMENSION_LAYER_BASE_REQ).returns(TEST_TILE)
with serv:
resp = self.app.get(WMTS_KVP_URL + '&layer=no_dimension_layer&Time=2012-11-14T00:00:00&Elevation=3000')
eq_(resp.content_type, 'image/png')
示例6: test_expects_get_no_body
def test_expects_get_no_body(self):
serv = MockServ()
serv.expects('/test')
with serv:
resp = requests.get('http://localhost:%d/test' % serv.port)
eq_(resp.status_code, 200)
eq_(resp.content, b'')
示例7: test_get_map_uncached
def test_get_map_uncached(self):
mbtiles_file = os.path.join(test_config['base_dir'], 'cache.mbtiles')
tiles_lock_dir = os.path.join(test_config['base_dir'], 'testlockdir')
assert os.path.exists(mbtiles_file) # already created on startup
assert not os.path.exists(tiles_lock_dir)
self.common_map_req.params.bbox = '-180,0,0,80'
serv = MockServ(port=42423)
serv.expects('/tiles/01/000/000/000/000/000/001.png')
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = StringIO(resp.body)
assert is_png(data)
# now cached
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = StringIO(resp.body)
assert is_png(data)
# custom tile_lock_dir created
assert os.path.exists(tiles_lock_dir)
示例8: test_expects_w_header_but_missing
def test_expects_w_header_but_missing(self):
serv = MockServ()
serv.expects('/test', headers={'Accept': 'Coffee'})
try:
with serv:
requests.get('http://localhost:%d/test' % serv.port)
except RequestsMismatchError as ex:
assert ex.assertions[0].expected == 'Accept: Coffee'
示例9: test_get_tile_flipped_axis
def test_get_tile_flipped_axis(self):
serv = MockServ(port=42423)
# source is ll, cache/service ul
serv.expects("/tiles/01/000/000/000/000/000/001.png")
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get("/wmts/myrest/tms_cache_ul/ulgrid/01/0/0.png", status=200)
eq_(resp.content_type, "image/png")
示例10: test_get_tile_webmerc
def test_get_tile_webmerc(self):
serv = MockServ(42423, bbox_aware_query_comparator=True)
serv.expects(
'/service?layers=foo,bar&width=256&version=1.1.1&bbox=-20037508.3428,0.0,0.0,20037508.3428&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A3857&request=GetMap&height=256').returns(TEST_TILE)
with serv:
resp = self.app.get(str(self.common_tile_req))
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
示例11: test_returns_headers
def test_returns_headers(self):
serv = MockServ()
serv.expects('/test')
serv.returns(body=b'hello', headers={'content-type': 'text/plain'})
with serv:
resp = requests.get('http://localhost:%d/test' % serv.port)
eq_(resp.headers['Content-type'], 'text/plain')
eq_(resp.content, b'hello')
示例12: test_returns_status
def test_returns_status(self):
serv = MockServ()
serv.expects('/test')
serv.returns(body=b'hello', status_code=418)
with serv:
resp = requests.get('http://localhost:%d/test' % serv.port)
eq_(resp.status_code, 418)
eq_(resp.content, b'hello')
示例13: test_returns
def test_returns(self):
serv = MockServ()
serv.expects('/test')
serv.returns(body=b'hello')
with serv:
resp = requests.get('http://localhost:%d/test' % serv.port)
assert 'Content-type' not in resp.headers
eq_(resp.content, b'hello')
示例14: test_multiple_requests
def test_multiple_requests(self):
serv = MockServ()
serv.expects('/test1').returns(body=b'hello1')
serv.expects('/test2').returns(body=b'hello2')
with serv:
resp = requests.get('http://localhost:%d/test1' % serv.port)
eq_(resp.content, b'hello1')
resp = requests.get('http://localhost:%d/test2' % serv.port)
eq_(resp.content, b'hello2')
示例15: test_get_tile_utm
def test_get_tile_utm(self):
serv = MockServ(42423, bbox_aware_query_comparator=True)
serv.expects(
'/service?layers=foo,bar&width=256&version=1.1.1&bbox=-46133.17,5675047.40429,580038.965712,6301219.54&service=WMS&format=image%2Fpng&styles=&srs=EPSG%3A25832&request=GetMap&height=256').returns(TEST_TILE)
self.common_tile_req.params['tilematrixset'] = 'utm32'
with serv:
resp = self.app.get(str(self.common_tile_req))
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)