Ejemplo n.º 1
0
    def test_db_service_create(self, init_sites):

        service_db = ServiceDB()

        # check that database is empty
        result = service_db.get_all()
        assert list(result) == []

        # create an item

        service = Service('Service#0',
                          url='http://hit2gap.eu/Service#0',
                          description='New sample service',
                          has_frontend=True,
                          site_ids=init_sites)
        new_service_id = service_db.create(service)
        assert new_service_id is not None
        assert new_service_id == service.id

        # check that database is not empty now
        result = service_db.get_all()
        services = list(result)
        assert len(services) == 1
        assert services[0].id == service.id
        assert services[0].name == service.name
        assert services[0].description == service.description
        assert services[0].url == service.url
        assert services[0].has_frontend
        assert set(services[0].site_ids) == set(init_sites)
Ejemplo n.º 2
0
    def test_db_service_get_empty(self):

        service_db = ServiceDB()

        # get all items
        result = service_db.get_all()
        assert list(result) == []

        # try to get an inexistant item
        with pytest.raises(ItemNotFoundError):
            service_db.get_by_id('not_existing')
Ejemplo n.º 3
0
    def test_db_model_create(self, init_services):

        model_db = ModelDB()

        # check that database is empty
        result = model_db.get_all()
        assert list(result) == []

        # create an item
        model = Model('ARIMA#0',
                      init_services[0],
                      description='A sample model',
                      parameters=[Parameter('ar', 5)])
        new_model_id = model_db.create(model)
        assert new_model_id is not None
        assert new_model_id == model.id

        # check that database is not empty now
        result = model_db.get_all()
        models = list(result)
        assert len(models) == 1
        assert models[0].id == model.id
        assert models[0].name == model.name
        assert models[0].service_id == model.service_id
        assert models[0].description == model.description
        assert models[0].get_set_of_parameters(
        ) == model.get_set_of_parameters()

        #test relation between service and model
        service = ServiceDB().get_by_id(model.service_id)
        assert service.model_ids == [model.id]
Ejemplo n.º 4
0
def init_services():
    services = [
        Service('ServiceFDD#{}'.format(idx+1),
                description='A fake fault and detection diagnosis service',
                url=_get_service_urls()[idx], id=id_)
        for idx, id_ in enumerate(_get_service_ids())]
    return [ServiceDB().create(service) for service in services]
Ejemplo n.º 5
0
    def test_db_service_update(self, init_services):

        service_ids = init_services
        service_db = ServiceDB()

        # get all items
        result = service_db.get_all()
        services = list(result)
        assert len(services) == 2
        for cur_service in services:
            assert cur_service.id in service_ids

        # get an item by its ID!
        # for a service, the ID to be used is the URL
        service = service_db.get_by_id(services[0].id)

        # update item data
        new_description = 'updated by patator'
        new_name = 'New Name'
        new_url = 'http://sibex.nobatek.inef4.fr/forecasting'

        service.description = new_description
        service.name = new_name
        service.url = new_url
        service_db.update(service.id, service)

        # check that item has really been updated in database
        updated_service = service_db.get_by_id(service.id)
        assert updated_service.id == service.id
        assert updated_service.name == new_name
        assert updated_service.description == new_description
        assert updated_service.url == new_url
        assert updated_service.kind == service.kind == 'Service'
        assert updated_service.model_ids == service.model_ids == []

        # delete an item by its ID
        service_db.remove(service.id)

        # get an item by its ID
        with pytest.raises(ItemNotFoundError):
            # it has been removed...
            service_db.get_by_id(service.id)
Ejemplo n.º 6
0
    def test_db_service_filter(self, init_sites):
        service_db = ServiceDB()

        # check that database is empty
        result = service_db.get_all(name='Service#0')
        assert list(result) == []
        result = service_db.get_all(
            url="http://hit2gap.eu/services/forecasting")
        assert list(result) == []

        # create an item
        service_db.create(
            Service('Service#0',
                    url='http://hit2gap.eu/services/fdd',
                    description='New sample FDD service',
                    site_ids=[str(init_sites[0])]))
        service_db.create(
            Service('Service#1',
                    url='http://hit2gap.eu/services/forecasting',
                    description='New sample forecasting service',
                    has_frontend=True))

        services = list(service_db.get_all())
        assert len(services) == 2
        result = service_db.get_all(name="Service#1")
        assert len(list(result)) == 1

        result = service_db.get_all(
            url="http://hit2gap.eu/services/forecasting")
        assert len(list(result)) == 1

        result = service_db.get_all(site=str(init_sites[0]))
        assert len(list(result)) == 1

        result = service_db.get_all(has_frontend=True)
        assert len(list(result)) == 1