Пример #1
0
 def setUp(self):
     self.connector = MockConnector(urlparse.urlparse('/baseurl/repo/'))
     self.connector.connect()
     self.pi = index.PictureIndex()
     self.pi.add(MockPicture.create_many(10))
     self.conf = repo.new_repo_config()
     self.conf['index.file'] = 'mock-index-path'
     Repo.create_on_disk(self.connector, self.conf, self.pi)
Пример #2
0
    def test_load_version_mismatch_error(self):
        self.conf['index.format_version'] = 99
        Repo.create_on_disk(self.connector, self.conf, self.pi)

        with self.assertRaises(VersionMismatchError) as cm:
            Repo.load_from_disk(self.connector)
        self.assertEqual(cm.exception.actual, 99)
        self.assertEqual(cm.exception.expected, repo.INDEX_FORMAT_VERSION)
Пример #3
0
 def setUp(self):
     self.connector = MockConnector(urlparse.urlparse('/baseurl/repo/'))
     self.connector.connect()
     self.pi = index.PictureIndex()
     self.pi.add(MockPicture.create_many(10))
     self.conf = repo.new_repo_config()
     self.conf['index.file'] = 'mock-index-path'
     Repo.create_on_disk(self.connector, self.conf, self.pi)
Пример #4
0
    def test_load_version_mismatch_error(self):
        self.conf['index.format_version'] = 99
        Repo.create_on_disk(self.connector, self.conf, self.pi)

        with self.assertRaises(VersionMismatchError) as cm:
            Repo.load_from_disk(self.connector)
        self.assertEqual(cm.exception.actual, 99)
        self.assertEqual(cm.exception.expected, repo.INDEX_FORMAT_VERSION)
Пример #5
0
    def test_load_from_disk(self):
        repo_created = Repo.create_on_disk(self.connector, self.conf, self.pi)
        repo_loaded = Repo.load_from_disk(self.connector)

        self.assertIsInstance(repo_loaded, Repo)
        self.assertEqual(repo_loaded.config, repo_created.config)
        self.assertIsNot(repo_loaded.config, repo_created.config)
        self.assertEqual(repo_loaded.index, repo_created.index)
        self.assertIsNot(repo_loaded.index, repo_created.index)
        self.assertIsNot(repo_loaded, repo_created)
        self.assertIs(repo_loaded.connector, self.connector)
Пример #6
0
    def test_load_from_disk(self):
        repo_created = Repo.create_on_disk(self.connector, self.conf, self.pi)
        repo_loaded = Repo.load_from_disk(self.connector)

        self.assertIsInstance(repo_loaded, Repo)
        self.assertEqual(repo_loaded.config, repo_created.config)
        self.assertIsNot(repo_loaded.config, repo_created.config)
        self.assertEqual(repo_loaded.index, repo_created.index)
        self.assertIsNot(repo_loaded.index, repo_created.index)
        self.assertIsNot(repo_loaded, repo_created)
        self.assertIs(repo_loaded.connector, self.connector)
Пример #7
0
    def test_clone(self):
        src_repo = Repo.create_on_disk(self.connector, self.conf, self.pi)
        dest_connector = MockConnector(urlparse.urlparse('/destrepo/baseurl/'))
        dest_connector.connect()
        dest_repo = Repo.clone(repo=src_repo, dest=dest_connector)

        self.assertIsInstance(dest_repo, Repo)
        self.assertEqual(dest_repo.config, src_repo.config)
        self.assertIsNot(dest_repo.config, src_repo.config)
        self.assertEqual(dest_repo.index, src_repo.index)
        self.assertIsNot(dest_repo.index, src_repo.index)
        self.assertIsNot(dest_repo, src_repo)
        self.assertTrue(dest_connector.opened(repo.CONFIG_FILE))
        self.assertTrue(dest_connector.opened('mock-index-path'))
Пример #8
0
    def test_clone(self):
        src_repo = Repo.create_on_disk(self.connector, self.conf, self.pi)
        dest_connector = MockConnector(urlparse.urlparse('/destrepo/baseurl/'))
        dest_connector.connect()
        dest_repo = Repo.clone(repo=src_repo, dest=dest_connector)

        self.assertIsInstance(dest_repo, Repo)
        self.assertEqual(dest_repo.config, src_repo.config)
        self.assertIsNot(dest_repo.config, src_repo.config)
        self.assertEqual(dest_repo.index, src_repo.index)
        self.assertIsNot(dest_repo.index, src_repo.index)
        self.assertIsNot(dest_repo, src_repo)
        self.assertTrue(dest_connector.opened(repo.CONFIG_FILE))
        self.assertTrue(dest_connector.opened('mock-index-path'))
Пример #9
0
    def test_create_on_disk_with_index(self):
        r = Repo.create_on_disk(self.connector, self.conf, self.pi)

        # test repo
        self.assertIsInstance(r, Repo)
        self.assertIs(r.connector, self.connector)
        self.assertIs(r.config, self.conf)
        self.assertEqual(r.index, self.pi)

        # test conf on disk
        self.assertTrue(self.connector.opened(repo.CONFIG_FILE))
        conf_on_disk = config.Config()
        conf_on_disk.read(self.connector.get_file(repo.CONFIG_FILE))
        self.assertEqual(conf_on_disk, self.conf)

        # test picture index on disk
        self.assertTrue(self.connector.opened('mock-index-path'))
        index_on_disk = index.PictureIndex()
        index_on_disk.read(self.connector.get_file('mock-index-path'))
        self.assertEqual(index_on_disk, self.pi)
Пример #10
0
    def test_create_on_disk_with_index(self):
        r = Repo.create_on_disk(self.connector, self.conf, self.pi)

        # test repo
        self.assertIsInstance(r, Repo)
        self.assertIs(r.connector, self.connector)
        self.assertIs(r.config, self.conf)
        self.assertEqual(r.index, self.pi)

        # test conf on disk
        self.assertTrue(self.connector.opened(repo.CONFIG_FILE))
        conf_on_disk = config.Config()
        conf_on_disk.read(self.connector.get_file(repo.CONFIG_FILE))
        self.assertEqual(conf_on_disk, self.conf)

        # test picture index on disk
        self.assertTrue(self.connector.opened('mock-index-path'))
        index_on_disk = index.PictureIndex()
        index_on_disk.read(self.connector.get_file('mock-index-path'))
        self.assertEqual(index_on_disk, self.pi)