本文整理汇总了Python中mapproxy.test.http.MockServ.returns方法的典型用法代码示例。如果您正苦于以下问题:Python MockServ.returns方法的具体用法?Python MockServ.returns怎么用?Python MockServ.returns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapproxy.test.http.MockServ
的用法示例。
在下文中一共展示了MockServ.returns方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_tile_limited_to_inside
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
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)))
示例2: test_get_map_uncached
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
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)
示例3: test_get_tile_limited_to
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
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)
示例4: test_get_tile_flipped_axis
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
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")
示例5: test_returns_status
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
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')
示例6: test_returns_headers
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
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')
示例7: test_returns
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
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')
示例8: test_get_tile_flipped_axis
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
def test_get_tile_flipped_axis(self):
self.common_tile_req.params['layer'] = 'tms_cache_ul'
self.common_tile_req.params['tilematrixset'] = 'ulgrid'
self.common_tile_req.params['format'] = 'image/png'
self.common_tile_req.tile = (0, 0, '01')
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(str(self.common_tile_req), status=200)
eq_(resp.content_type, 'image/png')
示例9: test_get_map_uncached
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
def test_get_map_uncached(self):
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)
示例10: test_get_map_uncached
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
def test_get_map_uncached(self):
assert os.path.exists(os.path.join(test_config['base_dir'], 'cache.gpkg')) # already created on startup
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 = BytesIO(resp.body)
assert is_png(data)
# now cached
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
示例11: test_get_featureinfo_limited_to_inside
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
def test_get_featureinfo_limited_to_inside(self):
def auth(service, layers, query_extent, **kw):
eq_(query_extent, ('EPSG:4326', (-80.0, -40.0, 0.0, 0.0)))
eq_(service, 'wms.featureinfo')
eq_(len(layers), 1)
return {
'authorized': 'partial',
'layers': {
'layer1b': {'featureinfo': True, 'limited_to': {'srs': 'EPSG:4326', 'geometry': [-80.0, -40.0, 0.0, 0.0]}},
}
}
serv = MockServ(port=42423)
serv.expects('/service?request=GetFeatureInfo&service=WMS&Version=1.1.1&SRS=EPSG:4326'
'&BBOX=-80.0,-40.0,0.0,0.0&WIDTH=200&HEIGHT=100&styles=&FORMAT=image/png&X=10&Y=10'
'&query_layers=fi&layers=fi')
serv.returns('infoinfo')
with serv:
resp = self.app.get(FI_REQ + 'query_layers=layer1b&layers=layer1b', extra_environ={'mapproxy.authorize': auth})
eq_(resp.body, 'infoinfo')
示例12: test_get_tile_flipped_axis
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
def test_get_tile_flipped_axis(self):
# test default tile lock directory
tiles_lock_dir = os.path.join(test_config['base_dir'], 'cache_data', 'tile_locks')
# make sure default tile_lock_dir was not created by other tests
shutil.rmtree(tiles_lock_dir, ignore_errors=True)
assert not os.path.exists(tiles_lock_dir)
self.common_tile_req.params['layer'] = 'tms_cache_ul'
self.common_tile_req.params['tilematrixset'] = 'ulgrid'
self.common_tile_req.params['format'] = 'image/png'
self.common_tile_req.tile = (0, 0, '01')
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(str(self.common_tile_req), status=200)
eq_(resp.content_type, 'image/png')
# test default tile lock directory was created
assert os.path.exists(tiles_lock_dir)
示例13: test_add_get_edit_delete
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
def test_add_get_edit_delete(self):
mock_serv = MockServ()
mock_serv.expects('/foo/service?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1')
cap_file = os.path.join(os.path.dirname(__file__), 'fixtures', 'wms_nasa_cap.xml')
mock_serv.returns(body_file=cap_file)
with mock_serv:
resp = self.app.post_json('/conf/base/wms_capabilities', {'data': {'url': mock_serv.base_url + '/foo/service'}})
id = resp.json['_id']
expected = {
'_id': id,
'data': {
'abstract': helper.ANY,
'title': 'JPL Global Imagery Service',
'url': 'http://wms.jpl.nasa.gov/wms.cgi?',
'layer': helper.ANY,
}
}
assert resp.json == expected
resp = self.app.get('/conf/base/wms_capabilities/%d' % resp.json['_id'])
expected.pop('_id') # remove if we decide to pass _id in get request
assert resp.json == expected
resp = self.app.get('/conf/base/wms_capabilities')
# add vars returned by function
expected['_id'] = id
expected['_locked'] = 0
expected['_manual'] = 0
expected['_section'] = 'wms_capabilities'
assert resp.json == {str(id): expected}
mock_serv.reset()
with mock_serv:
resp = self.app.put_json('/conf/base/wms_capabilities/%d' % id, {'data': {'url': mock_serv.base_url + '/foo/service'}})
resp = self.app.delete('/conf/base/wms_capabilities/%d' % id)
assert resp.status_code == 204
resp = self.app.get('/conf/base/wms_capabilities/%d' % id, status=404)
示例14: check_get_tile_limited_to
# 需要导入模块: from mapproxy.test.http import MockServ [as 别名]
# 或者: from mapproxy.test.http.MockServ import returns [as 别名]
def check_get_tile_limited_to(self, auth_dict):
def auth(service, layers, environ, query_extent, **kw):
eq_(environ['PATH_INFO'], '/kml/layer3_EPSG900913/1/0/0.jpeg')
eq_(service, 'kml')
eq_(len(layers), 1)
eq_(query_extent[0], 'EPSG:900913')
assert bbox_equals(query_extent[1], (-20037508.342789244, -20037508.342789244, 0, 0))
return auth_dict
serv = MockServ(port=42423)
serv.expects('/1/0/0.png')
serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
with serv:
resp = self.app.get('/kml/layer3_EPSG900913/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)