def test_cleanup_sqlite(self): seed_conf = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf) cleanup_tasks = seed_conf.cleanups(['sqlite_cache']) cache = cleanup_tasks[0].tile_manager.cache cache.store_tile(self.create_tile((0, 0, 2))) cache.store_tile(self.create_tile((0, 0, 3))) assert cache.is_cached(Tile((0, 0, 2))) assert cache.is_cached(Tile((0, 0, 3))) assert_files_in_dir(os.path.join(self.dir, 'cache', 'sqlite_cache', 'GLOBAL_GEODETIC'), ['2.mbtile', '3.mbtile'], glob='*.mbtile') cleanup(cleanup_tasks, verbose=False, dry_run=False) # 3.mbtile file is still there assert_files_in_dir(os.path.join(self.dir, 'cache', 'sqlite_cache', 'GLOBAL_GEODETIC'), ['2.mbtile', '3.mbtile'], glob='*.mbtile') assert cache.is_cached(Tile((0, 0, 2))) assert not cache.is_cached(Tile((0, 0, 3)))
def test_cleanup_remove_all(self): seed_conf = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf) cleanup_tasks = seed_conf.cleanups(['remove_all']) self.make_tile((0, 0, 0)) self.make_tile((0, 0, 1)) self.make_tile((1, 0, 1)) self.make_tile((0, 1, 1)) self.make_tile((1, 1, 1)) self.make_tile((0, 0, 2)) self.make_tile((0, 0, 3)) assert_files_in_dir(os.path.join(self.dir, 'cache', 'one_EPSG4326'), ['00', '01', '02', '03']) cleanup(cleanup_tasks, verbose=False, dry_run=False) assert self.tile_exists((0, 0, 0)) assert not self.tile_exists((0, 0, 1)) assert not self.tile_exists((1, 0, 1)) assert not self.tile_exists((0, 1, 1)) assert not self.tile_exists((1, 1, 1)) assert not self.tile_exists((0, 0, 1)) assert self.tile_exists((0, 0, 2)) assert self.tile_exists((0, 0, 3)) # remove_all should remove the whole directory assert_files_in_dir(os.path.join(self.dir, 'cache', 'one_EPSG4326'), ['00', '02', '03'])
def test_remove_level_files(self): self.cache.store_tile(self.create_tile((0, 0, 1))) self.cache.store_tile(self.create_tile((0, 0, 2))) assert_files_in_dir(self.cache_dir, ['1.mbtile', '2.mbtile'], glob='*.mbtile') self.cache.remove_level_tiles_before(1, timestamp=0) assert_files_in_dir(self.cache_dir, ['2.mbtile'], glob='*.mbtile')
def test_bulk_store_tiles_with_different_levels(self): self.cache.store_tiles([ self.create_tile((0, 0, 1)), self.create_tile((0, 0, 2)), self.create_tile((1, 0, 2)), self.create_tile((1, 0, 1)), ]) assert_files_in_dir(self.cache_dir, ['1.mbtile', '2.mbtile'], glob='*.mbtile') assert self.cache.is_cached(Tile((0, 0, 1))) assert self.cache.is_cached(Tile((1, 0, 1))) assert self.cache.is_cached(Tile((0, 0, 2))) assert self.cache.is_cached(Tile((1, 0, 2)))
def test_remove_level_tiles_before(self): self.cache.store_tile(self.create_tile((0, 0, 1))) self.cache.store_tile(self.create_tile((0, 0, 2))) assert_files_in_dir(self.cache_dir, ['1.mbtile', '2.mbtile'], glob='*.mbtile') assert self.cache.is_cached(Tile((0, 0, 1))) self.cache.remove_level_tiles_before(1, timestamp=time.time() - 60) assert self.cache.is_cached(Tile((0, 0, 1))) self.cache.remove_level_tiles_before(1, timestamp=time.time() + 60) assert not self.cache.is_cached(Tile((0, 0, 1))) assert_files_in_dir(self.cache_dir, ['1.mbtile', '2.mbtile'], glob='*.mbtile') assert self.cache.is_cached(Tile((0, 0, 2)))
def test_cleanup_levels(self): seed_conf = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf) cleanup_tasks = seed_conf.cleanups(['cleanup']) self.make_tile((0, 0, 0)) self.make_tile((0, 0, 1)) self.make_tile((0, 0, 2)) self.make_tile((0, 0, 3)) cleanup(cleanup_tasks, verbose=False, dry_run=False) assert not self.tile_exists((0, 0, 0)) assert not self.tile_exists((0, 0, 1)) assert self.tile_exists((0, 0, 2)) assert not self.tile_exists((0, 0, 3)) assert_files_in_dir(os.path.join(self.dir, 'cache', 'one_EPSG4326'), ['02'])
def test_level_files(self): assert_files_in_dir(self.cache_dir, []) self.cache.store_tile(self.create_tile((0, 0, 1))) assert_files_in_dir(self.cache_dir, ['1.mbtile'], glob='*.mbtile') self.cache.store_tile(self.create_tile((0, 0, 5))) assert_files_in_dir(self.cache_dir, ['1.mbtile', '5.mbtile'], glob='*.mbtile')
def test_level_files(self): if os.path.exists(self.cache_dir): assert_files_in_dir(self.cache_dir, [], glob='*.gpkg') self.cache.store_tile(self.create_tile((0, 0, 1))) assert_files_in_dir(self.cache_dir, ['1.gpkg'], glob='*.gpkg') self.cache.store_tile(self.create_tile((0, 0, 5))) assert_files_in_dir(self.cache_dir, ['1.gpkg', '5.gpkg'], glob='*.gpkg')