def test_db_model_filter(self, init_services): model_db = ModelDB() services = init_services # check that database is empty result = model_db.get_all(name='Model #0') assert list(result) == [] result = model_db.get_all(service_id=str(services[0])) assert list(result) == [] # create an item model_db.create( Model('Model #0', services[0], description='New sample FDD model', parameters=[Parameter('param1', 1)])) model_db.create( Model('Model #1', services[0], description='RENew sample FDD model', parameters=[Parameter('param1', 1), Parameter('param2', 2)])) models = list(model_db.get_all()) assert len(models) == 2 result = model_db.get_all(name="Model #1") assert len(list(result)) == 1 result = model_db.get_all(service_id=services[0]) assert len(list(result)) == 2 result = model_db.get_all(service_id=services[1]) assert len(list(result)) == 0
def init_models(): service_ids = init_services() params = [[Parameter('ar', 1), Parameter('I', 2), Parameter('MA', 0)], [Parameter('gamma', 0.543)]] models = [ Model('ARIMA#1', service_ids[0], description='A sample model #1', parameters=params[0]), Model('SVR #1', service_ids[0], description='A sample model #2', parameters=params[1])] model_ids = [ModelDB().create(model) for model in models] return model_ids, service_ids
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]
def test_db_model_update(self, init_services, init_models): model_ids = init_models model_db = ModelDB() # get all items result = model_db.get_all() models = list(result) assert len(models) == 2 for cur_model in models: assert cur_model.id in model_ids # get an item by its ID! # for a model, the ID to be used is the URL model = model_db.get_by_id(models[0].id) # update item data new_description = 'updated by patator' new_name = 'New Name' new_parameters = [Parameter('NewParam', 0)] model.description = new_description model.name = new_name model.parameters = new_parameters model_db.update(model.id, model) # check that item has really been updated in database updated_model = model_db.get_by_id(model.id) assert updated_model.id == model.id assert updated_model.name == new_name assert updated_model.description == new_description assert updated_model.service_id == model.service_id assert set(updated_model.event_output_ids) ==\ set(model.event_output_ids) assert set(updated_model.timeseries_output_ids) ==\ set(model.timeseries_output_ids) assert updated_model.get_set_of_parameters() ==\ model.get_set_of_parameters() == set([('NewParam', 0)]) # delete an item by its ID model_db.remove(model.id) # get an item by its ID with pytest.raises(ItemNotFoundError): # it has been removed... model_db.get_by_id(model.id)