def get(self, url, headers): app = TestApp(wsgi.create_app(self.minion)) response = app.get( url, headers=[(k, ",".join(v)) for k , v in headers.canonicalized()], ) return response.body
def setUp(self): super(ApplicationTestMixin, self).setUp() self.config = {"db" : {"url" : "sqlite://"}} self.great = create_app(config=self.config) self.app = TestApp(wsgi.create_app(self.great)) METADATA.create_all(self.great.bin.provide("db"))
def get(self, url, headers): app = TestApp(wsgi.create_app(self.minion)) response = app.get( url, headers=[(k, b",".join(v)) for k, v in headers.canonicalized()], ) return response.body
def setUp(self): super(ApplicationTestMixin, self).setUp() self.config = {"db": {"url": "sqlite://"}} self.great = create_app(config=self.config) self.app = TestApp(wsgi.create_app(self.great)) METADATA.create_all(self.great.bin.provide("engine").connect())
def test_script_name(self): self.minion.route(b"/home")(lambda request : Response(b"Hi!")) app = TestApp( wsgi.create_app(self.minion), extra_environ={"SCRIPT_NAME" : "/app"}, ) response = app.get(b"/app/home") self.assertEqual(response.body, b"Hi!")
def test_script_name(self): self.minion.route(b"/home")(lambda request: Response(b"Hi!")) app = TestApp( wsgi.create_app(self.minion), extra_environ={"SCRIPT_NAME": "/app"}, ) response = app.get(b"/app/home") self.assertEqual(response.body, b"Hi!")
def setUp(self): self.minion = Application() self.wsgi = TestApp(wsgi.create_app(self.minion))
@app.bin.provides("db") @app.bin.needs(["config"]) def connect_db(config): """Connects to the specific database.""" rv = sqlite3.connect(config["database"]["uri"]) rv.row_factory = sqlite3.Row return rv def init_db(): """Creates the database tables.""" with closing(connect_db()) as db: db.cursor().execute("DROP TABLE IF EXISTS entries") db.cursor().execute( """ CREATE TABLE entries ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, text TEXT NOT NULL ) """ ) db.commit() wsgi = create_app(app) if __name__ == "__main__": init_db()
from minion.core import Application from minion.request import Response from minion.routing import Router, RoutesMapper from minion.wsgi import create_app app = Application(router=Router(mapper=RoutesMapper())) @app.route("/greet/{user}", greeting="Hey") def greet(request, greeting, user): return Response("{} {}\n".format(greeting, user).encode("utf-8")) wsgi = create_app(app)