Made project use a callback provider to avoid letting almost the whole world on blank
This commit is contained in:
@@ -26,12 +26,51 @@ class BuildTilesTests(unittest.TestCase):
|
||||
config = {"global": {"minzoom": 7, "maxzoom": 12}, "sources": {"Altis.kmz": {"minzoom": 9, "maxzoom": 14}}}
|
||||
self.assertEqual(build_tiles.effective_zooms(11, "Altis.kmz", config), (9, 14, True))
|
||||
|
||||
def test_callback_provider_accepts_safe_https_xyz_template(self):
|
||||
provider = build_tiles.validate_callback_provider("https://tiles.example.org/maps/{z}/{x}/{y}.png")
|
||||
self.assertEqual(provider.origin, "https://tiles.example.org")
|
||||
|
||||
def test_callback_provider_rejects_missing_or_unsafe_template(self):
|
||||
with self.assertRaises(build_tiles.ProviderValidationError):
|
||||
build_tiles.validate_callback_provider("http://tiles.example.org/{z}/{x}/{y}.png")
|
||||
with self.assertRaises(build_tiles.ProviderValidationError):
|
||||
build_tiles.validate_callback_provider("https://127.0.0.1/{z}/{x}/{y}.png")
|
||||
with self.assertRaises(build_tiles.ProviderValidationError):
|
||||
build_tiles.validate_callback_provider("https://tiles.example.org/{z}/{x}.png")
|
||||
|
||||
def test_config_normalizes_source_key(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "maps.json"
|
||||
path.write_text(json.dumps({"global": {}, "sources": {"nested\\map.kmz": {"minzoom": 8}}}))
|
||||
self.assertIn("nested/map.kmz", build_tiles.read_config(path)["sources"])
|
||||
|
||||
def test_publish_replaces_generated_output_directory(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
stage = root / "stage"
|
||||
output = root / "tiles"
|
||||
stage.mkdir()
|
||||
output.mkdir()
|
||||
(stage / "metadata.json").write_text("new")
|
||||
(stage / "8").mkdir()
|
||||
(stage / "8" / "tile.png").write_text("tile")
|
||||
(output / "stale.png").write_text("stale")
|
||||
build_tiles.publish(stage, output)
|
||||
self.assertFalse((output / "stale.png").exists())
|
||||
self.assertEqual((output / "metadata.json").read_text(), "new")
|
||||
self.assertTrue((output / "8" / "tile.png").is_file())
|
||||
|
||||
def test_empty_tile_is_opaque_white_png(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
target = Path(directory)
|
||||
build_tiles.write_empty_tile(target)
|
||||
with build_tiles.Image.open(target / "empty.png") as image:
|
||||
self.assertEqual(image.mode, "RGBA")
|
||||
self.assertEqual(image.size, (256, 256))
|
||||
self.assertEqual(image.getpixel((0, 0)), (255, 255, 255, 255))
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user