Last active
August 16, 2019 15:12
-
-
Save aodag/ed3ad48c2573e1aed475b960bb9cffce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ message }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pyramid | |
pyramid-jinja2 | |
waitress | |
pytest | |
webtest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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