Skip to content

Instantly share code, notes, and snippets.

@aodag
Last active August 16, 2019 15:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodag/ed3ad48c2573e1aed475b960bb9cffce to your computer and use it in GitHub Desktop.
Save aodag/ed3ad48c2573e1aed475b960bb9cffce to your computer and use it in GitHub Desktop.
from pyramid.config import Configurator
def hello(request):
return dict(message="Hello, world!")
def main(global_conf, **settings):
config = Configurator(settings=settings)
config.include("pyramid_jinja2")
config.add_jinja2_renderer(".html")
config.add_view(hello, renderer="./hello.html")
return config.make_wsgi_app()
if __name__ == '__main__':
import argparse
import waitress
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", type=int, default=8080)
parser.add_argument("--host", type=str, default="0.0.0.0")
args = parser.parse_args()
app = main({})
waitress.serve(app, port=args.port, host=args.host)
{{ message }}
pyramid
pyramid-jinja2
waitress
pytest
webtest
from pyramid import testing
def test_hello():
from app import hello
request = testing.DummyRequest()
result = hello(request)
assert result == {"message": "Hello, world!"}
def test_app():
import webtest
from app import main
settings = {}
app = webtest.TestApp(main({}, **settings))
res = app.get("/")
assert "Hello, world!" in res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment