Exemplo n.º 1
0
    def get(self, item_type: str, config_id: str):
        args = config_parser.parse_args()
        config_context_qs: str = args['oslc_config.context']
        config_context_header: str = args['Configuration-Context']

        config_context = ''

        if config_context_qs is not (None and ' ' and ''):
            config_context = config_context_qs
        elif config_context_header is not (None and ' ' and ''):
            config_context = config_context_header

        url_sp = url_for('api.oslc_service_provider', _external=True)
        oslc_resource = OSLCResource(current_app.config['SOURCE_BASE_URI'],
                                     current_user.access_token)
        resource = oslc_resource.get_query_resource(
            item_type,
            config_id,
            url=request.base_url,
            url_sp=url_sp,
            config_context=config_context)
        if resource:
            response = create_response(oslc_resource)
            return response
        else:
            return make_response(
                f'The Item {item_type} with the Config ID: {config_id} and Config Context: {config_context}'
                f' does not exist or an error occurred during the RDF translation',
                400)
Exemplo n.º 2
0
    def get(self, item_type: str):
        args = paging_parser.parse_args()
        paging: bool = args['oslc.paging']
        page_size: int = args['oslc.pageSize']
        page_no: int = args['oslc.pageNo']

        url_sp = url_for('api.oslc_service_provider', _external=True)
        logger.debug(f'{page_no}-{page_size}-{paging}')

        oslc_resource = OSLCResource(current_app.config['SOURCE_BASE_URI'],
                                     current_user.access_token)
        oslc_resource.get_query_capabilities(item_type=item_type,
                                             url=request.base_url,
                                             url_sp=url_sp,
                                             paging=paging,
                                             page_size=page_size,
                                             page_no=page_no)
        response = create_response(oslc_resource)

        if response.status_code != 204:
            return response
        else:
            return make_response(
                f'The Item Type {item_type} does not exist or an error occurred during the RDF translation',
                400)
Exemplo n.º 3
0
def test_get_query_resource(source_base_uri, access_token, item_values, mocker,
                            load_item_types_test, load_items_test,
                            load_validate_configs_test,
                            load_resource_shape_test,
                            load_query_expanded_item_test):
    item_type = item_values[0]
    config_id = item_values[1]
    url = f'http://127.0.0.1:5000/api/oslc/{item_type}/{config_id}'

    if 'localhost' in source_base_uri:
        mocker.patch('oslc_api.aras.resources.validate_config_id',
                     return_value=load_validate_configs_test)

        mocker.patch('oslc_api.rest_api.aras.load_resource_shape',
                     return_value=load_resource_shape_test)

        mocker.patch('oslc_api.rest_api.aras.get_resource_shape',
                     return_value=None)

        mocker.patch('oslc_api.rest_api.aras.query_expanded_item',
                     return_value=load_query_expanded_item_test)

        mocker.patch('oslc_api.rest_api.aras.check_if_versionable',
                     return_value=True)

        mocker.patch('oslc_api.rest_api.aras.query_relation_properties',
                     return_value=load_query_expanded_item_test)

    resource = OSLCResource(source_base_uri=source_base_uri,
                            access_token=access_token)
    r = resource.get_query_resource(item_type, config_id, url,
                                    'http://127.0.0.1:5000/api/oslc')

    assert r is not None, 'The request was not processed'
    assert len(r.graph) >= 1, 'The graph is empty'
Exemplo n.º 4
0
def test_get_query_capabilities(source_base_uri, access_token, item_values,
                                mocker, load_item_types_test, load_items_test):
    item_type = item_values[0]
    url = f'http://127.0.0.1:5000/api/oslc/{item_type}'
    url_sp = 'http://127.0.0.1:5000/api/oslc'
    # rs = f'<rdf:type rdf:resource="http://127.0.0.1:5000/api/oslc/{item_type}/resourceShape#"/>'

    if 'localhost' in source_base_uri:
        mocker.patch('oslc_api.aras.resources.load_item_types',
                     return_value=load_item_types_test)

        mocker.patch('oslc_api.aras.resources.load_items',
                     return_value=load_items_test)

    resource = OSLCResource(source_base_uri=source_base_uri,
                            access_token=access_token)
    qc = resource.get_query_capabilities(item_type, url, url_sp)

    assert qc is not None, 'The request was not processed'

    g = qc.graph.serialize()

    assert len(qc.graph) >= 1, 'The graph is empty'
    # assert rs.encode('ascii') in g, 'The resource shape was not generated'
    assert b'rdfs:member rdf:resource' in g, 'The members were not generated'
Exemplo n.º 5
0
def test_get_streams(source_base_uri, access_token, item_values, mocker,
                     load_validate_configs_test):
    item_type = item_values[0]
    config_id = item_values[1]
    stream_id = item_values[2]

    if 'localhost' in source_base_uri:
        mocker.patch('oslc_api.aras.resources.validate_config_id',
                     return_value=load_validate_configs_test)

        mocker.patch('oslc_api.aras.resources.load_streams',
                     return_value={
                         e['id']: e
                         for e in load_validate_configs_test['value']
                     })

    url = f'http://127.0.0.1:5000/api/oslc/{item_type}/{config_id}/stream/{stream_id}'

    resource = OSLCResource(source_base_uri=source_base_uri,
                            access_token=access_token)
    stream = resource.get_stream(item_type, config_id, stream_id, url)

    assert stream is not None, 'The request was not processed'

    g = stream.graph.serialize()

    assert item_type.encode(
        'ascii') in g, 'The response does not contain the item type'
    assert config_id.encode(
        'ascii') in g, 'The response does not contain the component'
    assert stream_id.encode(
        'ascii') in g, 'The response does not contain the stream'
