import unittest from src.web import create_app from src.data_interface import Cache, model cache = Cache() app = create_app() with app.app_context(): model.init() class TestRedis(unittest.TestCase): def test_up(self): cache.redis_cache.ping() def test_set(self): cache.set("test:set", "foo") self.assertEqual(cache.get("test:set"), b"foo") def test_append(self): cache.append("test:list", "one") cache.append("test:list", "two") cache.get("test:list", start=0, end=-1) class TestPostgres(unittest.TestCase): def test_up(self): with app.app_context(): model.db.session.execute('SELECT 1')
def app(): app = create_app(app_config) return app
#!/usr/bin/env python import sys from flask_script import Manager, Server from sqlalchemy.engine.url import make_url from src.web import create_app from src.settings import app_config from src.data.prepopulate import prepopulate_database from src.data.db import DatabaseConnection app = create_app(app_config) server = Server(host='0.0.0.0', port=5000) manager = Manager(app) manager.add_command("runserver", server) @manager.command def prepopulate(): db_url = parse_sqlalchemy_url(app.config['SQLALCHEMY_DATABASE_URI']) _db = DatabaseConnection(db_url) with _db.transient_session(): prepopulate_database() def parse_sqlalchemy_url(input_url): try: url = make_url(input_url) _ = url.get_dialect()
raise ValueError( "Location of file containing spanish instructions for task should be specified in config with the key " "'instructions_span") # import pdb; pdb.set_trace() templates_dir = None if 'templates_dir' in params.keys(): templates_dir = os.path.join(root_path, params['templates_dir']) else: raise ValueError( "Location of HTML templates should be specified in config with the key templates_dir" ) if not os.path.exists(templates_dir): raise ValueError("Specified HTML template location doesn't exist: %s" % templates_dir) app = create_app(debug=True, templates_dir=templates_dir) schema_path = args.schema_path if not os.path.exists(schema_path): raise ValueError("No schema file found at %s" % schema_path) schema = Schema(schema_path, domain=args.domain) # todo in the future would we want individual models to have different lexicons? lexicon = Lexicon(schema, args.learned_lex, stop_words=args.stop_words) if args.inverse_lexicon: realizer = InverseLexicon(schema, args.inverse_lexicon) else: realizer = None scenario_db = ScenarioDB.from_dict(schema, read_json(args.scenarios_path)) app.config['scenario_db'] = scenario_db
#!/usr/bin/env python """ manage.py: run application related commands """ import os import sys sys.path.append(os.path.dirname("..")) from flask.ext.script import Manager from src.web import create_app app = create_app() manager = Manager(app) if "__main__" == __name__: manager.run()
instructions_file = open(params['instructions'], 'r') instructions = "".join(instructions_file.readlines()) instructions_file.close() else: raise ValueError("Location of file containing instructions for task should be specified in config with the key " "'instructions") templates_dir = None if 'templates_dir' in params.keys(): templates_dir = params['templates_dir'] else: raise ValueError("Location of HTML templates should be specified in config with the key templates_dir") if not os.path.exists(templates_dir): raise ValueError("Specified HTML template location doesn't exist: %s" % templates_dir) app = create_app(debug=False, templates_dir=templates_dir) schema_path = args.schema_path if not os.path.exists(schema_path): raise ValueError("No schema file found at %s" % schema_path) schema = Schema(schema_path, domain=args.domain) # todo in the future would we want individual models to have different lexicons? lexicon = Lexicon(schema, args.learned_lex, stop_words=args.stop_words) if args.inverse_lexicon: realizer = InverseLexicon(schema, args.inverse_lexicon) else: realizer = None scenario_db = ScenarioDB.from_dict(schema, read_json(args.scenarios_path)) app.config['scenario_db'] = scenario_db
#!/usr/bin/env python import sys from flask_script import Manager, Server from sqlalchemy.engine.url import make_url from src.web import create_app from src.settings import app_config from src.data.prepopulate import prepopulate_database from src.data.db import DatabaseConnection app = create_app(app_config) server = Server(host='0.0.0.0', port=5000) manager = Manager(app) manager.add_command("runserver", server) @manager.command def prepopulate(): db_url = parse_sqlalchemy_url(app.config['SQLALCHEMY_DATABASE_URI']) _db = DatabaseConnection(db_url) with _db.transient_session(): prepopulate_database() def parse_sqlalchemy_url(input_url): try: url = make_url(input_url) _ = url.get_dialect() return url except Exception as e: