예제 #1
0
class MBTilesManagerCatalogsTest(MBTilesManagerTest):

    def setUp(self):
        super(MBTilesManagerCatalogsTest, self).setUp()
        try:
            os.mkdir(os.path.join(FIXTURES_PATH, 'pouet'))
            shutil.copy(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'), os.path.join(FIXTURES_PATH, 'pouet', 'country.mbtiles'))
        except OSError:
            pass

    def tearDown(self):
        super(MBTilesManagerCatalogsTest, self).tearDown()
        try:
            shutil.rmtree(os.path.join(FIXTURES_PATH, 'pouet'))
        except OSError:
            pass

    def test_transparent_if_catalog_is_default(self):
        fullpath = self.mgr.catalog_path()
        self.assertEqual(fullpath, app_settings.MBTILES_ROOT)

    def test_error_if_catalog_is_unknown(self):
        self.assertRaises(MBTilesNotFoundError, self.mgr.catalog_path, ('paf'))

    def test_default_catalog_is_root_if_files_present(self):
        default = self.mgr.default_catalog()
        self.assertEqual(default, None)

    def test_default_catalog_is_first_folder_if_no_files(self):
        # Move all files to other
        shutil.move(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'), '/tmp/france-35.mbtiles')
        shutil.move(os.path.join(FIXTURES_PATH, 'geography-class.mbtiles'), '/tmp/geography-class.mbtiles')
        try:
            default = self.mgr.default_catalog()
            self.assertEqual(default, 'pouet')
        finally:
            # Move back
            shutil.move('/tmp/france-35.mbtiles', os.path.join(FIXTURES_PATH, 'france-35.mbtiles'))
            shutil.move('/tmp/geography-class.mbtiles', os.path.join(FIXTURES_PATH, 'geography-class.mbtiles'))

    def test_manager_should_fail_if_folder_does_not_exist(self):
        app_settings.MBTILES_ROOT = "/tmp/paf"
        self.assertRaises(MBTilesFolderError, MBTilesManager)

    def test_manager_should_fail_if_catalog_does_not_exist(self):
        self.assertRaises(MBTilesNotFoundError, self.mgr.filter, catalog='paf')

    def test_manager_should_restrict_list_to_catalog(self):
        self.mgr = MBTilesManager()
        listed = sorted([o.id for o in self.mgr.all()])
        self.failUnlessEqual(['france-35', 'geography-class'], listed)

        listed = sorted([o.id for o in self.mgr.filter(catalog='pouet').all()])
        self.failUnlessEqual(['country'], listed)

    def test_mbtiles_should_fail_if_mbtiles_does_not_exist(self):
        MBTiles('country', catalog='pouet')
        self.assertRaises(MBTilesNotFoundError, MBTiles, 'country', catalog='paf')
예제 #2
0
class MBTilesManagerTest(TestCase):

    def setUp(self):
        self.root_orig = app_settings.MBTILES_ROOT
        self.mgr = MBTilesManager()

    def tearDown(self):
        app_settings.MBTILES_ROOT = self.root_orig

    def test_files_in_folder(self):
        self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in self.mgr.all()]))
        # Can be called twice with same result
        qs = self.mgr.all()
        self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in qs]))
        self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in qs]))

    def test_files_list_is_dynamic(self):
        extrafile = os.path.join(FIXTURES_PATH, 'file.mbtiles')
        shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'), extrafile)
        self.failUnlessEqual(['file', 'france-35', 'geography-class'], sorted([o.id for o in self.mgr.all()]))
        os.remove(extrafile)

    def test_unsupported_extensions_are_ignored(self):
        extrafile = os.path.join(FIXTURES_PATH, 'file.wrong')
        shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'), extrafile)
        self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in self.mgr.all()]))
        # Except if we change the setting extension
        app_settings.MBTILES_EXT = 'wrong'
        self.failUnlessEqual(['file'], [o.id for o in self.mgr.all()])
        os.remove(extrafile)
        app_settings.MBTILES_EXT = 'mbtiles'

    def test_no_error_if_folder_is_empty(self):
        # Try a folder without mbtiles
        app_settings.MBTILES_ROOT = '.'
        self.mgr = MBTilesManager()
        self.failIfEqual(['france-35'], [o.id for o in self.mgr.all()])

    def test_error_if_folder_is_missing(self):
        app_settings.MBTILES_ROOT = "random-path-xyz"
        self.assertRaises(MBTilesFolderError, MBTilesManager)
