Esempio n. 1
0
    def test_ontology_manager_exceptions(self):

        logger = logging.getLogger('bemserver')

        onto_mgr = ontology_manager_factory.get_ontology_manager()

        # Bad operator
        with pytest.raises(SPARQLError):
            onto_mgr.perform('dummy_op', 'dummy_query')

        # Query bad formed
        with mock.patch.object(logger, 'error') as mock_error:
            with pytest.raises(SPARQLError):
                onto_mgr.perform(SPARQLOP.SELECT, 'SELECT dummy_query')
            assert mock_error.called

        # Endpoint not found
        wrong_url = ontology_manager_factory.base_url[:-1] + 'dummy/'
        ontology_manager_factory.open(wrong_url)
        onto_mgr = ontology_manager_factory.get_ontology_manager()
        with mock.patch.object(logger, 'error') as mock_error:
            with pytest.raises(SPARQLError):
                onto_mgr.perform(SPARQLOP.SELECT,
                                 'SELECT * WHERE { ?s ?p ?o }')
            assert mock_error.called
Esempio n. 2
0
def init_handlers(url=None):
    if url:
        ontology_manager_factory.open(url)
    return {
        Site: SiteDB(),
        Building: BuildingDB(),
        Floor: FloorDB(),
        Space: SpaceDB(),
        Zone: ZoneDB(),
        Facade: FacadeDB(),
        Slab: SlabDB(),
        Window: WindowDB(),
        Sensor: SensorDB(),
        Measure: MeasureDB(),
        Service: ServiceDB(),
        Model: ModelDB(),
        Output: OutputDB(),
        OutputEvent: OutputDB(),
        OutputTimeSeries: OutputDB(),
    }
Esempio n. 3
0
def init_onto_mgr_fact():
    onto_db_url = init_onto_db(use_file=True)
    ontology_manager_factory.open(onto_db_url)
    yield
    ontology_manager_factory.close()