当前位置: 首页>>代码示例>>Python>>正文


Python http.mock_httpd函数代码示例

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


在下文中一共展示了mock_httpd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_timeouts

    def test_timeouts(self):
        test_req = ({'path': '/', 'req_assert_function': lambda x: time.sleep(0.9) or True},
                    {'body': b'nothing'})

        import mapproxy.client.http

        client1 = HTTPClient(timeout=0.1)
        client2 = HTTPClient(timeout=0.5)
        with mock_httpd(TESTSERVER_ADDRESS, [test_req]):
            try:
                start = time.time()
                client1.open(TESTSERVER_URL + '/')
            except HTTPClientError as ex:
                assert 'timed out' in ex.args[0]
            else:
                assert False, 'HTTPClientError expected'
            duration1 = time.time() - start

        with mock_httpd(TESTSERVER_ADDRESS, [test_req]):
            try:
                start = time.time()
                client2.open(TESTSERVER_URL + '/')
            except HTTPClientError as ex:
                assert 'timed out' in ex.args[0]
            else:
                assert False, 'HTTPClientError expected'
            duration2 = time.time() - start

        # check individual timeouts
        assert 0.1 <= duration1 < 0.5, duration1
        assert 0.5 <= duration2 < 0.9, duration2
开发者ID:LKajan,项目名称:mapproxy,代码行数:31,代码来源:test_client.py

示例2: test_request_not_parsable

 def test_request_not_parsable(self):
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/', 'method': 'GET'},
                                           {'status': '200', 'body': ''})]):
         with capture_out() as (out,err):
             assert_raises(SystemExit, wms_capabilities_command, self.args)
         error_msg = err.getvalue().rsplit('-'*80, 1)[1].strip()
         assert error_msg.startswith('Could not parse the document')
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:7,代码来源:test_util_wms_capabilities.py

示例3: test_get_multiple_featureinfo_html_out

 def test_get_multiple_featureinfo_html_out(self):
     fi_body1 = "<a><b>Bar1</b></a>"
     fi_body2 = "<a><b>Bar2</b></a>"
     fi_body3 = "<body><h1>Hello<p>Bar3"
     expected_req1 = ({'path': r'/service_a?LAYERs=a_one&SERVICE=WMS&FORMAT=image%2Fpng'
                               '&REQUEST=GetFeatureInfo&HEIGHT=200&CRS=EPSG%3A900913'
                               '&VERSION=1.3.0&BBOX=1000.0,400.0,2000.0,1400.0&styles='
                               '&WIDTH=200&QUERY_LAYERS=a_one&i=10&J=20&info_format=text/xml'},
                     {'body': fi_body1, 'headers': {'content-type': 'text/xml'}})
     expected_req2 = ({'path': r'/service_b?LAYERs=b_one&SERVICE=WMS&FORMAT=image%2Fpng'
                               '&REQUEST=GetFeatureInfo&HEIGHT=200&SRS=EPSG%3A900913'
                               '&VERSION=1.1.1&BBOX=1000.0,400.0,2000.0,1400.0&styles='
                               '&WIDTH=200&QUERY_LAYERS=b_one&X=10&Y=20&info_format=text/xml'},
                     {'body': fi_body2, 'headers': {'content-type': 'text/xml'}})
     expected_req3 = ({'path': r'/service_d?LAYERs=d_one&SERVICE=WMS&FORMAT=image%2Fpng'
                               '&REQUEST=GetFeatureInfo&HEIGHT=200&SRS=EPSG%3A900913'
                               '&VERSION=1.1.1&BBOX=1000.0,400.0,2000.0,1400.0&styles='
                               '&WIDTH=200&QUERY_LAYERS=d_one&X=10&Y=20&info_format=text/html'},
                     {'body': fi_body3, 'headers': {'content-type': 'text/html'}})
     with mock_httpd(('localhost', 42423), [expected_req1, expected_req2, expected_req3]):
         self.common_fi_req.params['layers'] = 'fi_multi_layer'
         self.common_fi_req.params['query_layers'] = 'fi_multi_layer'
         self.common_fi_req.params['info_format'] = 'text/html'
         resp = self.app.get(self.common_fi_req)
         eq_(resp.content_type, 'text/html')
         eq_(strip_whitespace(resp.body),
             '<html><body><h1>Bars</h1><p>Bar1</p><p>Bar2</p><p>Bar3</p></body></html>')
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:27,代码来源:test_xslt_featureinfo.py

示例4: test_layers_with_opacity

    def test_layers_with_opacity(self):
        # overlay with opacity -> request should not be combined
        common_params = (r'?SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                                  '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                                  '&WIDTH=200')

        img_bg = create_tmp_image((200, 200), color=(0, 0, 0))
        img_fg = create_tmp_image((200, 200), color=(255, 0, 128))

        expected_req = [
                        ({'path': '/service_a' + common_params + '&layers=a_one'},
                         {'body': img_bg, 'headers': {'content-type': 'image/png'}}),
                        ({'path': '/service_a' + common_params + '&layers=a_two'},
                         {'body': img_fg, 'headers': {'content-type': 'image/png'}}),
                        ]

        with mock_httpd(('localhost', 42423), expected_req):
            self.common_map_req.params.layers = 'opacity_base,opacity_overlay'
            resp = self.app.get(self.common_map_req)
            eq_(resp.content_type, 'image/png')
            data = BytesIO(resp.body)
            assert is_png(data)
            img = Image.open(data)
            eq_(img.getcolors()[0], ((200*200),(127, 0, 64)))
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:25,代码来源:test_combined_sources.py