예제 #3
0
 def test_list(self):
     # Use fixtures folder
     mgr = MBTilesManager()
     self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in mgr.all()]))
     # Can be called twice with same result
     qs = mgr.all()
     self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in qs]))
     self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in qs]))
     # And is refreshed
     extrafile = os.path.join(FIXTURES_PATH, 'file.mbtiles')
     shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'), extrafile)
     self.failUnlessEqual(['file', 'france-35', 'geography-class'], sorted([o.id for o in mgr.all()]))
     os.remove(extrafile)
     # File with different extensions are ignored
     extrafile = os.path.join(FIXTURES_PATH, 'file.wrong')
     shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'), extrafile)
     self.failUnlessEqual(['france-35', 'geography-class'], sorted([o.id for o in mgr.all()]))
     # Except if we change the setting extension
     app_settings.MBTILES_EXT = 'wrong'
     self.failUnlessEqual(['file'], [o.id for o in mgr.all()])
     os.remove(extrafile)
     app_settings.MBTILES_EXT = 'mbtiles'
     # Try a folder without mbtiles
     app_settings.MBTILES_ROOT = '.'
     mgr = MBTilesManager()
     self.failIfEqual(['france-35'], [o.id for o in mgr.all()])
     # Try with a bad (=empty) mbtiles file
     extrafile = os.path.join(FIXTURES_PATH, 'file.png')
     self.failIfEqual(['file'], [o.id for o in mgr.all()])
     open(extrafile, 'w').close()
     os.remove(extrafile)
     # Try a unexisting folder
     app_settings.MBTILES_ROOT = "random-path-xyz"
     self.assertRaises(MBTilesFolderError, MBTilesManager)
예제 #4
0
class MBTilesManagerTest(TestCase):
    def setUp(self):
        self.root_orig = app_settings.MBTILES_ROOT
        self.mgr = MBTilesManager()

    def tearDown(self):
        app_settings.MBTILES_ROOT = self.root_orig

    def test_files_in_folder(self):
        self.failUnlessEqual(['france-35', 'geography-class'],
                             sorted([o.id for o in self.mgr.all()]))
        # Can be called twice with same result
        qs = self.mgr.all()
        self.failUnlessEqual(['france-35', 'geography-class'],
                             sorted([o.id for o in qs]))
        self.failUnlessEqual(['france-35', 'geography-class'],
                             sorted([o.id for o in qs]))

    def test_files_list_is_dynamic(self):
        extrafile = os.path.join(FIXTURES_PATH, 'file.mbtiles')
        shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'),
                        extrafile)
        self.failUnlessEqual(['file', 'france-35', 'geography-class'],
                             sorted([o.id for o in self.mgr.all()]))
        os.remove(extrafile)

    def test_unsupported_extensions_are_ignored(self):
        extrafile = os.path.join(FIXTURES_PATH, 'file.wrong')
        shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'),
                        extrafile)
        self.failUnlessEqual(['france-35', 'geography-class'],
                             sorted([o.id for o in self.mgr.all()]))
        # Except if we change the setting extension
        app_settings.MBTILES_EXT = 'wrong'
        self.failUnlessEqual(['file'], [o.id for o in self.mgr.all()])
        os.remove(extrafile)
        app_settings.MBTILES_EXT = 'mbtiles'

    def test_no_error_if_folder_is_empty(self):
        # Try a folder without mbtiles
        app_settings.MBTILES_ROOT = '.'
        self.mgr = MBTilesManager()
        self.failIfEqual(['france-35'], [o.id for o in self.mgr.all()])

    def test_error_if_folder_is_missing(self):
        app_settings.MBTILES_ROOT = "random-path-xyz"
        self.assertRaises(MBTilesFolderError, MBTilesManager)
