Пример #1
0
def test_all():
    g = Graph().parse(source=os.path.join(settings.HOME_DIR, 'modules',
                                          'pingbacks', 'tests',
                                          'test_proms_report_internal.ttl'),
                      format='turtle')

    e = Engine(g, 'http://example.com/report',
               'http://localhost:9000/instance',
               'http://fake-sparql-endpoint.com')
Пример #2
0
def test_entity_selection():
    g = Graph().parse(source=os.path.join(settings.HOME_DIR, 'modules',
                                          'pingbacks', 'tests',
                                          'test_proms_report_internal.ttl'),
                      format='turtle')

    e = Engine(g, 'http://example.com/report',
               'http://fake-instance-endpoint.com',
               'http://fake-sparql-endpoint.com')

    expected_results = [
        'http://example.com/default#e_a', 'http://example.com/default#e_b',
        'http://example.com/default#e_c', 'http://example.com/default#e_d',
        'http://example.com/default#e_h', 'http://example.com/default#e_k',
        'http://example.com/default#e_l', 'http://example.com/default#e_p',
        'http://example.com/default#e_s'
    ]

    actual_results = e.get_candidates()

    assert set(expected_results) == set(actual_results)
Пример #3
0
def lodge_report():
    """Insert a Report into the provenance database

    This function should be edited if any custom actions are to be undertaken by PROMS on reciept of a Report, such as
    Ppingbacks
    """
    # only accept RDF documents
    acceptable_mimes = LDAPI.get_rdf_mimetypes_list()
    ct = request.content_type
    if ct not in acceptable_mimes:
        return api_functions.client_error_response(
            'The Report posted is not encoded with a valid RDF Content-Type. Must be one of: '
            + ', '.join(acceptable_mimes) + '.')

    # validate Report, using the controller validator class, IncomingReport
    r = class_reports.IncomingReport(request)
    if not r.valid():
        return api_functions.client_error_response(
            'The Report posted is not valid for the following reasons: ' +
            ', '.join(r.error_messages) + '.')

    # generate Named Graph metadata
    r.determine_uri()
    r.generate_named_graph_metadata()

    # store the Report
    # since it is valid and NG metadata has been built, we can store it
    if not r.stored():
        return api_functions.server_error_response(
            'Report posted is valid but cannot be stored for the following reasons: '
            + ', '.join(r.error_messages) + '.')

    # Custom Actions
    # Only try to any custom actions, e.g. Pingbacks, if the module is turned on
    if conf.MODULES.get('pingbacks').get('valid'):
        # kick off any Pingbacks for this Report, as per chosen Pingbacks strategies
        # TODO: split Pingbacks process off into another thread
        from modules.pingbacks.engine import Engine
        e = Engine(r.graph, r.uri, url_for('modelx.instance'),
                   url_for('.sparql'))

    # reply to sender
    return r.uri, 201
Пример #4
0
def lodge_report():
    """Insert a Report into the provenance database"""
    # only accept RDF documents
    acceptable_mimes = LDAPI.get_rdf_mimetypes_list()
    ct = request.content_type
    if ct not in acceptable_mimes:
        return api_functions.client_error_response(
            'The Report posted is not encoded with a valid RDF Content-Type. Must be one of: '
            + ', '.join(acceptable_mimes) + '.')

    # validate Report
    r = class_reports.IncomingReport(request)
    print(str(r))
    if not r.valid():
        return api_functions.client_error_response(
            'The Report posted is not valid for the following reasons: ' +
            ', '.join(r.error_messages) + '.')

    # get the Report's URI
    r.determine_uri()

    r.generate_named_graph_metadata()

    # store the Report
    if not r.stored():
        return api_functions.server_error_response(
            'Report posted is valid but cannot be stored for the following reasons: '
            + ', '.join(r.error_messages) + '.')

    # kick off any Pingbacks for this Report, as per chosen Pingbacks strategies
    # TODO: split this off into another thread
    from modules.pingbacks.engine import Engine
    e = Engine(r.graph, r.uri, url_for('modelx.instance'), url_for('.sparql'))

    # reply to sender
    return r.uri, 201
Пример #5
0
def test_get_strategies_enabled():
    e = Engine(Graph(), 'nothing')
    strategies = e.get_strategies_enabled()

    assert len(strategies) == 1  # by default, none only enabled strategy