示例5: test_timeout

    def test_timeout(self):
        # test concurrent seeding where seed concurrency is higher than the permitted
        # concurrent_request value of the source and a lock times out

        seed_conf  = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
        tasks = seed_conf.seeds(['test'])
        
        expected_req1 = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                          '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                          '&width=256&height=128&srs=EPSG:4326'},
                        {'body': tile_image, 'headers': {'content-type': 'image/png'}, 'duration': 0.1})
        
        expected_req2 = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                          '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                          '&width=512&height=256&srs=EPSG:4326'},
                        {'body': tile_image, 'headers': {'content-type': 'image/png'}, 'duration': 0.1})

        expected_req3 = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                          '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                          '&width=1024&height=512&srs=EPSG:4326'},
                        {'body': tile_image, 'headers': {'content-type': 'image/png'}, 'duration': 0.1})


        with mock_httpd(('localhost', 42423), [expected_req1, expected_req2, expected_req3], unordered=True):
            seed(tasks, dry_run=False, concurrency=3)
开发者ID:cedricmoullet,项目名称:mapproxy,代码行数:25,代码来源:test_seed.py

示例6: test_seed_refresh_remove_before_from_file

    def test_seed_refresh_remove_before_from_file(self):
        # tile already there but too old, will be refreshed and removed
        t000 = self.make_tile((0, 0, 0), timestamp=time.time() - (60*60*25))
        with tmp_image((256, 256), format='png') as img:
            img_data = img.read()
            expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
                                  '&width=256&height=128&srs=EPSG:4326'},
                            {'body': img_data, 'headers': {'content-type': 'image/png'}})
            with mock_httpd(('localhost', 42423), [expected_req]):
                # touch the seed_conf file and refresh everything
                timestamp = time.time() - 60
                os.utime(self.seed_conf_file, (timestamp, timestamp))
                
                with local_base_config(self.mapproxy_conf.base_config):
                    seed_conf  = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
                    tasks = seed_conf.seeds(['refresh_from_file'])

                    seed(tasks, dry_run=False)

                assert os.path.exists(t000)
                assert os.path.getmtime(t000) - 5 < time.time() < os.path.getmtime(t000) + 5
        
                # now touch the seed_conf again and remove everything
                os.utime(self.seed_conf_file, None)
                with local_base_config(self.mapproxy_conf.base_config):
                    seed_conf  = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
                    cleanup_tasks = seed_conf.cleanups(['remove_from_file'])
                    cleanup(cleanup_tasks, verbose=False, dry_run=False)
开发者ID:ChrisRenton,项目名称:mapproxy,代码行数:29,代码来源:test_seed.py

示例7: test_sld_url

 def test_sld_url(self):
     self.common_map_req.params['layers'] = 'sld_url'
     with mock_httpd(TESTSERVER_ADDRESS, [
       ({'path': self.common_wms_url + '&sld=' +quote('http://example.org/sld.xml'),
         'method': 'GET'},
        {'body': ''})]):
         self.app.get(self.common_map_req)
开发者ID:atrawog,项目名称:mapproxy,代码行数:7,代码来源:test_sld.py

示例8: test_mixed_featureinfo

 def test_mixed_featureinfo(self):
     fi_body1 = "Hello"
     fi_body2 = "<a><b>Bar2</b></a>"
     expected_req1 = (
         {
             "path": r"/service_c?LAYERs=c_one&SERVICE=WMS&FORMAT=image%2Fpng"
             "&REQUEST=GetFeatureInfo&HEIGHT=200&SRS=EPSG%3A900913"
             "&VERSION=1.1.1&BBOX=1000.0,400.0,2000.0,1400.0&styles="
             "&WIDTH=200&QUERY_LAYERS=c_one&X=10&Y=20"
         },
         {"body": fi_body1, "headers": {"content-type": "text/plain"}},
     )
     expected_req2 = (
         {
             "path": r"/service_a?LAYERs=a_one&SERVICE=WMS&FORMAT=image%2Fpng"
             "&REQUEST=GetFeatureInfo&HEIGHT=200&CRS=EPSG%3A900913"
             "&VERSION=1.3.0&BBOX=1000.0,400.0,2000.0,1400.0&styles="
             "&WIDTH=200&QUERY_LAYERS=a_one&i=10&J=20&info_format=text/xml"
         },
         {"body": fi_body2, "headers": {"content-type": "text/xml"}},
     )
     with mock_httpd(("localhost", 42423), [expected_req1, expected_req2]):
         self.common_fi_req.params["layers"] = "fi_without_xslt_layer,fi_layer"
         self.common_fi_req.params["query_layers"] = "fi_without_xslt_layer,fi_layer"
         resp = self.app.get(self.common_fi_req)
         eq_(resp.content_type, "text/plain")
         eq_(strip_whitespace(resp.body), "Hello<baz><foo>Bar2</foo></baz>")
