Ejemplo n.º 1
0
 def setUp(self):
     self.tempfile = NamedTemporaryFile()
     # Use the PngRenderer because we want to know that callback
     # works properly.
     self.renderer = PngRenderer(png8=False, optimize=False)
     self.metadata = dict(
         name='transparent',
         type=Metadata.latest().TYPES.BASELAYER,
         version='1.0.0',
         description='Transparent World 2012',
         format=Metadata.latest().FORMATS.PNG,
     )
     self.storage = MbtilesStorage.create(renderer=self.renderer,
                                          filename=':memory:',
                                          metadata=self.metadata)
Ejemplo n.º 2
0
 def setUp(self):
     self.filename = ':memory:'
     self.version = '1.0'
     self.metadata = dict(
         name='transparent',
         type=Metadata.latest().TYPES.BASELAYER,
         version='1.0.0',
         description='Transparent World 2012',
     )
Ejemplo n.º 3
0
 def setUp(self):
     self.filename = ':memory:'
     self.version = '1.0'
     self.metadata = dict(
         name='transparent',
         type=Metadata.latest().TYPES.BASELAYER,
         version='1.0.0',
         description='Transparent World 2012',
     )
Ejemplo n.º 4
0
 def setUp(self):
     self.tempfile = NamedTemporaryFile(suffix='.mbtiles')
     self.filename = self.tempfile.name
     self.version = '1.0'
     self.metadata = dict(
         name='transparent',
         type=Metadata.latest().TYPES.BASELAYER,
         version='1.0.0',
         description='Transparent World 2012',
     )
Ejemplo n.º 5
0
 def setUp(self):
     self.tempfile = NamedTemporaryFile(suffix='.mbtiles')
     self.filename = self.tempfile.name
     self.version = '1.0'
     self.metadata = dict(
         name='transparent',
         type=Metadata.latest().TYPES.BASELAYER,
         version='1.0.0',
         description='Transparent World 2012',
     )
Ejemplo n.º 6
0
    def test_validate_1_0(self):
        version = '1.0'
        metadata = dict(
            name='transparent',
            type=Metadata.all()[version].TYPES.BASELAYER,
            version='1.0.0',
        )

        self.assertRaises(MetadataKeyError,
                          MBTiles.create, filename=self.filename, metadata={},
                          version=version)
        metadata.update(dict(
            description='Transparent World 2012',
        ))

        with MBTiles.create(filename=self.filename,
                            metadata=metadata) as mbtiles:
            self.assertEqual(mbtiles.version, version)

        with MBTiles.create(filename=self.filename,
                            metadata=metadata,
                            version=version) as mbtiles:
            metadata = mbtiles.metadata
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'name')
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'type')
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'version')
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'description')

            metadata['type'] = metadata.TYPES.OVERLAY
            self.assertEqual(metadata['type'], 'overlay')
            metadata['type'] = metadata.TYPES.BASELAYER
            self.assertEqual(metadata['type'], 'baselayer')
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'type', 'invalid')
Ejemplo n.º 7
0
    def test_validate_1_0(self):
        version = '1.0'
        metadata = dict(
            name='transparent',
            type=Metadata.all()[version].TYPES.BASELAYER,
            version='1.0.0',
        )

        self.assertRaises(MetadataKeyError,
                          MBTiles.create,
                          filename=self.filename,
                          metadata={},
                          version=version)
        metadata.update(dict(description='Transparent World 2012', ))

        with MBTiles.create(filename=self.filename,
                            metadata=metadata) as mbtiles:
            self.assertEqual(mbtiles.version, version)

        with MBTiles.create(filename=self.filename,
                            metadata=metadata,
                            version=version) as mbtiles:
            metadata = mbtiles.metadata
            self.assertRaises(MetadataKeyError, metadata.__delitem__, 'name')
            self.assertRaises(MetadataKeyError, metadata.__delitem__, 'type')
            self.assertRaises(MetadataKeyError, metadata.__delitem__,
                              'version')
            self.assertRaises(MetadataKeyError, metadata.__delitem__,
                              'description')

            metadata['type'] = metadata.TYPES.OVERLAY
            self.assertEqual(metadata['type'], 'overlay')
            metadata['type'] = metadata.TYPES.BASELAYER
            self.assertEqual(metadata['type'], 'baselayer')
            self.assertRaises(MetadataValueError, metadata.__setitem__, 'type',
                              'invalid')
