forked from morepath/morepath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_method_directive.py
More file actions
96 lines (70 loc) · 2.06 KB
/
test_method_directive.py
File metadata and controls
96 lines (70 loc) · 2.06 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import morepath
from webtest import TestApp as Client
def test_implicit_function():
class app(morepath.App):
@morepath.dispatch_method()
def one(self):
return "Default one"
@morepath.dispatch_method()
def two(self):
return "Default two"
@app.path(path='')
class Model(object):
def __init__(self):
pass
@app.method(app.one)
def one_impl(self):
return self.two()
@app.method(app.two)
def two_impl(self):
return "The real two"
@app.view(model=Model)
def default(self, request):
return request.app.one()
c = Client(app())
response = c.get('/')
assert response.body == b'The real two'
def test_implicit_function_mounted():
class base(morepath.App):
@morepath.dispatch_method()
def one(self):
return "Default one"
@morepath.dispatch_method()
def two(self):
return "Default two"
class alpha(base):
pass
class beta(base):
def __init__(self, id):
self.id = id
@alpha.mount(path='mounted/{id}', app=beta)
def mount_beta(id):
return beta(id=id)
class AlphaRoot(object):
pass
class Root(object):
def __init__(self, id):
self.id = id
@alpha.path(path='/', model=AlphaRoot)
def get_alpha_root():
return AlphaRoot()
@beta.path(path='/', model=Root)
def get_root(app):
return Root(app.id)
@beta.method(base.one)
def one_impl(self):
return self.two()
@beta.method(base.two)
def two_impl(self):
return "The real two"
@alpha.view(model=AlphaRoot)
def alpha_default(self, request):
return request.app.one()
@beta.view(model=Root)
def default(self, request):
return "View for %s, message: %s" % (self.id, request.app.one())
c = Client(alpha())
response = c.get('/mounted/1')
assert response.body == b'View for 1, message: The real two'
response = c.get('/')
assert response.body == b'Default one'