예제 #5
0
 def test_list(self):
     # Use fixtures folder
     mgr = MBTilesManager()
     self.failUnlessEqual(['france-35', 'geography-class'],
                          sorted([o.id for o in mgr.all()]))
     # Can be called twice with same result
     qs = mgr.all()
     self.failUnlessEqual(['france-35', 'geography-class'],
                          sorted([o.id for o in qs]))
     self.failUnlessEqual(['france-35', 'geography-class'],
                          sorted([o.id for o in qs]))
     # And is refreshed
     extrafile = os.path.join(FIXTURES_PATH, 'file.mbtiles')
     shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'),
                     extrafile)
     self.failUnlessEqual(['file', 'france-35', 'geography-class'],
                          sorted([o.id for o in mgr.all()]))
     os.remove(extrafile)
     # File with different extensions are ignored
     extrafile = os.path.join(FIXTURES_PATH, 'file.wrong')
     shutil.copyfile(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'),
                     extrafile)
     self.failUnlessEqual(['france-35', 'geography-class'],
                          sorted([o.id for o in mgr.all()]))
     # Except if we change the setting extension
     app_settings.MBTILES_EXT = 'wrong'
     self.failUnlessEqual(['file'], [o.id for o in mgr.all()])
     os.remove(extrafile)
     app_settings.MBTILES_EXT = 'mbtiles'
     # Try a folder without mbtiles
     app_settings.MBTILES_ROOT = '.'
     mgr = MBTilesManager()
     self.failIfEqual(['france-35'], [o.id for o in mgr.all()])
     # Try with a bad (=empty) mbtiles file
     extrafile = os.path.join(FIXTURES_PATH, 'file.png')
     self.failIfEqual(['file'], [o.id for o in mgr.all()])
     open(extrafile, 'w').close()
     os.remove(extrafile)
     # Try a unexisting folder
     app_settings.MBTILES_ROOT = "random-path-xyz"
     self.assertRaises(MBTilesFolderError, MBTilesManager)
예제 #6
0
class MBTilesManagerCatalogsTest(MBTilesManagerTest):
    def setUp(self):
        super(MBTilesManagerCatalogsTest, self).setUp()
        try:
            os.mkdir(os.path.join(FIXTURES_PATH, 'pouet'))
            shutil.copy(
                os.path.join(FIXTURES_PATH, 'france-35.mbtiles'),
                os.path.join(FIXTURES_PATH, 'pouet', 'country.mbtiles'))
        except OSError:
            pass

    def tearDown(self):
        super(MBTilesManagerCatalogsTest, self).tearDown()
        try:
            shutil.rmtree(os.path.join(FIXTURES_PATH, 'pouet'))
        except OSError:
            pass

    def test_transparent_if_catalog_is_default(self):
        fullpath = self.mgr.catalog_path()
        self.assertEqual(fullpath, app_settings.MBTILES_ROOT)

    def test_error_if_catalog_is_unknown(self):
        self.assertRaises(MBTilesNotFoundError, self.mgr.catalog_path, ('paf'))

    def test_default_catalog_is_root_if_files_present(self):
        default = self.mgr.default_catalog()
        self.assertEqual(default, None)

    def test_default_catalog_is_first_folder_if_no_files(self):
        # Move all files to other
        shutil.move(os.path.join(FIXTURES_PATH, 'france-35.mbtiles'),
                    '/tmp/france-35.mbtiles')
        shutil.move(os.path.join(FIXTURES_PATH, 'geography-class.mbtiles'),
                    '/tmp/geography-class.mbtiles')
        try:
            default = self.mgr.default_catalog()
            self.assertEqual(default, 'pouet')
        finally:
            # Move back
            shutil.move('/tmp/france-35.mbtiles',
                        os.path.join(FIXTURES_PATH, 'france-35.mbtiles'))
            shutil.move('/tmp/geography-class.mbtiles',
                        os.path.join(FIXTURES_PATH, 'geography-class.mbtiles'))

    def test_manager_should_fail_if_folder_does_not_exist(self):
        app_settings.MBTILES_ROOT = "/tmp/paf"
        self.assertRaises(MBTilesFolderError, MBTilesManager)

    def test_manager_should_fail_if_catalog_does_not_exist(self):
        self.assertRaises(MBTilesNotFoundError, self.mgr.filter, catalog='paf')

    def test_manager_should_restrict_list_to_catalog(self):
        self.mgr = MBTilesManager()
        listed = sorted([o.id for o in self.mgr.all()])
        self.failUnlessEqual(['france-35', 'geography-class'], listed)

        listed = sorted([o.id for o in self.mgr.filter(catalog='pouet').all()])
        self.failUnlessEqual(['country'], listed)

    def test_mbtiles_should_fail_if_mbtiles_does_not_exist(self):
        MBTiles('country', catalog='pouet')
        self.assertRaises(MBTilesNotFoundError,
                          MBTiles,
                          'country',
                          catalog='paf')