def test_init(self): path = "/test/path" rep = app.init_repo(path) self.assertEqual(rep.connector.url.path, path) self.assertEqual(rep.index, index.PictureIndex()) self.assertEqual(rep.config, repo.new_repo_config())
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'
def test_save_index_to_disk(self): r = Repo(self.pi, self.conf, self.connector) r.save_index_to_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) self.assertIsNot(index_on_disk, self.pi)
def test_create_on_disk_empty(self): r = Repo.create_on_disk(self.connector, self.conf) # test repo self.assertIsInstance(r, Repo) self.assertIs(r.connector, self.connector) self.assertIs(r.config, self.conf) self.assertEqual(r.index, PictureIndex()) # 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, index.PictureIndex())
def create_on_disk(cls, connector, conf, pi=None): """Create repo and necessary dirs according to config. Return repo. connector -- connector to index's base dir (created if necessary) conf -- repository specific configuration pi -- picture index (optional) """ if not pi: pi = index.PictureIndex() if not connector.exists('.'): connector.mkdir('.') connector.mkdir(PIC_DIR) with connector.open(CONFIG_FILE, 'w') as config_fh: conf.write(config_fh) repo = Repo(pi, conf, connector) repo.save_index_to_disk() return repo
def _load_index_v1(self, fh): pi = index.PictureIndex() pi.read(fh) return pi