Пример #1
0
def check_database(corpus_name, token=load_token(), port=8080):
    host = 'http://localhost:{}'.format(port)
    client = PGDBClient(host, token)
    try:
        client.start_database(corpus_name)
    except Exception as e:
        print("Database problem: {}".format(e))
Пример #2
0
def test_client_delete_corpus(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    client.start_database('test_database')
    assert 'test' in [x['name'] for x in client.list_corpora('test_database')]
    client.delete_corpus('test')
    assert 'test' not in [x['name'] for x in client.list_corpora('test_database')]

    client.stop_database('test_database')
Пример #3
0
def test_client_delete_corpus(localhost):
    client = PGDBClient(localhost)
    client.start_database('test_database')
    assert 'test' in client.list_corpora('test_database')
    client.delete_corpus('test')
    assert 'test' not in client.list_corpora('test_database')

    client.stop_database('test_database')
Пример #4
0
def test_client_database_status(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    statuses = client.database_status()
    print(statuses)
    for s in statuses:
        if s['name'] == 'test_database':
            assert s['status'] == 'Stopped'
    status = client.database_status('test_database')
    assert status['status'] == 'Stopped'
Пример #5
0
def test_query_basic(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    client.start_database('test_database')
    hierarchy = client.hierarchy('test')
    q = client.generate_query(hierarchy.phone)
    q.filter(hierarchy.phone.label == 'aa')
    q.columns(hierarchy.phone.label.column_name('phone_name'))
    results = client.run_query(q, blocking=True)
    assert len(results) > 0
    assert all(x['phone_name'] == 'aa' for x in results)

    client.stop_database('test_database')
Пример #6
0
def test_client_create_database(graph_db, localhost, auth_token):
    print(graph_db)
    client = PGDBClient(localhost, token=auth_token)
    try:
        client.delete_database('test_database')
    except ClientError:
        pass
    with pytest.raises(ClientError):
        client.delete_database('test_database')
    client.create_database('test_database')
    with pytest.raises(ClientError):
        response = client.create_database('test_database')

    ports = client.get_ports('test_database')
    assert 'graph_http_port' in ports
    assert 'graph_bolt_port' in ports
    assert 'acoustic_http_port' in ports
Пример #7
0
def test_client_delete_database(localhost):
    client = PGDBClient(localhost)
    assert 'test_database' in client.list_databases()
    client.delete_database('test_database')
    assert 'test_database' not in client.list_databases()
Пример #8
0
def test_client_import(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    with pytest.raises(ClientError):
        client.import_corpus('test', 'acoustic', 'M', 'test_database')

    client.start_database('test_database')
    client.import_corpus('test', 'acoustic', 'M', 'test_database', blocking=True)

    client.stop_database('test_database')
    assert client.corpus_status('test')['status'] == 'Imported'
    assert 'test' in [x['name'] for x in client.list_corpora('test_database')]
Пример #9
0
def test_client_source_directories(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    choices = client.get_source_choices()
    assert 'acoustic' in choices
Пример #10
0
import sys
import os
import argparse

base_dir = os.path.dirname(os.path.abspath(__file__))

from polyglotdb.client.client import PGDBClient

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('corpus_name', help='Name of the corpus')

    args = parser.parse_args()
    corpus_name = args.corpus_name
    directories = [x for x in os.listdir(base_dir) if os.path.isdir(x) and x != 'Common']

    if args.corpus_name not in directories:
        print(
            'The corpus {0} does not have a directory (available: {1}).  Please make it with a {0}.yaml file inside.'.format(
                args.corpus_name, ', '.join(directories)))
        sys.exit(1)
    print('Processing...')
    client = PGDBClient('http://localhost:8000')
    client.delete_database(corpus_name)
Пример #11
0
def test_client_corpus_list(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    corpora = client.list_corpora('test_database')
    assert corpora == []
Пример #12
0
def graph_db(localhost):
    from polyglotdb.client.client import PGDBClient, ClientError
    client = PGDBClient(localhost)

    dbs = client.list_databases()
    for d in dbs:
        if 'test' in d:
            client.delete_database(d)

    client.create_database('main_test_database')
    ports = client.get_ports('main_test_database')
    ports['data_dir'] = client.get_directory('main_test_database')
    ports['host'] = 'localhost'
    client.start_database('main_test_database')
    return ports
Пример #13
0
def graph_db(localhost, auth_token):
    from polyglotdb.client.client import PGDBClient, ClientError
    client = PGDBClient(localhost, token=auth_token)

    dbs = client.list_databases()
    print(dbs)
    for d in dbs:
        if d['name'] == 'main_test_database':
            client.delete_database(d['name'])

    client.create_database('main_test_database')
    ports = client.get_ports('main_test_database')
    ports['data_dir'] = client.get_directory('main_test_database')
    ports['host'] = 'localhost'
    client.start_database('main_test_database')
    return ports
Пример #14
0
sys.path.insert(0, script_dir)

import common

from polyglotdb.client.client import PGDBClient

token = common.load_token()

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('corpus_name', help='Name of the corpus')
    parser.add_argument('-d', '--docker', help="This script is being called from Docker", action='store_true')

    args = parser.parse_args()
    corpus_name = args.corpus_name
    docker = args.docker
    directories = [x for x in os.listdir(base_dir) if os.path.isdir(x) and x != 'Common']

    if args.corpus_name not in directories:
        print(
            'The corpus {0} does not have a directory (available: {1}).  Please make it with a {0}.yaml file inside.'.format(
                args.corpus_name, ', '.join(directories)))
        sys.exit(1)
    corpus_conf = common.load_config(corpus_name)
    ip = common.server_ip
    if docker:
        ip = common.docker_ip
    print('Processing...')
    client = PGDBClient('http://{}:{}'.format(ip, 8080), token=token)
    client.delete_database(corpus_name)
Пример #15
0
def test_client_database_list(localhost):
    client = PGDBClient(localhost)
    dbs = client.list_databases()
    assert 'test_database' in dbs
Пример #16
0
def test_client_import(localhost):
    client = PGDBClient(localhost)
    with pytest.raises(ClientError):
        client.import_corpus('test', 'acoustic', 'M', 'test_database')

    client.start_database('test_database')
    client.import_corpus('test',
                         'acoustic',
                         'M',
                         'test_database',
                         blocking=True)

    client.stop_database('test_database')
    assert client.corpus_status('test') == 'Imported'
    assert 'test' in client.list_corpora('test_database')
Пример #17
0
def test_client_corpus_list(localhost):
    client = PGDBClient(localhost)
    corpora = client.list_corpora('test_database')
    assert corpora == []
Пример #18
0
def test_client_database_status(localhost):
    client = PGDBClient(localhost)
    statuses = client.database_status()
    assert statuses['test_database'] == 'Stopped'
    status = client.database_status('test_database')
    assert status == 'Stopped'
Пример #19
0
def test_client_delete_database(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    assert 'test_database' in [x['name'] for x in client.list_databases()]
    client.delete_database('test_database')
    assert 'test_database' not in [x['name'] for x in client.list_databases()]
Пример #20
0
def test_client_database_list(localhost, auth_token):
    client = PGDBClient(localhost, token=auth_token)
    dbs = client.list_databases()
    assert 'test_database' in [ x['name'] for x in dbs]
Пример #21
0
base_dir = os.path.dirname(os.path.abspath(__file__))
script_dir = os.path.join(base_dir, 'Common')

sys.path.insert(0, script_dir)

import common

from polyglotdb.client.client import PGDBClient

token = common.load_token()

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('corpus_name', help='Name of the corpus')

    args = parser.parse_args()
    corpus_name = args.corpus_name
    directories = [
        x for x in os.listdir(base_dir) if os.path.isdir(x) and x != 'Common'
    ]

    if args.corpus_name not in directories:
        print(
            'The corpus {0} does not have a directory (available: {1}).  Please make it with a {0}.yaml file inside.'
            .format(args.corpus_name, ', '.join(directories)))
        sys.exit(1)
    corpus_conf = common.load_config(corpus_name)
    print('Processing...')
    client = PGDBClient('http://localhost:{}'.format(8080), token=token)
    client.delete_database(corpus_name)
Пример #22
0
def auth_token(localhost, test_user):
    from polyglotdb.client.client import PGDBClient, ClientError
    client = PGDBClient(localhost)
    token= client.login(*test_user)
    return token