def test_delete(): with db_connection.session() as session: session.query( subs_model.User).filter_by(name="foo").delete() session.query( auth_model.User).filter_by(name="bar").delete() session.commit()
def test_fetch(): with db_connection.session() as session: subs_user = session.query( subs_model.User).filter_by(name="foo").first() assert subs_user.email == "*****@*****.**" auth_user = session.query( auth_model.User).filter_by(name="bar").first() assert auth_user.email == "*****@*****.**"
def test_create(): with db_connection.session() as session: subs_user = subs_model.User( name="foo", email="*****@*****.**", password="******") session.add(subs_user) auth_user = auth_model.User( name="bar", email="*****@*****.**", password="******") session.add(auth_user) session.commit()
def make_app(): http_origins = options.CORS_URLS ws_origins = [url_to_ws_origins(u) for u in http_origins] handlers = [ (r"/api(.*)", RpcHandler, {'http_origins': http_origins, 'ws_url': options.WS_URL}), (r"/websocket", RpcWebsocket, {'ws_origins': ws_origins}), (r"/logout", LogoutHandler), (r"/api.html", ApiPageHandler), (r"/", IndexHandler), ] settings = { 'services': Service.describe(spddo.micro.func), 'micro_context': Context, 'cookie_name': 'micro-session', 'cookie_secret': '-it-was-a-dark-and-spddo-chat-night-', 'template_path': resource_filename('spddo.micro', "templates"), 'allow_exception_messages': options.DEBUG, 'gzip': True, 'debug': options.DEBUG } db_url = heroku_db_url(options.CLEARDB_DATABASE_URL) db_connection.db_init(db_url) if options.DEBUG: create_all(Base, db_connection._engine_) with db_connection.session() as session: try: session.add(model.Person(email="*****@*****.**", password="******")) session.commit() except IntegrityError: session.rollback() if options.PROC_POOL_SIZE: pool_init_processes(options.PROC_POOL_SIZE, options.DEBUG) if options.CLOUDAMQP_URL: queue = PikaTopic(options.CLOUDAMQP_URL, RpcWebsocket.async_broadcast, 'micro-chat') queue.connect() settings["broadcast_queue"] = queue logging.info("broadcast_queue %s", options.CLOUDAMQP_URL) spddo.micro.func.cache.init_mc() return tornado.web.Application(handlers, **settings)
def session(self): return db_connection.session()
pool_init(ProcessPoolExecutor(2)) application = tornado.web.Application([ (r"/websocket", RpcWebsocket), (r"/(.*)", RpcHandler) ], services=Service.describe(actions), micro_context=Context, cookie_name='blueshed-test', cookie_secret='-it-was-a-dark-and-blueshed-night-', allow_exception_messages=True) engine = db_connection.db_init("mysql+pymysql://root:root@localhost:8889/test") with db_connection.session() as session: drop_all(session) create_all(Base, engine) with db_connection.session() as session: session.add(model.User(name="admin", email="admin", password="******")) session.commit() @pytest.fixture def app(): return application @pytest.mark.gen_test def test_hello_world_get(http_client, base_url): response = yield http_client.fetch(base_url)