Exemple #1
0
def test_get_has_query_service_endpoints_via_given():
    entity_uri = 'http://example.com/resource/1'
    ttl = PREFIXES + '''
        <''' + entity_uri + '''> a dcat:Dataset, prov:Entity ;
            dct:description "has_provenance property only"^^xsd:string ;
            dct:title "Dataset 002"^^xsd:string ;
            prov:has_query_service <http://example.com/resource/1/pingback> ,
                <http://example.com/resource/1/pingback/2>
        .
        '''
    expected_results = [
        'http://example.com/resource/1/pingback',
        'http://example.com/resource/1/pingback/2'
    ]
    expected_results.sort()
    actual_results = strategy_functions.get_has_query_service_endpoints_via_given(
        strategy_functions.get_graph(ttl), entity_uri)
    actual_results.sort()

    ttl2 = PREFIXES + '''
        <''' + entity_uri + '''> a dcat:Dataset, prov:Entity ;
            dct:description "has_provenance property only"^^xsd:string ;
            dct:title "Dataset 002"^^xsd:string
        .
        '''
    expected_results2 = []
    actual_results2 = strategy_functions.get_has_query_service_endpoints_via_given(
        strategy_functions.get_graph(ttl2), entity_uri)  # cannot sort []

    return actual_results == expected_results and actual_results2 == expected_results2
Exemple #2
0
def test_get_has_provenance_service_endpoints_via_lookup():
    expected_results = [{
        'entity_uri':
        'http://promsns.org/eg/entity-server/id/dataset/003',
        'enpoints':
        ['http://promsns.org/eg/entity-server/api/provenance-service']
    }, {
        'entity_uri':
        'http://promsns.org/eg/entity-server/id/dataset/005',
        'enpoints':
        ['http://promsns.org/eg/entity-server/api/provenance-service']
    }, {
        'entity_uri':
        'http://promsns.org/eg/entity-server/id/dataset/007',
        'enpoints':
        ['http://promsns.org/eg/entity-server/api/provenance-service']
    }]

    actual_results = []
    for datum in DATA:
        r = strategy_functions.get_has_query_service_endpoints_via_lookup(
            strategy_functions.get_graph(PREFIXES + datum['rdf_metadata']),
            datum['entity_uri'])
        if len(r) > 0:
            r.sort()
            actual_results.append({
                'entity_uri': datum['entity_uri'],
                'enpoints': r
            })

    return actual_results == expected_results
Exemple #3
0
def test_get_pingback_endpoints_via_lookup():
    expected_results = [{
        'entity_uri': 'http://promsns.org/eg/entity-server/id/dataset/004',
        'enpoints': ['http://example.com/id/bundle/y']
    }, {
        'entity_uri':
        'http://promsns.org/eg/entity-server/id/dataset/005',
        'enpoints': [
            'http://promsns.org/eg/entity-server/api/pingback-service/dataset/005',
            'http://promsns.org/eg/entity-server/api/pingback-service2/dataset/005'
        ]
    }, {
        'entity_uri':
        'http://promsns.org/eg/entity-server/id/dataset/006',
        'enpoints': [
            'http://promsns.org/eg/entity-server/api/pingback-service/dataset/006'
        ]
    }]

    actual_results = []
    for datum in DATA:
        r = strategy_functions.get_pingback_endpoints_via_lookup(
            strategy_functions.get_graph(PREFIXES + datum['rdf_metadata']),
            datum['entity_uri'])
        if len(r) > 0:
            r.sort()
            actual_results.append({
                'entity_uri': datum['entity_uri'],
                'enpoints': r
            })

    return actual_results == expected_results
Exemple #4
0
def test_strategy_1(ttl_file_path):
    expected_results = [{
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/99',
        'pingback_endpoints': []
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/1',
        'pingback_endpoints': []
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/2',
        'pingback_endpoints': []
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/3',
        'pingback_endpoints': []
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/4',
        'pingback_endpoints': []
    }, {
        'entity_uri':
        'http://promsns.org/datastoredemo/id/dataset/5',
        'pingback_endpoints':
        ['http://proms-dev1-vc.it.csiro.au/function/pingback/']
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/6',
        'pingback_endpoints': []
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/7',
        'pingback_endpoints': []
    }, {
        'entity_uri':
        'http://promsns.org/datastoredemo/id/dataset/8',
        'pingback_endpoints': [
            'http://example.com/api/pingback',
            'http://example.com/function/pingback/'
        ]
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/9',
        'pingback_endpoints': []
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/10',
        'pingback_endpoints': []
    }, {
        'entity_uri': 'http://promsns.org/datastoredemo/id/dataset/11',
        'pingback_endpoints': []
    }]
    expected_results = sorted(expected_results, key=lambda k: k['entity_uri'])

    g = strategy_functions.get_graph(ttl_file_path)

    entity_uris = get_entities(g)
    actual_results = []
    for entity_uri in entity_uris:
        actual_results.append({
            'entity_uri':
            entity_uri,
            'pingback_endpoints':
            strategy_functions.get_pingback_endpoints_via_given(g, entity_uri)
        })

    if len(actual_results) != len(expected_results):
        return [
            False, 'incorrect number of entities, expected ' +
            str(len(expected_results)) + ', got ' + str(len(actual_results))
        ]

    actual_results = sorted(actual_results, key=lambda k: k['entity_uri'])

    i = 0
    passes = True
    reasons = []
    for entity in actual_results:
        entity['pingback_endpoints'].sort()
        expected_results[i]['pingback_endpoints'].sort()

        if entity['pingback_endpoints'] != expected_results[i][
                'pingback_endpoints']:
            passes = False
            reasons.append('incorrect result for ' + entity['entity_uri'])
        i += 1

    if passes:
        return [True]
    else:
        return [False, reasons]