def get_module_by_id(ctx, module_id): scoped_session = start_engine() session = scoped_session() facade = ModuleFacade(session) module = facade.get_module_by_id(module_id) session.close() return module
def get_all_modules(ctx): scoped_session = start_engine() session = scoped_session() facade = ModuleFacade(session) modules = facade.get_all() session.close() return modules
def create_module(ctx, module): module_id = -1 if module.id is None: scoped_session = start_engine() session = scoped_session() facade = ModuleFacade(session) facade.create_module(module=module) module_id = facade.get_module_by_name(name=module.name).id session.close() return module_id
def test_create(): scoped_session = start_engine() session = scoped_session() # create module module = Module(name="sample") facade = ModuleFacade(session) facade.create_module(module=module) # get created module query = session.query(Module).filter_by(id=module.id) module_query = query.all() assert len(module_query) == 1 assert module_query[0] is module session.close()
def test_delete(): scoped_session = start_engine() session = scoped_session() # get first module query = session.query(Module).filter_by(id=1) module_query = query.all() module = module_query[0] # delete facade = ModuleFacade(session) facade.delete_module(module) # get module again query = session.query(Module).filter_by(id=1) module_query = query.all() assert len(module_query) == 0 session.close()
def test_update(): scoped_session = start_engine() session = scoped_session() # get first module query = session.query(Module).filter_by(id=1) module_query = query.all() module = module_query[0] module.name = module.name + "_update" # update facade = ModuleFacade(session) facade.update_module(module) # get module again query = session.query(Module).filter_by(id=1) module_query = query.all() assert len(module_query) == 1 assert module_query[0] is module session.close()
def update_module(ctx, module): scoped_session = start_engine() session = scoped_session() facade = ModuleFacade(session) facade.update_module(module=module) session.close()