Exemplo n.º 6
0
def test_get_configurations(source_base_uri, access_token, item_values, mocker,
                            load_validate_configs_test):

    item_type = item_values[0]
    config_id = item_values[1]
    url = f'http://127.0.0.1:5000/api/oslc/{item_type}/{config_id}/configurations'

    if 'localhost' in source_base_uri:
        mocker.patch('oslc_api.aras.resources.validate_config_id',
                     return_value=load_validate_configs_test)

        mocker.patch('oslc_api.aras.resources.load_streams',
                     return_value=load_validate_configs_test)

    resource = OSLCResource(source_base_uri=source_base_uri,
                            access_token=access_token)
    configs = resource.get_configurations(item_type, config_id, url)

    assert configs is not None, 'The request was not processed'

    g = configs.graph.serialize()

    assert item_type.encode(
        'ascii') in g, f'The {item_type} was not found in the response'
    assert config_id.encode(
        'ascii') in g, f'The {config_id} was not found in the response'
Exemplo n.º 7
0
def test_singleton_instance():
    ins1 = OSLCResource()
    ins2 = OSLCResource()

    logger.debug(f'instance 1: {ins1}')
    logger.debug(f'instance 2: {ins2}')

    assert ins1 == ins2, 'The singleton is creating different instances'
Exemplo n.º 8
0
    def get(self):
        oslc_resource = OSLCResource(current_app.config['SOURCE_BASE_URI'],
                                     current_user.access_token)
        oslc_resource.get_service_provider(request.base_url)

        if oslc_resource:
            response = create_response(oslc_resource)
            return response
        else:
            return make_response('Could not connect with the data source.',
                                 404)
Exemplo n.º 9
0
    def get(self, item_type: str, config_id: str):
        oslc_resource = OSLCResource(current_app.config['SOURCE_BASE_URI'],
                                     current_user.access_token)
        oslc_resource.get_component(item_type, config_id, request.base_url)

        response = create_response(oslc_resource)
        if response.status_code != 204:
            return response
        else:
            return make_response(
                f'The Item {item_type} with the ID: {config_id} does not exist or an error occurred during the RDF translation',
                400)
Exemplo n.º 10
0
    def get(self, item_type):
        url_sp = url_for('api.oslc_service_provider', _external=True)
        oslc_resource = OSLCResource(current_app.config['SOURCE_BASE_URI'],
                                     current_user.access_token)
        oslc_resource.get_resource_shape(item_type,
                                         request.base_url,
                                         url_sp=url_sp)

        if oslc_resource:
            response = create_response(oslc_resource)
            return response
        else:
            return make_response(
                f'The Item Type {item_type} does not exist or an error occurred during the RDF translation',
                400)
Exemplo n.º 11
0
def test_get_service_provider(source_base_uri, access_token, mocker,
                              load_item_types_test):

    if 'localhost' in source_base_uri:
        mocker.patch('oslc_api.aras.resources.load_item_types',
                     return_value=load_item_types_test)

    resource = OSLCResource(source_base_uri=source_base_uri,
                            access_token=access_token)
    sp = resource.get_service_provider('http://127.0.0.1:5000/')

    assert sp is not None, 'The request was not processed'

    g = sp.graph.serialize()

    assert b'ServiceProvider' in g, 'The Service Provider was not generated correctly'
    assert b'<rdf:type rdf:resource="http://open-services.net/ns/core#QueryCapability"/>' in g, 'The QC was not generated correctly'
    assert b'<rdf:type rdf:resource="http://open-services.net/ns/core#Service"/>' in g, 'The response does not contain a Service'
Exemplo n.º 12
0
    def get(self, item_type: str):
        args = paging_parser.parse_args()
        paging: bool = args['oslc.paging']
        page_size: int = args['oslc.pageSize']
        page_no: int = args['oslc.pageNo']

        oslc_resource = OSLCResource(current_app.config['SOURCE_BASE_URI'],
                                     current_user.access_token)
        oslc_resource.get_components(item_type=item_type,
                                     url=request.base_url,
                                     paging=paging,
                                     page_size=page_size,
                                     page_no=page_no)

        response = create_response(oslc_resource)
        if response.status_code != 204:
            return response
        else:
            return make_response(
                f'The Item Type {item_type} does not exist or an error occurred during the RDF translation',
                400)
Exemplo n.º 13
0
def test_get_components(source_base_uri, access_token, item_values, mocker,
                        load_item_types_test, load_items_test):
    item_type = item_values[0]
    url = f'http://127.0.0.1:5000/api/oslc/{item_type}'

    if 'localhost' in source_base_uri:
        mocker.patch('oslc_api.aras.resources.load_item_types',
                     return_value=load_item_types_test)

        mocker.patch('oslc_api.aras.resources.load_items',
                     return_value=load_items_test)

    resource = OSLCResource(source_base_uri, access_token)
    comps = resource.get_components(item_type, url)

    assert comps is not None, 'The request was not processed'

    g = comps.graph.serialize()

    assert item_type.encode(
        'ascii') in g, f'The {item_type} was not found in the response'