Esempio n. 1
0
    def testAlternativeMethod(self):
        handler = BasicHttpHandler(notFoundMethod=lambda path, **kwargs: 'HTTP/1.0 404\r\n\r\n%s' % path)
        observer = CallTrace('HttpComponent', emptyGeneratorMethods=['handleRequest'])
        observable = Observable()
        observable.addObserver(handler)
        handler.addObserver(observer)

        response = ''.join(compose(observable.all.handleRequest(RequestURI="/", path='/')))

        self.assertEquals('HTTP/1.0 404\r\n\r\n/', response)
        self.assertEquals(['handleRequest'], observer.calledMethodNames())
Esempio n. 2
0
    def test404(self):
        handler = BasicHttpHandler()
        observer = CallTrace('HttpComponent', emptyGeneratorMethods=['handleRequest'])
        observable = Observable()
        observable.addObserver(handler)
        handler.addObserver(observer)

        response = ''.join(compose(observable.all.handleRequest(RequestURI="/")))

        self.assertEquals('HTTP/1.0 404 Not Found\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<html><body>404 Not Found</body></html>', response)
        self.assertEquals(['handleRequest'], observer.calledMethodNames())
Esempio n. 3
0
    def testOk(self):
        handler = BasicHttpHandler()
        observer = CallTrace('HttpComponent')
        observer.returnValues['handleRequest'] = (f for f in ['HTTP/1.0 200 OK\r\n\r\n', 'Body'])
        observable = Observable()
        observable.addObserver(handler)
        handler.addObserver(observer)

        response = ''.join(compose(observable.all.handleRequest(RequestURI="/")))

        self.assertEquals('HTTP/1.0 200 OK\r\n\r\nBody', response)
        self.assertEquals(['handleRequest'], observer.calledMethodNames())
    def testAlternativeMethod(self):
        handler = BasicHttpHandler(notFoundMethod=lambda path, **kwargs:
                                   'HTTP/1.0 404\r\n\r\n%s' % path)
        observer = CallTrace('HttpComponent',
                             emptyGeneratorMethods=['handleRequest'])
        observable = Observable()
        observable.addObserver(handler)
        handler.addObserver(observer)

        response = ''.join(
            compose(observable.all.handleRequest(RequestURI="/", path='/')))

        self.assertEquals('HTTP/1.0 404\r\n\r\n/', response)
        self.assertEquals(['handleRequest'], observer.calledMethodNames())
    def testOk(self):
        handler = BasicHttpHandler()
        observer = CallTrace('HttpComponent')
        observer.returnValues['handleRequest'] = (
            f for f in ['HTTP/1.0 200 OK\r\n\r\n', 'Body'])
        observable = Observable()
        observable.addObserver(handler)
        handler.addObserver(observer)

        response = ''.join(
            compose(observable.all.handleRequest(RequestURI="/")))

        self.assertEquals('HTTP/1.0 200 OK\r\n\r\nBody', response)
        self.assertEquals(['handleRequest'], observer.calledMethodNames())
    def test404(self):
        handler = BasicHttpHandler()
        observer = CallTrace('HttpComponent',
                             emptyGeneratorMethods=['handleRequest'])
        observable = Observable()
        observable.addObserver(handler)
        handler.addObserver(observer)

        response = ''.join(
            compose(observable.all.handleRequest(RequestURI="/")))

        self.assertEquals(
            'HTTP/1.0 404 Not Found\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<html><body>404 Not Found</body></html>',
            response)
        self.assertEquals(['handleRequest'], observer.calledMethodNames())