1. Atsushi Odagiri
  2. pyconjp2011

Source

pyconjp2011 / basefw / pyconjp2011 / framework / tests.py

import unittest

class ApplicationTests(unittest.TestCase):
    def _getTarget(self):
        from .application import Application
        return Application

    def _makeOne(self):
        return self._getTarget()()

    def _dummyRequest(self, url='/', environ={}):
        from webob import Request
        request = Request.blank(url)
        request.environ.update(**environ)
        return request

    def test_it(self):
        app = self._makeOne()
        app.add_route("hoge", "/", DummyView('ok'))
        request = self._dummyRequest()
        res = request.get_response(app)
        self.assertEqual(res.body, 'ok')

class DummyView(object):
    def __init__(self, body):
        self.body = body
        self.called = []

    def __call__(self, request):
        self.called.append(request)
        from webob import Response
        return Response(self.body)