Пример #1
0
def cli_sage():
    parser = argparse.ArgumentParser(
        description='Launch the Sage server using a configuration file')
    parser.add_argument('config',
                        metavar='config',
                        help='Path to the configuration file')
    parser.add_argument('-p',
                        '--port',
                        metavar='P',
                        type=int,
                        help='The port to bind (default: 8000)',
                        default=8000)
    parser.add_argument('-w',
                        '--workers',
                        metavar='W',
                        type=int,
                        help='The number of server workers (default: 4)',
                        default=4)
    parser.add_argument('--log-level',
                        metavar='LEVEL',
                        dest='log_level',
                        help='The granularity of log outputs (default: info)',
                        default='info')
    args = parser.parse_args()
    # check if config file exists
    if not isfile(args.config):
        print("Error: Configuration file not found: '{}'".format(args.config))
        print("Error: Sage server could not start, aborting...")
    else:
        options = {
            'bind': '%s:%s' % ('0.0.0.0', args.port),
            'workers': args.workers,
            'log-level': args.log_level
        }
        StandaloneApplication(sage_app(args.config), options).run()
Пример #2
0
# lookup_test.py
# Author: Thomas MINIER - MIT License 2017-2018
from http_server.server import sage_app
from rdflib import Graph

app = sage_app('tests/data/test_config.yaml')
client = app.test_client()


def test_entity_lookup():
    ref_graph = Graph()
    ref_graph.parse("tests/entity/data/city0.ttl", format="ttl")
    # dereference entity City0
    url = "http://localhost:8000/entity/foo/City0"
    deref = client.get(url)
    # load downloaded N-triples into a graph and test if it is isomorphic to the reference graph
    desc_graph = Graph()
    desc_graph.parse(data=deref.data, format="nt")
    assert ref_graph.isomorphic(desc_graph)