blob: 879ad26d3547f9e432c8916d127b6405298dffb5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
from webtest import TestApp
try:
from simplejson import dumps
except:
from json import dumps # noqa
from six import b as b_
from pecan import Pecan, expose
from pecan.tests import PecanTestCase
class TestGeneric(PecanTestCase):
def test_simple_generic(self):
class RootController(object):
@expose(generic=True)
def index(self):
pass
@index.when(method='POST', template='json')
def do_post(self):
return dict(result='POST')
@index.when(method='GET')
def do_get(self):
return 'GET'
app = TestApp(Pecan(RootController()))
r = app.get('/')
assert r.status_int == 200
assert r.body == b_('GET')
r = app.post('/')
assert r.status_int == 200
assert r.body == b_(dumps(dict(result='POST')))
r = app.get('/do_get', status=404)
assert r.status_int == 404
|