Esempio n. 1
0
def config_db(request):
    filename = local_config.CONFIG_PATH
    with file(filename, 'a'):
        os.utime(filename, None)

    name = TESTDB
    url = 'https://localhost:2223'
    path = '/home/myself/cozyfiles'
    db_login = '******'
    db_password = '******'
    dbutils.create_db(name)
    dbutils.create_db_user(name, db_login, db_password)
    local_config.add_config(name, url, path, db_login, db_password)
    db = dbutils.get_db(name)
    dbutils.init_database_views(name)

    binary = {
       '_id': BINARY_ID,
        'docType': 'Binary',
    }
    db.save(binary)
    db.put_attachment(binary, open('./file_test.txt'), 'file')

    testfile = {
        '_id': FILE_ID,
        'docType': 'File',
        'path': '/tests',
        'name': 'file_test.txt',
        'binary': { 'file': { 'id': BINARY_ID } }
    }
    db.save(testfile)

    def fin():
        dbutils.remove_db(name)
    request.addfinalizer(fin)
Esempio n. 2
0
def test_rename(config_db):
    fs = couchmount.CouchFSDocument(TESTDB, local_config.MOUNT_FOLDER,
                                    'http://localhost:5984/%s' % TESTDB)
    db = dbutils.get_db(TESTDB)
    pathfrom = '/file_test.txt'
    pathto = '/A/test_doc.txt'
    fs.rename(pathfrom, pathto)

    assert dbutils.get_file(db, pathfrom) is None
    assert -errno.ENOENT == fs.open(pathfrom, 32769)
    assert -errno.ENOENT == fs.getattr(pathfrom)
    assert 'new_file.txt' not in fs._get_names('')

    (file_doc, binary_id, binary_path) = \
        fs.binary_cache.get_file_metadata(pathto)
    assert file_doc['path'] == '/A'
    assert file_doc['name'] == 'test_doc.txt'
    assert -errno.ENOENT != fs.open(pathto, 32769)
    assert -errno.ENOENT != fs.getattr(pathto)

    pathfrom = '/A'
    pathto = '/C'
    fs.rename(pathfrom, pathto)
    assert dbutils.get_file(db, '/A/test.sh') is None
    assert dbutils.get_folder(db, '/A/B') is None
    assert dbutils.get_file(db, '/C/test.sh') is not None
    assert dbutils.get_folder(db, '/C/B') is not None
Esempio n. 3
0
def get_device():
    device = {
        'url': 'https://test.cozycloud.cc',
        'folder': '/home/cozy',
        'name': TESTDB,
        'configuration': ["File", "Folder"],
    }
    db = dbutils.get_db(TESTDB)
    db.create(device)
Esempio n. 4
0
def test_rmdir(config_db):
    fs = couchmount.CouchFSDocument(TESTDB, local_config.MOUNT_FOLDER,
                                    'http://localhost:5984/%s' % TESTDB)
    db = dbutils.get_db(TESTDB)
    path = '/new_dir'
    fs.rmdir(path)
    assert dbutils.get_folder(db, path) is None
    assert -errno.ENOENT == fs.getattr('/new_dir')
    assert 'new_dir' not in fs._get_names('')
Esempio n. 5
0
def test_mkdir(config_db):
    fs = couchmount.CouchFSDocument(TESTDB, local_config.MOUNT_FOLDER,
                                    'http://localhost:5984/%s' % TESTDB)
    db = dbutils.get_db(TESTDB)
    path = '/new_dir'
    fs.mkdir(path, '')
    folder = dbutils.get_folder(db, path)
    assert folder["path"] == ''
    assert folder["name"] == 'new_dir'
Esempio n. 6
0
def test_release(config_db):
    fs = couchmount.CouchFSDocument(TESTDB, local_config.MOUNT_FOLDER,
                         'http://localhost:5984/%s' % TESTDB)
    path = '/new_file.txt'
    fs.release(path, None)

    db = dbutils.get_db(TESTDB)
    file_doc = dbutils.get_file(db, path)
    assert file_doc['size'] == len('test_write_again')
Esempio n. 7
0
def test_delete_file(config_db):
    db = dbutils.get_db(TESTDB)
    create_file(db, '', 'to_delete.txt')

    path = os.path.join(local_config.MOUNT_FOLDER, 'to_delete.txt')
    print os.path.exists(path)
    assert os.path.exists(path)
    os.remove(path)
    assert not os.path.exists(path)
Esempio n. 8
0
def test_mark_file_as_stored():
    db = dbutils.get_db(TESTDB)
    file_doc = db.get(FILE_ID)
    assert file_doc['storage'] == []
    binary_cache = binarycache.BinaryCache(
        TESTDB, DEVICE_CONFIG_PATH, COUCH_URL, MOUNT_FOLDER)
    binary_cache.mark_file_as_stored(file_doc)
    assert file_doc['storage'] == ['cozy-fuse-test']
    binary_cache.mark_file_as_not_stored(file_doc)
    assert file_doc['storage'] == []
Esempio n. 9
0
def test_unlink(config_db):
    fs = couchmount.CouchFSDocument(TESTDB, local_config.MOUNT_FOLDER,
                         'http://localhost:5984/%s' % TESTDB)
    path = '/new_file.txt'
    (file_doC, binary_id, filename) = fs.binary_cache.get_file_metadata(path)
    fs.unlink(path)
    db = dbutils.get_db(TESTDB)
    assert dbutils.get_file(db, path) is None
    assert -errno.ENOENT == fs.open(path, 32769)
    assert -errno.ENOENT == fs.getattr(path)
    assert 'new_file.txt' not in fs._get_names('')
    assert not os.path.exists(filename)
Esempio n. 10
0
def config_db(request):
    filename = local_config.CONFIG_PATH
    with file(filename, 'a'):
        os.utime(filename, None)

    name = TESTDB
    url = 'https://localhost:2223'
    path = '/home/myself/cozyfiles'
    db_login = '******'
    db_password = '******'
    dbutils.remove_db(name)
    dbutils.create_db(name)
    dbutils.create_db_user(name, db_login, db_password)
    local_config.add_config(name, url, path, db_login, db_password)
    db = dbutils.get_db(name)
    dbutils.init_database_views(name)

    device = {
        '_id': uuid4().hex,
        'docType': 'Device',
        'login': TESTDB,
        'url': 'http://',
        'password': TESTDB,
    }
    db.save(device)

    binary = {
       '_id': BINARY_ID,
        'docType': 'Binary',
    }
    db.save(binary)
    db.put_attachment(binary, open('./file_test.txt'), 'file')

    create_file(db, '', 'file_test.txt')
    create_file(db, '/A', 'test.sh')
    create_folder(db, '', 'A')

    couchmount.unmount(local_config.MOUNT_FOLDER)
    time.sleep(1)
    couchmount.mount(name, local_config.MOUNT_FOLDER)
    time.sleep(2)

    def fin():
        pass
        #couchmount.unmount(local_config.MOUNT_FOLDER)
        #time.sleep(10)
        #dbutils.remove_db(name)
    request.addfinalizer(fin)
Esempio n. 11
0
def test_get_db(config_db):
    db = dbutils.get_db(TESTDB)
    assert db is not None
Esempio n. 12
0
def test_remove_db():
    dbutils.remove_db(TESTDB)
    db = dbutils.get_db(TESTDB)
    assert db is None