Exemple #1
0
    def test_get_map_error(self):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data)
                eq_(task['command'], 'tile')
                # request main tile of metatile
                eq_(task['tiles'], [[15, 17, 5]])
                eq_(task['cache_identifier'], 'wms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'aeb52b506e4e82d0a1edf649d56e0451cfd5862c')

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    '{"status": "error", "error_message": "barf"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            self.common_map_req.params['bbox'] = '0,0,9,9'
            resp = self.app.get(self.common_map_req)

            eq_(resp.content_type, 'application/vnd.ogc.se_xml')
            is_111_exception(resp.lxml, re_msg='Error from renderd: barf')
Exemple #2
0
    def test_get_tile_error(self):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data)
                eq_(task['command'], 'tile')
                eq_(task['tiles'], [[10, 20, 7]])
                eq_(task['cache_identifier'], 'tms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'c24b8c3247afec34fd0a53e5d3706e977877ef47')

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(
                    '{"status": "error", "error_message": "you told me to fail"}'
                )

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            resp = self.app.get('/tiles/tms_cache/EPSG900913/7/10/20.png',
                                status=500)
            eq_(resp.content_type, 'text/plain')
            eq_(resp.body, 'Error from renderd: you told me to fail')
Exemple #3
0
    def test_get_tile(self):
        test_self = self
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode('utf-8'))
                eq_(task['command'], 'tile')
                eq_(task['tiles'], [[10, 20, 6]])
                eq_(task['cache_identifier'], 'tms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'cf35c1c927158e188d8fbe0db380c1772b536da9')

                # manually create tile renderd should create
                tile_filename = os.path.join(test_self.config['cache_dir'],
                    'tms_cache_EPSG900913/06/000/000/010/000/000/020.png')
                ensure_directory(tile_filename)
                with open(tile_filename, 'wb') as f:
                    f.write(b"foobaz")

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(b'{"status": "ok"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            resp = self.app.get('/tiles/tms_cache/EPSG900913/6/10/20.png')

            eq_(resp.content_type, 'image/png')
            eq_(resp.body, b'foobaz')
            self.created_tiles.append('tms_cache_EPSG900913/06/000/000/010/000/000/020.png')
    def test_get_tile_error(self):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode('utf-8'))
                eq_(task['command'], 'tile')
                eq_(task['tiles'], [[10, 20, 7]])
                eq_(task['cache_identifier'], 'tms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'c24b8c3247afec34fd0a53e5d3706e977877ef47')

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(b'{"status": "error", "error_message": "you told me to fail"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            resp = self.app.get('/tiles/tms_cache/EPSG900913/7/10/20.png', status=500)
            eq_(resp.content_type, 'text/plain')
            eq_(resp.body, b'Error from renderd: you told me to fail')
    def test_get_map_error(self):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode('utf-8'))
                eq_(task['command'], 'tile')
                # request main tile of metatile
                eq_(task['tiles'], [[15, 17, 5]])
                eq_(task['cache_identifier'], 'wms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'aeb52b506e4e82d0a1edf649d56e0451cfd5862c')

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(b'{"status": "error", "error_message": "barf"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            self.common_map_req.params['bbox'] = '0,0,9,9'
            resp = self.app.get(self.common_map_req)

            eq_(resp.content_type, 'application/vnd.ogc.se_xml')
            is_111_exception(resp.lxml, re_msg='Error from renderd: barf')
    def test_get_tile_error(self, app):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers["content-length"])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode("utf-8"))
                assert task["command"] == "tile"
                assert task["tiles"] == [[10, 20, 7]]
                assert task["cache_identifier"] == "tms_cache_GLOBAL_MERCATOR"
                assert task["priority"] == 100
                # this id should not change for the same tile/cache_identifier combination
                assert task["id"] == "c24b8c3247afec34fd0a53e5d3706e977877ef47"

                self.send_response(200)
                self.send_header("Content-type", "application/json")
                self.end_headers()
                self.wfile.write(
                    b'{"status": "error", "error_message": "you told me to fail"}'
                )

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(("localhost", 42423), req_handler):
            resp = app.get("/tiles/tms_cache/EPSG900913/7/10/20.png",
                           status=500)
            assert resp.content_type == "text/plain"
            assert resp.body == b"Error from renderd: you told me to fail"
    def test_get_tile(self, app, cache_dir):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers["content-length"])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode("utf-8"))
                assert task["command"] == "tile"
                assert task["tiles"] == [[10, 20, 6]]
                assert task["cache_identifier"] == "tms_cache_GLOBAL_MERCATOR"
                assert task["priority"] == 100
                # this id should not change for the same tile/cache_identifier combination
                assert task["id"] == "cf35c1c927158e188d8fbe0db380c1772b536da9"

                # manually create tile renderd should create
                cache_dir.join(
                    "tms_cache_EPSG900913/06/000/000/010/000/000/020.png"
                ).write_binary(b"foobaz", ensure=True)

                self.send_response(200)
                self.send_header("Content-type", "application/json")
                self.end_headers()
                self.wfile.write(b'{"status": "ok"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(("localhost", 42423), req_handler):
            resp = app.get("/tiles/tms_cache/EPSG900913/6/10/20.png")

            assert resp.content_type == "image/png"
            assert resp.body == b"foobaz"
        assert cache_dir.join(
            "tms_cache_EPSG900913/06/000/000/010/000/000/020.png").check()
    def test_get_map_error(self, app):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers["content-length"])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode("utf-8"))
                assert task["command"] == "tile"
                # request main tile of metatile
                assert task["tiles"] == [[15, 17, 5]]
                assert task["cache_identifier"] == "wms_cache_GLOBAL_MERCATOR"
                assert task["priority"] == 100
                # this id should not change for the same tile/cache_identifier combination
                assert task["id"] == "aeb52b506e4e82d0a1edf649d56e0451cfd5862c"

                self.send_response(200)
                self.send_header("Content-type", "application/json")
                self.end_headers()
                self.wfile.write(
                    b'{"status": "error", "error_message": "barf"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(("localhost", 42423), req_handler):
            self.common_map_req.params["bbox"] = "0,0,9,9"
            resp = app.get(self.common_map_req)

            assert resp.content_type == "application/vnd.ogc.se_xml"
            is_111_exception(resp.lxml, re_msg="Error from renderd: barf")
Exemple #9
0
    def test_get_map(self):
        test_self = self

        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data)
                eq_(task['command'], 'tile')
                # request main tile of metatile
                eq_(task['tiles'], [[15, 17, 5]])
                eq_(task['cache_identifier'], 'wms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'aeb52b506e4e82d0a1edf649d56e0451cfd5862c')

                # manually create tile renderd should create
                tile_filename = os.path.join(
                    test_self.config['cache_dir'],
                    'wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg')
                ensure_directory(tile_filename)
                with open(tile_filename, 'w') as f:
                    f.write(
                        create_tmp_image((256, 256),
                                         format='jpeg',
                                         color=(255, 0, 100)))

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write('{"status": "ok"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            self.common_map_req.params['bbox'] = '0,0,9,9'
            resp = self.app.get(self.common_map_req)

            img = img_from_buf(resp.body)
            main_color = sorted(img.convert('RGBA').getcolors())[-1]
            # check for red color (jpeg/png conversion requires fuzzy comparision)
            assert main_color[0] == 40000
            assert main_color[1][0] > 250
            assert main_color[1][1] < 5
            assert 95 < main_color[1][2] < 105
            assert main_color[1][3] == 255

            eq_(resp.content_type, 'image/png')
            self.created_tiles.append(
                'wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg')
    def test_get_map(self, app, cache_dir):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers["content-length"])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode("utf-8"))
                assert task["command"] == "tile"
                # request main tile of metatile
                assert task["tiles"] == [[15, 17, 5]]
                assert task["cache_identifier"] == "wms_cache_GLOBAL_MERCATOR"
                assert task["priority"] == 100
                # this id should not change for the same tile/cache_identifier combination
                assert task["id"] == "aeb52b506e4e82d0a1edf649d56e0451cfd5862c"

                # manually create tile renderd should create
                cache_dir.join(
                    "wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg"
                ).write_binary(
                    create_tmp_image((256, 256),
                                     format="jpeg",
                                     color=(255, 0, 100)),
                    ensure=True,
                )

                self.send_response(200)
                self.send_header("Content-type", "application/json")
                self.end_headers()
                self.wfile.write(b'{"status": "ok"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(("localhost", 42423), req_handler):
            self.common_map_req.params["bbox"] = "0,0,9,9"
            resp = app.get(self.common_map_req)

            img = img_from_buf(resp.body)
            main_color = sorted(img.convert("RGBA").getcolors())[-1]
            # check for red color (jpeg/png conversion requires fuzzy comparision)
            assert main_color[0] == 40000
            assert main_color[1][0] > 250
            assert main_color[1][1] < 5
            assert 95 < main_color[1][2] < 105
            assert main_color[1][3] == 255

            assert resp.content_type == "image/png"
        assert cache_dir.join(
            "wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg").check()
    def test_get_map(self):
        test_self = self
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                task = json.loads(json_data.decode('utf-8'))
                eq_(task['command'], 'tile')
                # request main tile of metatile
                eq_(task['tiles'], [[15, 17, 5]])
                eq_(task['cache_identifier'], 'wms_cache_GLOBAL_MERCATOR')
                eq_(task['priority'], 100)
                # this id should not change for the same tile/cache_identifier combination
                eq_(task['id'], 'aeb52b506e4e82d0a1edf649d56e0451cfd5862c')

                # manually create tile renderd should create
                tile_filename = os.path.join(test_self.config['cache_dir'],
                    'wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg')
                ensure_directory(tile_filename)
                with open(tile_filename, 'wb') as f:
                    f.write(create_tmp_image((256, 256), format='jpeg', color=(255, 0, 100)))

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(b'{"status": "ok"}')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            self.common_map_req.params['bbox'] = '0,0,9,9'
            resp = self.app.get(self.common_map_req)

            img = img_from_buf(resp.body)
            main_color = sorted(img.convert('RGBA').getcolors())[-1]
            # check for red color (jpeg/png conversion requires fuzzy comparision)
            assert main_color[0] == 40000
            assert main_color[1][0] > 250
            assert main_color[1][1] < 5
            assert 95 < main_color[1][2] < 105
            assert main_color[1][3] == 255

            eq_(resp.content_type, 'image/png')
            self.created_tiles.append('wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg')
Exemple #12
0
    def test_get_map_non_json_response(self):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers['content-length'])
                json_data = self.rfile.read(length)
                json.loads(json_data.decode('utf-8'))

                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                self.wfile.write(b'{"invalid')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(('localhost', 42423), req_handler):
            self.common_map_req.params['bbox'] = '0,0,9,9'
            resp = self.app.get(self.common_map_req)

        eq_(resp.content_type, 'application/vnd.ogc.se_xml')
        is_111_exception(resp.lxml, re_msg='Error while communicating with renderd: invalid JSON')
    def test_get_map_non_json_response(self, app):
        class req_handler(BaseHTTPRequestHandler):
            def do_POST(self):
                length = int(self.headers["content-length"])
                json_data = self.rfile.read(length)
                json.loads(json_data.decode("utf-8"))

                self.send_response(200)
                self.send_header("Content-type", "application/json")
                self.end_headers()
                self.wfile.write(b'{"invalid')

            def log_request(self, code, size=None):
                pass

        with mock_single_req_httpd(("localhost", 42423), req_handler):
            self.common_map_req.params["bbox"] = "0,0,9,9"
            resp = app.get(self.common_map_req)

        assert resp.content_type == "application/vnd.ogc.se_xml"
        is_111_exception(
            resp.lxml,
            re_msg="Error while communicating with renderd: invalid JSON")