Example #1
0
 def test_get_cached(self, app, cache_dir, layer, source, wms_format,
                     cache_format, req_format):
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = (
             {
                 "path":
                 self.expected_base_path + "&layers=" + source +
                 "&format=image%2F" + req_format
             },
             {
                 "body": img.read(),
                 "headers": {
                     "content-type": "image/" + req_format
                 },
             },
         )
         with mock_httpd(("localhost", 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             self.common_map_req.params["layers"] = layer
             self.common_map_req.params["format"] = "image/" + wms_format
             resp = app.get(self.common_map_req)
             assert resp.content_type == "image/" + wms_format
             check_format(BytesIO(resp.body), wms_format)
     assert_file_format(
         cache_dir.join(layer + "_EPSG900913/01/000/000/001/000/000/001." +
                        cache_format),
         cache_format,
     )
Example #2
0
 def check_get_direct(self, layer, source, wms_format, req_format):
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = ({'path': self.expected_direct_base_path +
                                  '&layers=' + source +
                                  '&format=image%2F' + req_format},
                         {'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
         with mock_httpd(('localhost', 42423), [expected_req], bbox_aware_query_comparator=True):
             self.common_direct_map_req.params['layers'] = layer
             self.common_direct_map_req.params['format'] = 'image/'+wms_format
             resp = self.app.get(self.common_direct_map_req)
             eq_(resp.content_type, 'image/'+wms_format)
             check_format(BytesIO(resp.body), wms_format)
Example #3
0
 def check_get_cached(self, layer, source, wms_format, cache_format, req_format):
     self.created_tiles.append((layer+'_EPSG900913/01/000/000/001/000/000/001.'+cache_format, cache_format))
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = ({'path': self.expected_base_path +
                                  '&layers=' + source +
                                  '&format=image%2F' + req_format},
                         {'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
         with mock_httpd(('localhost', 42423), [expected_req]):
             self.common_map_req.params['layers'] = layer
             self.common_map_req.params['format'] = 'image/'+wms_format
             resp = self.app.get(self.common_map_req)
             eq_(resp.content_type, 'image/'+wms_format)
             check_format(StringIO(resp.body), wms_format)
Example #4
0
 def check_get_direct(self, layer, source, wms_format, req_format):
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = ({
             'path':
             self.expected_direct_base_path + '&layers=' + source +
             '&format=image%2F' + req_format
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/' + req_format
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req]):
             self.common_direct_map_req.params['layers'] = layer
             self.common_direct_map_req.params[
                 'format'] = 'image/' + wms_format
             resp = self.app.get(self.common_direct_map_req)
             eq_(resp.content_type, 'image/' + wms_format)
             check_format(StringIO(resp.body), wms_format)
Example #5
0
    def test_mixed_mode(self):
        req_format = 'png'
        transparent = 'True'
        with create_mixed_mode_img((512, 256)) as img:
            expected_req = ({
                'path':
                self.expected_base_path + '&layers=mixedsource' +
                '&format=image%2F' + req_format + '&transparent=' + transparent
            }, {
                'body': img.read(),
                'headers': {
                    'content-type': 'image/' + req_format
                }
            })
            with mock_httpd(('localhost', 42423), [expected_req]):
                self.common_map_req.params['format'] = 'image/' + req_format
                resp = self.app.get(self.common_map_req)
                self.created_tiles.append(
                    'mixed_cache_EPSG900913/01/000/000/000/000/000/001.mixed')
                self.created_tiles.append(
                    'mixed_cache_EPSG900913/01/000/000/001/000/000/001.mixed')

                eq_(resp.content_type, 'image/' + req_format)
                check_format(StringIO(resp.body), req_format)
                # GetMap Request is fully within the opaque tile
                assert not is_transparent(resp.body)

                # check cache formats
                cache_dir = base_config().cache.base_dir
                check_format(
                    open(os.path.join(cache_dir, self.created_tiles[0]), 'rb'),
                    'png')
                check_format(
                    open(os.path.join(cache_dir, self.created_tiles[1]), 'rb'),
                    'jpeg')
Example #6
0
    def test_mixed_mode(self, app, cache_dir):
        req_format = "png"
        transparent = "True"
        with create_mixed_mode_img((512, 256)) as img:
            expected_req = (
                {
                    "path":
                    self.expected_base_path + "&layers=mixedsource" +
                    "&format=image%2F" + req_format + "&transparent=" +
                    transparent
                },
                {
                    "body": img.read(),
                    "headers": {
                        "content-type": "image/" + req_format
                    },
                },
            )
            with mock_httpd(("localhost", 42423), [expected_req],
                            bbox_aware_query_comparator=True):
                self.common_map_req.params["format"] = "image/" + req_format
                resp = app.get(self.common_map_req)

                assert resp.content_type == "image/" + req_format
                check_format(BytesIO(resp.body), req_format)
                # GetMap Request is fully within the opaque tile
                assert not is_transparent(resp.body)

        # check cache formats
        for f, format in [
            ["mixed_cache_EPSG900913/01/000/000/000/000/000/001.mixed", "png"],
            [
                "mixed_cache_EPSG900913/01/000/000/001/000/000/001.mixed",
                "jpeg"
            ],
        ]:
            assert cache_dir.join(f).check()
            check_format(cache_dir.join(f).read_binary(), format)
Example #7
0
 def check_get_cached(self, layer, source, wms_format, cache_format,
                      req_format):
     self.created_tiles.append(
         (layer + '_EPSG900913/01/000/000/001/000/000/001.' + cache_format,
          cache_format))
     with tmp_image((256, 256), format=req_format) as img:
         expected_req = ({
             'path':
             self.expected_base_path + '&layers=' + source +
             '&format=image%2F' + req_format
         }, {
             'body': img.read(),
             'headers': {
                 'content-type': 'image/' + req_format
             }
         })
         with mock_httpd(('localhost', 42423), [expected_req],
                         bbox_aware_query_comparator=True):
             self.common_map_req.params['layers'] = layer
             self.common_map_req.params['format'] = 'image/' + wms_format
             resp = self.app.get(self.common_map_req)
             eq_(resp.content_type, 'image/' + wms_format)
             check_format(BytesIO(resp.body), wms_format)
    def test_mixed_mode(self):
        req_format = 'png'
        transparent = 'True'
        with create_mixed_mode_img((512, 256)) as img:
            expected_req = ({'path': self.expected_base_path +
                                     '&layers=mixedsource' +
                                     '&format=image%2F' + req_format +
                                     '&transparent=' + transparent},
                            {'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
            with mock_httpd(('localhost', 42423), [expected_req]):
                self.common_map_req.params['format'] = 'image/'+req_format
                resp = self.app.get(self.common_map_req)
                self.created_tiles.append('mixed_cache_EPSG900913/01/000/000/000/000/000/001.mixed')
                self.created_tiles.append('mixed_cache_EPSG900913/01/000/000/001/000/000/001.mixed')

                eq_(resp.content_type, 'image/'+req_format)
                check_format(StringIO(resp.body), req_format)
                # GetMap Request is fully within the opaque tile
                assert not is_transparent(resp.body)

                # check cache formats
                cache_dir = base_config().cache.base_dir
                check_format(open(os.path.join(cache_dir, self.created_tiles[0]), 'rb'), 'png')
                check_format(open(os.path.join(cache_dir, self.created_tiles[1]), 'rb'), 'jpeg')
Example #9
0
 def _test_created_tiles(self):
     for filename, format in self.created_tiles_filenames():
         if not os.path.exists(filename):
             assert False, "didn't found tile " + filename
         else:
             check_format(open(filename, 'rb'), format)
Example #10
0
def assert_file_format(filename, format):
    assert filename.check()
    check_format(filename.read_binary(), format)
Example #11
0
 def test_output_formats(self):
     img = Image.new("RGB", (100, 100))
     for format in ["png", "gif", "tiff", "jpeg", "GeoTIFF", "bmp"]:
         ir = ImageSource(img, (100, 100), image_opts=ImageOptions(format=format))
         check_format(ir.as_buffer(), format)
Example #12
0
 def _test_created_tiles(self):
     for filename, format in self.created_tiles_filenames():
         if not os.path.exists(filename):
             assert False, "didn't found tile " + filename
         else:
             check_format(open(filename, 'rb'), format)