• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python http.MockServ类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mapproxy.test.http.MockServ的典型用法代码示例。如果您正苦于以下问题:Python MockServ类的具体用法?Python MockServ怎么用?Python MockServ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MockServ类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:32,代码来源:test_auth.py


示例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')
开发者ID:LKajan,项目名称:mapproxy,代码行数:7,代码来源:test_http_helper.py


示例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')
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:7,代码来源:test_wmts_dimensions.py


示例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)))
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:26,代码来源:test_auth.py


示例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')
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:7,代码来源:test_wmts_dimensions.py


示例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'')
开发者ID:LKajan,项目名称:mapproxy,代码行数:7,代码来源:test_http_helper.py


示例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)
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:25,代码来源:test_cache_mbtiles.py


示例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'
开发者ID:LKajan,项目名称:mapproxy,代码行数:8,代码来源:test_http_helper.py


示例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")
开发者ID:TNRIS,项目名称:mapproxy,代码行数:8,代码来源:test_wmts_restful.py


示例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)
开发者ID:tjay,项目名称:mapproxy,代码行数:9,代码来源:test_multi_cache_layers.py


示例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')
开发者ID:LKajan,项目名称:mapproxy,代码行数:9,代码来源:test_http_helper.py


示例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')
开发者ID:LKajan,项目名称:mapproxy,代码行数:9,代码来源:test_http_helper.py


示例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')
开发者ID:LKajan,项目名称:mapproxy,代码行数:9,代码来源:test_http_helper.py


示例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')
开发者ID:LKajan,项目名称:mapproxy,代码行数:10,代码来源:test_http_helper.py


示例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)
开发者ID:tjay,项目名称:mapproxy,代码行数:11,代码来源:test_multi_cache_layers.py


示例16: test_expects_post_but_get

 def test_expects_post_but_get(self):
     serv = MockServ()
     serv.expects('/test', method='POST')
     try:
         with serv:
             requests.get('http://localhost:%d/test' % serv.port)
     except RequestsMismatchError as ex:
         assert ex.assertions[0].expected == 'POST'
         assert ex.assertions[0].actual == 'GET'
     else:
         raise AssertionError('AssertionError expected')
开发者ID:LKajan,项目名称:mapproxy,代码行数:11,代码来源:test_http_helper.py


示例17: test_get_tile_flipped_axis

 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')
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:12,代码来源:test_wmts.py


示例18: test_missing_requests

    def test_missing_requests(self):
        serv = MockServ()
        serv.expects('/test1').returns(body=b'hello1')
        serv.expects('/test2').returns(body=b'hello2')

        try:
            with serv:
                resp = requests.get('http://localhost:%d/test1' % serv.port)
                eq_(resp.content, b'hello1')
        except RequestsMismatchError as ex:
            assert 'requests mismatch:\n -  missing requests' in str(ex)
        else:
            raise AssertionError('AssertionError expected')
开发者ID:LKajan,项目名称:mapproxy,代码行数:13,代码来源:test_http_helper.py


示例19: test_too_many_requests

    def test_too_many_requests(self):
        serv = MockServ()
        serv.expects('/test1').returns(body=b'hello1')

        with serv:
            resp = requests.get('http://localhost:%d/test1' % serv.port)
            eq_(resp.content, b'hello1')
            try:
                requests.get('http://localhost:%d/test2' % serv.port)
            except requests.exceptions.RequestException:
                pass
            else:
                raise AssertionError('RequestException expected')
开发者ID:LKajan,项目名称:mapproxy,代码行数:13,代码来源:test_http_helper.py


示例20: test_get_map_uncached

    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)
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:16,代码来源:test_cache_mbtiles.py



注:本文中的mapproxy.test.http.MockServ类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python image.create_image函数代码示例发布时间:2022-05-27
下一篇:
Python http.mock_httpd函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap