forked from morepath/morepath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_link.py
More file actions
200 lines (149 loc) · 5.29 KB
/
Copy pathtest_link.py
File metadata and controls
200 lines (149 loc) · 5.29 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import pytest
from morepath.app import App
from morepath.converter import Converter
@pytest.fixture
def info():
class MyApp(App):
pass
MyApp.commit()
app = MyApp()
r = app.config.path_registry
return app, r
def test_path_without_variables(info):
app, r = info
class Foo(object):
pass
r.register_inverse_path(model=Foo,
path='/',
factory_args=set())
info = app._get_path(Foo())
assert info.path == ''
assert info.parameters == {}
def test_path_with_variables(info):
app, r = info
class Foo(object):
def __init__(self, name):
self.name = name
r.register_path_variables(Foo,
lambda obj: {'name': obj.name})
r.register_inverse_path(model=Foo,
path='/foos/{name}',
factory_args=set(['name']))
info = app._get_path(Foo('a'))
assert info.path == 'foos/a'
assert info.parameters == {}
def test_path_with_default_variables(info):
app, r = info
class Foo(object):
def __init__(self, name):
self.name = name
r.register_inverse_path(model=Foo,
path='/foos/{name}',
factory_args=set(['name']))
info = app._get_path(Foo('a'))
assert info.path == 'foos/a'
assert info.parameters == {}
def test_path_with_parameters(info):
app, r = info
class Foo(object):
def __init__(self, name):
self.name = name
r.register_path_variables(Foo,
lambda obj: {'name': obj.name})
r.register_inverse_path(model=Foo,
path='/foos',
factory_args=set(['name']))
info = app._get_path(Foo('a'))
assert info.path == 'foos'
assert info.parameters == {'name': ['a']}
def test_class_path_without_variables(info):
app, r = info
class Foo(object):
pass
r.register_inverse_path(model=Foo,
path='/',
factory_args=set())
info = app._class_path(Foo, {})
assert info.path == ''
assert info.parameters == {}
def test_class_path_with_variables(info):
app, r = info
class Foo(object):
def __init__(self, name):
self.name = name
r.register_inverse_path(model=Foo,
path='/foos/{name}',
factory_args=set(['name']))
info = app._class_path(Foo, {'name': 'a'})
assert info.path == 'foos/a'
assert info.parameters == {}
def test_class_path_with_parameters(info):
app, r = info
class Foo(object):
def __init__(self, name):
self.name = name
r.register_inverse_path(model=Foo,
path='/foos',
factory_args=set(['name']))
info = app._class_path(Foo, {'name': 'a'})
assert info.path == 'foos'
assert info.parameters == {'name': ['a']}
def test_class_path_variables_with_converters(info):
app, r = info
class Foo(object):
def __init__(self, value):
self.value = value
r.register_inverse_path(model=Foo,
path='/foos/{value}',
factory_args=set(['value']),
converters={'value': Converter(int)})
info = app._class_path(Foo, {'value': 1})
assert info.path == 'foos/1'
assert info.parameters == {}
def test_class_path_parameters_with_converters(info):
app, r = info
class Foo(object):
def __init__(self, value):
self.value = value
r.register_inverse_path(model=Foo,
path='/foos',
factory_args=set(['value']),
converters={'value': Converter(int)})
info = app._class_path(Foo, {'value': 1})
assert info.path == 'foos'
assert info.parameters == {'value': ['1']}
def test_class_path_absorb(info):
app, r = info
class Foo(object):
pass
r.register_inverse_path(model=Foo,
path='/foos',
factory_args=set(),
absorb=True)
info = app._class_path(Foo, {'absorb': 'bar'})
assert info.path == 'foos/bar'
assert info.parameters == {}
def test_class_path_extra_parameters(info):
app, r = info
class Foo(object):
pass
r.register_inverse_path(model=Foo,
path='/foos',
factory_args=set())
info = app._class_path(Foo, {'extra_parameters': {'a': 'A',
'b': 'B'}})
assert info.path == 'foos'
assert info.parameters == {'a': ['A'], 'b': ['B']}
def test_class_path_extra_parameters_convert(info):
app, r = info
class Foo(object):
pass
r.register_inverse_path(model=Foo,
path='/foos',
factory_args=set(),
converters={'a': Converter(int)})
info = app._class_path(Foo,
{'extra_parameters': {'a': 1,
'b': 'B'}})
assert info.path == 'foos'
assert info.parameters == {'a': ['1'], 'b': ['B']}