Contenu connexe
Plus de Atsushi Odagiri (20)
Pyramid
- 5. お約束のHello, World
from paste.httpserver import serve
from pyramid.configuration import Configurator
from pyramid.response import Response
def hello_world(context, request):
return Response('Hello world!')
if __name__ == '__main__':
config = Configurator()
config.begin()
config.add_view(hello_world)
config.end()
app = config.make_wsgi_app()
serve(app, host='0.0.0.0')
- 8. モデル定義
from persistent import Persistent
class Document(Persistent):
def __init__(self, title, contents):
self.title = title
self.contents = contents
- 13. テスト(2)
@nose.with_setup(setup, teardown)
def test_hello():
import newproject.views.add_document
req = DummyRequest()
req.params = {"name":"first-document",
"title":u"テスト", "contents":u"内容"}
info = add_document(context, req.params)
assert info.location == 'http://example.com/first-document/'
assert context['first-document'] is not None
doc = context['first-document']
assert doc.title == u'テスト'