• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from paste.session import SessionMiddleware
2from paste.fixture import TestApp
3import six
4
5info = []
6
7def wsgi_app(environ, start_response):
8    pi = environ.get('PATH_INFO', '')
9    if pi in ('/get1', '/get2'):
10        if pi == '/get1':
11            sess = environ['paste.session.factory']()
12        start_response('200 OK', [('content-type', 'text/plain')])
13        if pi == '/get2':
14            sess = environ['paste.session.factory']()
15        if 'info' in sess:
16            body = str(sess['info'])
17            if six.PY3:
18                body = body.encode('utf8')
19            return [body]
20        else:
21            return [b'no-info']
22    if pi in ('/put1', '/put2'):
23        if pi == '/put1':
24            sess = environ['paste.session.factory']()
25            sess['info']  = info[0]
26        start_response('200 OK', [('content-type', 'text/plain')])
27        if pi == '/put2':
28            sess = environ['paste.session.factory']()
29            sess['info']  = info[0]
30        return [b'foo']
31
32wsgi_app = SessionMiddleware(wsgi_app)
33
34def test_app1():
35    app = TestApp(wsgi_app)
36    res = app.get('/get1')
37    assert res.body == b'no-info'
38    res = app.get('/get2')
39    assert res.body ==b'no-info'
40    info[:] = ['test']
41    res = app.get('/put1')
42    res = app.get('/get1')
43    assert res.body == b'test'
44    res = app.get('/get2')
45    assert res.body == b'test'
46
47def test_app2():
48    app = TestApp(wsgi_app)
49    info[:] = ['fluff']
50    res = app.get('/put2')
51    res = app.get('/get1')
52    assert res.body == b'fluff'
53    res = app.get('/get2')
54    assert res.body == b'fluff'
55
56
57