Project

General

Profile

Download (1.22 KB) Statistics
| Branch: | Tag: | Revision:

root / entrouvert / wsgi / tests.py @ 9c67cb92

1
from entrouvert.wsgi.middleware import VersionMiddleware
2
from unittest import TestCase
3

    
4
class MiddlewareTestCase(TestCase):
5
    def setUp(self):
6
        VersionMiddleware.ENTROUVERT_PACKAGES.append('nose')
7

    
8
    def application(self, environ, start_response):
9
        start_response('coin', {'a':'b'})
10
        return ['xxx']
11

    
12
    def test_version_middleware(self):
13
        import json
14
        app = VersionMiddleware(self.application)
15
        class start_response_cls:
16
            status = None
17
            headers = None
18
            def __call__(self, status, headers):
19
                self.status = status
20
                self.headers = headers
21
        start_response = start_response_cls()
22
        result = app({ 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/__version__'}, start_response)
23
        result = json.loads(''.join(result))
24
        self.assertTrue(type(result) is dict)
25
        self.assertTrue('nose' in result)
26
        result = app({ 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/'}, start_response)
27
        self.assertEqual(result, ['xxx'])
28
        self.assertEqual(start_response.status, 'coin')
29
        self.assertEqual(start_response.headers, {'a': 'b'})
30

    
31
    def tearDown(self):
32
        VersionMiddleware.ENTROUVERT_PACKAGES.append('nose')
(3-3/3)