Ejemplo n.º 8
0
    def test_validate_1_2(self):
        version = '1.2'
        metadata = dict(
            name='transparent',
            type=Metadata.all()[version].TYPES.BASELAYER,
            version='1.0.0',
            description='Transparent World 2012',
        )

        self.assertRaises(MetadataKeyError,
                          MBTiles.create, filename=self.filename,
                          metadata=self.metadata, version=version)
        metadata.update(dict(
            format=Metadata.all()[version].FORMATS.PNG,
            bounds='-180.0,-85,180,85',
            attribution='Brought to you by the letter A and the number 1.',
        ))

        with MBTiles.create(filename=self.filename,
                            metadata=metadata) as mbtiles:
            self.assertEqual(mbtiles.version, version)

        with MBTiles.create(filename=self.filename,
                            metadata=metadata,
                            version=version) as mbtiles:
            metadata = mbtiles.metadata
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'name')
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'type')
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'version')
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'description')
            self.assertRaises(MetadataKeyError,
                              metadata.__delitem__, 'format')

            metadata['type'] = metadata.TYPES.OVERLAY
            self.assertEqual(metadata['type'], 'overlay')
            metadata['type'] = metadata.TYPES.BASELAYER
            self.assertEqual(metadata['type'], 'baselayer')
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'type', 'invalid')

            metadata['format'] = metadata.FORMATS.PNG
            self.assertEqual(metadata['format'], 'png')
            metadata['format'] = metadata.FORMATS.JPG
            self.assertEqual(metadata['format'], 'jpg')
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'format', 'invalid')

            metadata['bounds'] = '-1,-1,1,1'
            metadata['bounds'] = '-1.0,-1.0,1.0,1.0'
            metadata['bounds'] = '-1.0,-1.0,1.0,1.0'
            # left < -180
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '-180.1,-1,1,1')
            # bottom < -90
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '-1,-90.1,1,1')
            # right > 180
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '-1,-1,180.1,1')
            # top > 90
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '-1,-1,1,90.1')
            # left == right
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '1,-1,1,1')
            # left > right
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '1.1,-1,1,1')
            # bottom == top
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '-1,1,1,1')
            # bottom > top
            self.assertRaises(MetadataValueError,
                              metadata.__setitem__, 'bounds', '-1,1.1,1,1')
Ejemplo n.º 9
0
def jpgtile(name, x, y, z, folder=''):
    """Responds with a JPEG for `name` at (`x`, `y``, `z``)."""
    return tile(name=name, x=x, y=y, z=z,
                format=Metadata.latest().FORMATS.JPG,
                content_type='image/jpeg', folder=folder)
Ejemplo n.º 10
0
def tile_png(name, x, y, z, folder=''):
    """Responds with a PNG for `name` at (`x`, `y``, `z``)."""
    return tile(name=name, x=x, y=y, z=z,
                format=Metadata.latest().FORMATS.PNG,
                content_type='image/png', folder=folder)
Ejemplo n.º 11
0
    def test_validate_1_2(self):
        version = '1.2'
        metadata = dict(
            name='transparent',
            type=Metadata.all()[version].TYPES.BASELAYER,
            version='1.0.0',
            description='Transparent World 2012',
        )

        self.assertRaises(MetadataKeyError,
                          MBTiles.create,
                          filename=self.filename,
                          metadata=self.metadata,
                          version=version)
        metadata.update(
            dict(
                format=Metadata.all()[version].FORMATS.PNG,
                bounds='-180.0,-85,180,85',
                attribution='Brought to you by the letter A and the number 1.',
            ))

        with MBTiles.create(filename=self.filename,
                            metadata=metadata) as mbtiles:
            self.assertEqual(mbtiles.version, version)

        with MBTiles.create(filename=self.filename,
                            metadata=metadata,
                            version=version) as mbtiles:
            metadata = mbtiles.metadata
            self.assertRaises(MetadataKeyError, metadata.__delitem__, 'name')
            self.assertRaises(MetadataKeyError, metadata.__delitem__, 'type')
            self.assertRaises(MetadataKeyError, metadata.__delitem__,
                              'version')
            self.assertRaises(MetadataKeyError, metadata.__delitem__,
                              'description')
            self.assertRaises(MetadataKeyError, metadata.__delitem__, 'format')

            metadata['type'] = metadata.TYPES.OVERLAY
            self.assertEqual(metadata['type'], 'overlay')
            metadata['type'] = metadata.TYPES.BASELAYER
            self.assertEqual(metadata['type'], 'baselayer')
            self.assertRaises(MetadataValueError, metadata.__setitem__, 'type',
                              'invalid')

            metadata['format'] = metadata.FORMATS.PNG
            self.assertEqual(metadata['format'], 'png')
            metadata['format'] = metadata.FORMATS.JPG
            self.assertEqual(metadata['format'], 'jpg')
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'format', 'invalid')

            metadata['bounds'] = '-1,-1,1,1'
            metadata['bounds'] = '-1.0,-1.0,1.0,1.0'
            metadata['bounds'] = '-1.0,-1.0,1.0,1.0'
            # left < -180
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '-180.1,-1,1,1')
            # bottom < -90
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '-1,-90.1,1,1')
            # right > 180
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '-1,-1,180.1,1')
            # top > 90
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '-1,-1,1,90.1')
            # left == right
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '1,-1,1,1')
            # left > right
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '1.1,-1,1,1')
            # bottom == top
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '-1,1,1,1')
            # bottom > top
            self.assertRaises(MetadataValueError, metadata.__setitem__,
                              'bounds', '-1,1.1,1,1')