def generate_response(status, content=None):
    if content:
        content = json.dumps(content)
        length = len(content)
    else:
        length = 0
    response = 'HTTP/1.1 {}\r\nContent-Length: {}\r\n\r\n{}'
    return get_bytes(response.format(status, length, content))
def test_document_get_blobs(server):
    """ Fetch all blobs of a given document. """

    number = 4
    with Doc(server, blobs=number) as doc:
        for idx in range(number):
            xpath = 'files:files/{}/file'.format(idx)
            blob = doc.fetch_blob(xpath)
            assert blob == get_bytes('foo {}'.format(idx))
def test_document_get_blobs(server):
    """ Fetch all blobs of a given document. """

    number = 4
    with Doc(server, blobs=number) as doc:
        for idx in range(number):
            xpath = 'files:files/{}/file'.format(idx)
            blob = doc.fetch_blob(xpath)
            assert blob == get_bytes('foo {}'.format(idx))
def find_duplicates_with_name(name):
    operation = nuxeo.operations.new('Document.FetchByProperty')
    operation.params = {'property': 'dc:title', 'values': name}
    docs = operation.execute()
    doc_paths = defaultdict(list)
    for doc in docs['entries']:
        doc_paths[doc['path'].rsplit('/', 1)[0]].append(compute_uid_line(doc))

    no_duplicates = True
    for (path, uids) in doc_paths.items():
        if len(uids) > 1:
            no_duplicates = False
            print_duplicates('/'.join([path, name]), uids)
    if no_duplicates:
        color_print('No duplicate for {}.'.format(get_bytes(name)), BColors.OKGREEN)
def find_duplicates_with_name(name):
    operation = nuxeo.operations.new('Document.FetchByProperty')
    operation.params = {'property': 'dc:title', 'values': name}
    docs = operation.execute()
    doc_paths = defaultdict(list)
    for doc in docs['entries']:
        doc_paths[doc['path'].rsplit('/', 1)[0]].append(compute_uid_line(doc))

    no_duplicates = True
    for (path, uids) in doc_paths.items():
        if len(uids) > 1:
            no_duplicates = False
            print_duplicates('/'.join([path, name]), uids)
    if no_duplicates:
        color_print('No duplicate for {}.'.format(get_bytes(name)),
                    BColors.OKGREEN)
def find_duplicates_of_uid(uid):
    if not re.match(r'^[a-fA-F\d]{8}-[a-fA-F\d]{4}-[a-fA-F\d]{4}-[a-fA-F\d]{4}-[a-fA-F\d]{12}$', uid):
        color_print('Not a valid uid.', BColors.FAIL)
    else:
        try:
            doc = nuxeo.documents.get(uid=uid)
            query = "SELECT * FROM Document WHERE ecm:parentId = '" + doc.parentRef + "'"
            query += " AND dc:title = '" + doc.title + "'"
            request = 'query?query=' + quote(get_bytes(query), safe='!=:')
            entries = nuxeo.client.request('GET', request).get('entries')
            if len(entries) > 1:
                print_duplicates('/'.join([doc.path.rsplit('/', 1)[0], doc.title]),
                                 [compute_uid_line(x) for x in entries])
            else:
                color_print('No duplicate for the document with uid={}.'.format(uid), BColors.OKGREEN)
        except HTTPError as e:
            if e.response.status_code == 404:
                color_print('No document with uid={}.'.format(uid), BColors.FAIL)
示例#7
0
def test_unauthorized(server):
    username = '******'
    password = '******'
    user = server.users.create(
        User(properties={
            'username': username,
            'password': password
        }))

    auth = server.client.auth
    server.client.auth = (get_bytes(username), password)
    try:
        with pytest.raises(Unauthorized) as e:
            server.users.create(
                User(properties={
                    'username': '******',
                    'password': '******'
                }))
        assert text(e.value)
    finally:
        server.client.auth = auth
        user.delete()
def find_duplicates_of_uid(uid):
    if not re.match(
            r'^[a-fA-F\d]{8}-[a-fA-F\d]{4}-[a-fA-F\d]{4}-[a-fA-F\d]{4}-[a-fA-F\d]{12}$',
            uid):
        color_print('Not a valid uid.', BColors.FAIL)
    else:
        try:
            doc = nuxeo.documents.get(uid=uid)
            query = "SELECT * FROM Document WHERE ecm:parentId = '" + doc.parentRef + "'"
            query += " AND dc:title = '" + doc.title + "'"
            request = 'query?query=' + quote(get_bytes(query), safe='!=:')
            entries = nuxeo.client.request('GET', request).get('entries')
            if len(entries) > 1:
                print_duplicates(
                    '/'.join([doc.path.rsplit('/', 1)[0], doc.title]),
                    [compute_uid_line(x) for x in entries])
            else:
                color_print(
                    'No duplicate for the document with uid={}.'.format(uid),
                    BColors.OKGREEN)
        except HTTPError as e:
            if e.response.status_code == 404:
                color_print('No document with uid={}.'.format(uid),
                            BColors.FAIL)
示例#9
0
def test_fetch_rendition(server):
    with Doc(server, with_blob=True) as doc:
        res = doc.fetch_rendition('xmlExport')
        assert b'<?xml version="1.0" encoding="UTF-8"?>' in res
        path = '<path>' + pytest.ws_python_tests_path[1:] + '</path>'
        assert get_bytes(path) in res