def create_app(): app = flask.Flask(__name__) app.environment = os.environ.get("ENVIRONMENT", "dev") AppFactory.setup(app) return app
def create_app(): app = flask.Flask(__name__) app.environment = os.environ.get('ENVIRONMENT', 'dev') AppFactory.setup(app) return app
def test_add_test_data_and_get_data_from_db(self): '''CONFIG | Agrega datos de prueba''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.nombre_rol = u"Desarrollador" self.r1 = Rol(self.nombre_rol) #act AppFactory.add_test_data(db, [self.r1]) #assert assert Rol.query.filter_by(nombre=self.nombre_rol).first() is self.r1
def test_get_user_story_by_id(self): '''API | GET User Story por Id''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True AppFactory.add_test_data(db, [self.rol,self.us1]) #act with _app.test_client() as c: self.ruta = '/api/user_story/' + str(self.us1.id) self.resp = c.get(self.ruta) #asserts assert self.resp.status_code == 200 assert json.loads(self.resp.data)['id']==self.us1.id assert json.loads(self.resp.data)['quiero']==self.us1.quiero assert json.loads(self.resp.data)['para']==self.us1.para assert json.loads(self.resp.data)['rol_id']==self.rol.id
def setUpClassHelper(cls, domain): ''' Instantiate variables shared within a test case. Must be called with a Domain object in setUpClass ''' cls.app = AppFactory(domain=domain) cls.flask_client, cls.socket_client = cls.app.create_test_clients()
def setUp(self): self.app = AppFactory(microworld_domain, log_path='test_logs') self._setup_helper() self.agent = create_agent('agents.api_test_agent.APITestAgent', None, None, self.interfaces) self.app.rooms['0'].set_agent(self.agent)
def test_get_rol_by_id(self): '''API | GET Rol por Id''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.rol1 = Rol(u"Desarrollador") self.rol2 = Rol(u"Administrador") AppFactory.add_test_data(db, [self.rol1, self.rol2]) #act with _app.test_client() as c: self.ruta = '/api/rol/' + str(self.rol1.id) self.resp = c.get(self.ruta) #asserts assert self.resp.status_code == 200 assert json.loads(self.resp.data)['id']==self.rol1.id assert json.loads(self.resp.data)['nombre']==self.rol1.nombre
def test_get_desarrollador_by_id(self): '''API | GET Desarrollador por Id''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.des1 = Desarrollador(u"Juan") self.des2 = Desarrollador(u"Pedro") AppFactory.add_test_data(db, [self.des1, self.des2]) #act with _app.test_client() as c: self.ruta = '/api/desarrollador/' + str(self.des1.id) self.resp = c.get(self.ruta) #asserts assert self.resp.status_code == 200 assert json.loads(self.resp.data)['id']==self.des1.id assert json.loads(self.resp.data)['nombre']==self.des1.nombre
def test_delete_user_story(self): '''API | DELETE User Story''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True AppFactory.add_test_data(db, [self.rol, self.us1]) #act with _app.test_client() as c: self.ruta = '/api/user_story/' + str(self.us1.id) self.storiesBefore = len(json.loads(c.get('/api/user_story/').data)) self.resp = c.delete(self.ruta) self.storiesAfter = len(json.loads(c.get('/api/user_story/').data)) #asserts assert self.resp.status_code in [200, 204] assert self.storiesBefore == 1 assert self.storiesAfter == 0
def test_put_rol(self): '''API | PUT Rol''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.rol1 = Rol(u"Desarrollador") self.nuevo_nombre = u"Miembro del equipo" self.put_data = dict(nombre=self.nuevo_nombre) AppFactory.add_test_data(db, [self.rol1]) #act with _app.test_client() as c: self.ruta = '/api/rol/' + str(self.rol1.id) print(self.ruta, self.put_data) self.resp = c.put(self.ruta, data=self.put_data) self.modRol = Rol.query.get(1) assert self.resp.status_code in [200,204] assert self.modRol.nombre == self.nuevo_nombre
def test_delete_desarrollador(self): '''API | DELETE Desarrollador''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.des1 = Desarrollador(u"Juan") AppFactory.add_test_data(db, [self.des1]) #act with _app.test_client() as c: self.ruta = '/api/desarrollador/' + str(self.des1.id) self.desarrolladoresAntes = len(json.loads(c.get('/api/desarrollador/').data)) self.resp = c.delete(self.ruta) self.desarrolladoresDespues = len(json.loads(c.get('/api/desarrollador/').data)) #asserts assert self.resp.status_code in [200, 204] assert self.desarrolladoresAntes == 1 assert self.desarrolladoresDespues == 0
def test_delete_iteracion(self): '''API | DELETE Iteracion''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.ite1 = Iteracion(u"Iteracion",date(2016,1,1),date(2016,1,2)) AppFactory.add_test_data(db, [self.ite1]) #act with _app.test_client() as c: self.ruta = '/api/iteracion/' + str(self.ite1.id) self.iteracionesAntes = len(json.loads(c.get('/api/iteracion/').data)) self.resp = c.delete(self.ruta) self.iteracionesDespues = len(json.loads(c.get('/api/iteracion/').data)) #asserts assert self.resp.status_code in [200, 204] assert self.iteracionesAntes == 1 assert self.iteracionesDespues == 0
def test_create_app_ok(self): '''CONFIG | Crea y vincula las instancias de APP, API y ORM''' _app = AppFactory.create_app(_api, db, self.dbLocation) #assert assert _app is db.app assert _app is _api.app assert type(_app) == Flask self.assertEquals(_app.config['SQLALCHEMY_DATABASE_URI'], 'sqlite:///' + self.dbLocation)
def test_delete_rol(self): '''API | DELETE Rol''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.rol1 = Rol(u"Desarrollador") AppFactory.add_test_data(db, [self.rol1]) #act with _app.test_client() as c: self.ruta = '/api/rol/' + str(self.rol1.id) self.rolesBefore = len(json.loads(c.get('/api/rol/').data)) self.resp = c.delete(self.ruta) self.rolesAfter = len(json.loads(c.get('/api/rol/').data)) #asserts assert self.resp.status_code in [200, 204] assert self.rolesBefore == 1 assert self.rolesAfter == 0
def test_get_user_stories(self): '''API | GET User Stories''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True AppFactory.add_test_data(db, [self.rol, self.us1, self.us2]) #act with _app.test_client() as c: self.ruta = '/api/user_story/' self.resp = c.get(self.ruta) #asserts assert self.resp.status_code == 200 assert len(json.loads(self.resp.data))==2 assert json.loads(self.resp.data)[0]['id'] == self.us1.id assert json.loads(self.resp.data)[1]['id'] == self.us2.id assert json.loads(self.resp.data)[0]['quiero'] == self.us1.quiero assert json.loads(self.resp.data)[1]['quiero'] == self.us2.quiero assert json.loads(self.resp.data)[0]['rol_id'] == self.rol.id assert json.loads(self.resp.data)[1]['rol_id'] == self.rol.id
def test_get_iteracion_by_id(self): '''API | GET Iteracion por Id''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.nombre = u"Iteración 1" self.inicio = date(2016,1,1) self.fin = date(2016,1,14) self.ite1 = Iteracion(self.nombre, self.inicio, self.fin) AppFactory.add_test_data(db, [self.ite1]) #act with _app.test_client() as c: self.ruta = '/api/iteracion/1' self.resp = c.get(self.ruta) self.respData = json.loads(self.resp.data) #asserts assert self.resp.status_code == 200 assert self.respData["id"]==1 assert self.respData["nombre"]==self.ite1.nombre assert parse(self.respData["inicio"]).date()==self.ite1.inicio assert parse(self.respData["fin"]).date()==self.ite1.fin
def test_post_user_story(self): '''API | POST User Story''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True AppFactory.add_test_data(db, [self.rol]) self.data = dict(quiero=self.us1.quiero, para=self.us1.para, obs=self.us1.observaciones, rol_id=self.rol.id, estimacion=self.us1.estimacion, prioridad=self.us1.prioridad) #act with _app.test_client() as c: self.ruta = '/api/user_story/' self.resp = c.post(self.ruta, data=self.data) self.jsonResp = json.loads(self.resp.data) self.createdUS=UserStory.query.get(1) #asserts assert self.resp.status_code == 201 assert self.jsonResp['id'] == 1 assert self.createdUS.quiero == self.us1.quiero assert self.createdUS.para == self.us1.para assert self.createdUS.estimacion == self.us1.estimacion assert self.createdUS.prioridad == self.us1.prioridad
def test_add_static_server_and_get_static_files_ok(self): '''CONFIG | Configura ruta raíz y carpeta con contenido estático''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.imgDir = 'imgDir' self.imgRelPath = self.imgDir + '/img.png' os.mkdir(self.defaultDir + '/' + self.imgDir) os.mknod(self.defaultDir + '/' + self.imgRelPath) os.mknod(self.defaultDir + '/' + self.defaultFile) with open(self.defaultDir + '/' + self.defaultFile, 'a') as f: f.write('Hola Sqrum') #act AppFactory.add_static_server(_app, self.defaultDir, self.defaultFile) #assert with _app.test_client() as c: res = c.get('/') assert res.status_code == 200 assert 'Hola Sqrum' in res.data assert c.get(self.imgRelPath).status_code == 200
def test_delete_iteracion_asignado(self): '''API | DELETE Iteracion Con Stories''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.ite1 = Iteracion(u"Iteracion",date(2016,1,1),date(2016,1,2)) self.rol = Rol(u"UnRol") self.us1 = UserStory(self.rol, u'Agregar una User Story', para=u'Agregar funcionalidad al sistema', obs=u'Observaciones', prioridad=1, estimacion=2) self.us1.iteracion = self.ite1 AppFactory.add_test_data(db, [self.ite1, self.rol, self.us1]) #act with _app.test_client() as c: self.ruta = '/api/iteracion/' + str(self.ite1.id) self.iteracionesAntes = len(json.loads(c.get('/api/iteracion/').data)) self.resp = c.delete(self.ruta) self.iteracionesDespues = len(json.loads(c.get('/api/iteracion/').data)) self.us1 = UserStory.query.get(1) #asserts assert self.resp.status_code in [200, 204] assert self.iteracionesAntes == 1 assert self.iteracionesDespues == 0 assert self.us1.iteracion is None
def test_delete_desarrollador_asignado(self): '''API | DELETE Desarrollador Asignado''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.des1 = Desarrollador(u"Juan") self.rol = Rol(u"Desarrollador") self.us1 = UserStory(self.rol, u'Agregar una User Story', para=u'Agregar funcionalidad al sistema', obs=u'Observaciones', prioridad=1, estimacion=2) self.us1.desarrollador = self.des1 AppFactory.add_test_data(db, [self.des1, self.rol ,self.us1]) #act with _app.test_client() as c: self.ruta = '/api/desarrollador/' + str(self.des1.id) self.desarrolladoresAntes = len(json.loads(c.get('/api/desarrollador/').data)) self.resp = c.delete(self.ruta) self.desarrolladoresDespues = len(json.loads(c.get('/api/desarrollador/').data)) self.us1 = UserStory.query.get(1) #asserts assert self.resp.status_code in [200, 204] assert self.desarrolladoresAntes == 1 assert self.desarrolladoresDespues == 0 assert self.us1.desarrollador is None
def test_post_desarrollador(self): '''API | POST Desarrollador''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.nombre_des = u"Pablo" #act with _app.test_client() as c: self.ruta = '/api/desarrollador/' self.resp = c.post(self.ruta, data=dict(nombre=self.nombre_des) ) assert self.resp.status_code == 201 assert Desarrollador.query.filter_by(nombre=self.nombre_des) is not None
def test_post_rol(self): '''API | POST Rol''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.nombre_rol = u"Gerente" #act with _app.test_client() as c: self.ruta = '/api/rol/' self.resp = c.post(self.ruta, data=dict(nombre=self.nombre_rol) ) assert self.resp.status_code == 201 assert Rol.query.filter_by(nombre=self.nombre_rol) is not None
def test_get_iteraciones(self): '''API | GET Iteraciones''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.nombre1 = u"Iteración 1" self.nombre2 = u"Iteración 2" self.inicio1 = date(2016,1,1) self.fin1 = date(2016,1,14) self.inicio2 = date(2016,1,15) self.fin2 = date(2016,1,29) self.ite1 = Iteracion(self.nombre1, self.inicio1, self.fin1) self.ite2 = Iteracion(self.nombre2, self.inicio2, self.fin2) AppFactory.add_test_data(db, [self.ite1, self.ite2]) #act with _app.test_client() as c: self.ruta = '/api/iteracion/' self.resp = c.get(self.ruta) #asserts assert self.resp.status_code == 200 assert len(json.loads(self.resp.data))==2 assert json.loads(self.resp.data)[0]['id'] == self.ite1.id assert json.loads(self.resp.data)[1]['id'] == self.ite2.id
def test_put_iteracion(self): '''API | PUT Iteracion''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.nombre = u"Iteración 2" self.inicio = date(2016,1,1) self.fin = date(2016,1,14) self.modNombre = u"Iteración 3" self.modInicio = "2016-01-02" self.modFin = "2016-01-15" self.ite1 = Iteracion(self.nombre, self.inicio, self.fin) self.put_data = dict(nombre=self.modNombre, inicio=self.modInicio,fin=self.modFin) AppFactory.add_test_data(db, [self.ite1]) #act with _app.test_client() as c: self.ruta = '/api/iteracion/' + str(self.ite1.id) print(self.ruta, self.put_data) self.resp = c.put(self.ruta, data=self.put_data) self.modifiedIte = Iteracion.query.get(1) assert self.resp.status_code in [200,204] assert self.modifiedIte.nombre == self.modNombre assert self.modifiedIte.inicio == parse(self.modInicio).date() assert self.modifiedIte.fin == parse(self.modFin).date()
def test_put_user_story(self): '''API | PUT User Story''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True AppFactory.add_test_data(db, [self.rol, self.us1, self.des1, self.ite1]) self.modQuiero = "quiero modificado" self.modPara = "para modificado" self.modEstado = 2 self.modDesarrollador = self.des1.id self.modIteracion = self.ite1.id self.data = dict(quiero=self.modQuiero, para=self.modPara, estado=self.modEstado, desarrollador=self.modDesarrollador, iteracion=self.modIteracion) #act with _app.test_client() as c: self.ruta = '/api/user_story/1' self.resp = c.put(self.ruta, data=self.data) self.modifiedUS=UserStory.query.get(1) #asserts assert self.resp.status_code in [200, 204] assert self.modifiedUS.quiero == self.modQuiero assert self.modifiedUS.para == self.modPara assert self.modifiedUS.estado_id == self.modEstado assert self.modifiedUS.desarrollador.id == self.modDesarrollador assert self.modifiedUS.iteracion.id == self.modIteracion
def test_post_iteracion(self): '''API | POST Iteracion''' #arrange _app = AppFactory.create_app(_api, db, self.dbLocation) _app.testing = True self.nombre = u"Iteración 1" self.inicio = '2016-07-01' self.fin = '2016-07-10' self.data = dict(nombre=self.nombre,inicio=self.inicio,fin=self.fin) #act with _app.test_client() as c: self.ruta = '/api/iteracion/' self.resp = c.post(self.ruta, data=self.data) self.ite = Iteracion.query.get(1) assert self.resp.status_code == 201 assert self.ite.nombre == self.nombre assert self.ite.inicio == parse(self.inicio).date() assert self.ite.fin == parse(self.fin).date()
def run(config_file): from global_configuration import NitroConfiguration cfg = NitroConfiguration(config_file) cfg.logger.info("Driver starting..") from app_factory import AppFactory factory = AppFactory(cfg) try: factory.build() factory.start() cfg.logger.info("Driver exiting..") return 0 except Exception as e: print "driver: Exception -> ", e cfg.logger.exception(e) raise e finally: print "Exiting.." cfg.logger.info("Exiting..") import logging logging.shutdown()
def setUp(self): self.app = AppFactory(weather_domain) self._setup_helper()
return two_turn_examples def get_received(socket_client): '''return a list of messages received from the server from the agent''' result = [] for variable in socket_client.get_received(): if variable['name'] == '/message' and variable['args'][0][ 'sender'] == 'agent': result.append(variable['args'][0]['body']) return result if __name__ == '__main__': # Set up message passing and agent destination_app = AppFactory( [MapInterface(map_provider='google', api_key=keys['google_maps'])]) _flask_client, socket_client = destination_app.create_test_clients() agent = create_agent( 'agents.rule_based_agent.RuleBasedAgent', lambda lat, long: None, destination_app.interfaces, ) destination_app.set_agent(agent) # Consume startup messages socket_client.get_received() # Test agent by writing training data to it split = 'train' two_turn_examples = prepare_two_turn_dataset(split) out_fname = "two_turn_examples.%s.txt" % split
def setUp(self): self.app = AppFactory(destination_domain) self._setup_helper()
def setUp(self): self.app = AppFactory(microworld_domain) self._setup_helper()
# TODO(SF): Disable front-end UI components that use this api key, # (TTS, translation) os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = keys['google_speech'] # Initialize domain domain = load_domain(args.domain) # Set up logging if args.log_dir is None: args.log_dir = 'logs/{}'.format(args.domain) os.makedirs(args.log_dir, exist_ok=True) # Initialize app app = AppFactory(domain, agent_class_name=args.agent_class_name, agent_model_path=args.agent_model_path, user_class_name=args.user_class_name, user_model_path=args.user_model_path, log_path=args.log_dir, evaluation_file=args.evaluation_file, num_rooms=args.num_rooms, starting_evaluation_index=args.evaluation_start_index, user_stories=args.user_stories, generate_destinations=args.generate_destinations, save_logs=not args.dont_save, purge_logs_every_N=args.purge_logs_every_N) # Run app logging.basicConfig(filename='server_log.txt', level=logging.DEBUG) app.start(args.port, debug=args.debug)
from app_factory import AppFactory class CustomApi(Api): def __init__(self, app): super(Api, self).__init__(app=app) def handle_error(self, e): print(e.description) return jsonify({'message': e.description}), e.code # Gunicorn setup before init if __name__ != '__main__': app = AppFactory.create_app() gunicorn_logger = logging.getLogger('gunicorn.error') app.logger.handlers = gunicorn_logger.handlers app.logger.setLevel(gunicorn_logger.level) # Classic setup before init if __name__ == '__main__': app = AppFactory.create_app() app.run(host='0.0.0.0', port=6004)
# -*- coding: utf-8 -*- import os from common import _app, _api, db from app_factory import AppFactory import data if __name__ == '__main__': port = int(os.getenv('PORT', 8080)) host = os.getenv('IP', '0.0.0.0') _app = AppFactory.create_app(_api, db, "sqrum.db") AppFactory.add_static_server(_app,'front', 'index.html') AppFactory.add_test_data(db, data.roles) AppFactory.add_test_data(db, data.stories) AppFactory.add_test_data(db, data.desarrolladores) AppFactory.add_test_data(db, data.iteraciones) _app.run(port=port, host=host, debug=True)
def setUp(self): self.app = AppFactory(compare_numbers_domain) self._setup_helper()