Ejemplo n.º 1
0
def create_database(tree, path):
    '''Create a new, empty database at 'path' in 'tree'.

    A Database object for the new database is returned.
    '''
    if tree.does_path_exist(path):
        raise FileExistsError('Path already exists: ' + str(path))
    main = datafile.create_main_in_replacement_mode(tree, path)
    main.append_item(datafile.ItemSetting(b'checksum', b'sha256'))
    main.commit_and_close()
    datafile.create_content_in_replacement_mode(tree, path).commit_and_close()
    return Database(tree, path)
Ejemplo n.º 2
0
    def test_create_typical_main(self):
        tree = FakeTree()
        tree._add_directory(('path', 'to'))

        main = datafile.create_main_in_replacement_mode(
            tree, ('path', 'to', 'db'))
        main.append_item(datafile.ItemSetting(b'checksum', b'sha256'))
        self.assertCountEqual(
            (('path', 'to', 'db', 'main.new'), ('path', 'to', 'db')),
            tree._files_modified)
        main.commit_and_close()
        self.assertCountEqual(
            (('path', 'to', 'db'),
             ('path', 'to', 'db', 'main'),
             ('path', 'to', 'db', 'main.new')),
            tree._files_modified)
        self.assertNotIn(('path', 'to', 'db', 'main.new'), tree._files)
        self.assertEqual(
            testdata.dbfiledata('main-1'),
            tree._files[('path', 'to', 'db', 'main')].content)