开发者ID:quiqua,项目名称:mapproxy,代码行数:27,代码来源:test_xslt_featureinfo.py

示例9: test_sld_body

 def test_sld_body(self):
     self.common_map_req.params['layers'] = 'sld_body'
     with mock_httpd(TESTSERVER_ADDRESS, [
       ({'path': self.common_wms_url + '&sld_body=' +quote('<sld:StyledLayerDescriptor />'),
         'method': 'POST'},
        {'body': ''})]):
         self.app.get(self.common_map_req)
开发者ID:atrawog,项目名称:mapproxy,代码行数:7,代码来源:test_sld.py

示例10: test_combined_mixed_fwd_req_params

    def test_combined_mixed_fwd_req_params(self):
        # not merged to one request because fwd_req_params are different
        common_params = (r'/service_a?SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
                                  '&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
                                  '&WIDTH=200&transparent=True')

        with tmp_image((200, 200), format='png') as img:
            img = img.read()
            expected_req = [({'path': common_params + '&layers=a_one&TIME=20041012'},
                             {'body': img, 'headers': {'content-type': 'image/png'}}),
                             ({'path': common_params + '&layers=a_two&TIME=20041012&VENDOR=foo'},
                             {'body': img, 'headers': {'content-type': 'image/png'}}),
                             ({'path': common_params + '&layers=a_four'},
                             {'body': img, 'headers': {'content-type': 'image/png'}}),
                            ]

            with mock_httpd(('localhost', 42423), expected_req):
                self.common_map_req.params.layers = 'layer_fwdparams1,single'
                self.common_map_req.params['time'] = '20041012'
                self.common_map_req.params['vendor'] = 'foo'
                self.common_map_req.params.transparent = True
                resp = self.app.get(self.common_map_req)
                resp.content_type = 'image/png'
                data = BytesIO(resp.body)
                assert is_png(data)
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:26,代码来源:test_combined_sources.py

示例11: test_arcgiscache_path

 def test_arcgiscache_path(self):
     template = TileURLTemplate(TESTSERVER_URL + '/%(arcgiscache_path)s.png')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/L09/R0000000d/C00000005.png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
开发者ID:Geodan,项目名称:mapproxy,代码行数:8,代码来源:test_client.py

示例12: test_xyz

 def test_xyz(self):
     template = TileURLTemplate(TESTSERVER_URL + '/x=%(x)s&y=%(y)s&z=%(z)s&format=%(format)s')
     client = TileClient(template)
     with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/x=5&y=13&z=9&format=png'},
                                           {'body': b'tile',
                                            'headers': {'content-type': 'image/png'}})]):
         resp = client.get_tile((5, 13, 9)).source.read()
         eq_(resp, b'tile')
开发者ID:Geodan,项目名称:mapproxy,代码行数:8,代码来源:test_client.py

示例13: test_get_tile_intersection_tms

 def test_get_tile_intersection_tms(self):
     with tmp_image((256, 256), format='jpeg') as img:
         expected_req = ({'path': r'/tms/1.0.0/foo/1/1/1.jpeg'},
                         {'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             resp = self.app.get('/tms/1.0.0/tms_cache/0/1/1.jpeg')
             eq_(resp.content_type, 'image/jpeg')
             self.created_tiles.append('tms_cache_EPSG900913/01/000/000/001/000/000/001.jpeg')
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:8,代码来源:test_coverage.py

示例14: test_get_tile_from_missing_arcgis_layer

    def test_get_tile_from_missing_arcgis_layer(self):
        expected_req = [({'path': '/arcgis/rest/services/NonExistentLayer/ImageServer/exportImage?f=image&format=png&imageSR=900913&bboxSR=900913&bbox=-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244&size=512,512'},
                 {'body': b'', 'status': 400}),
                ]

        with mock_httpd(('localhost', 42423), expected_req, bbox_aware_query_comparator=True):
            resp = self.app.get('/tms/1.0.0/app2_wrong_url_layer/0/0/1.png', status=500)
            eq_(resp.status_code, 500)
开发者ID:tjay,项目名称:mapproxy,代码行数:8,代码来源:test_arcgis.py

示例15: test_sld_file

 def test_sld_file(self):
     self.common_map_req.params['layers'] = 'sld_file'
     with mock_httpd(TESTSERVER_ADDRESS, [
       ({'path': self.common_wms_url + '&sld_body=' +quote('<sld>'), 'method': 'GET'},
        {'body': create_tmp_image((200, 200), format='png')}
       )]):
         resp = self.app.get(self.common_map_req)
         eq_(resp.content_type, 'image/png')
开发者ID:LKajan,项目名称:mapproxy,代码行数:8,代码来源:test_sld.py


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