1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
1 |
from nose.tools import assert_equal, raises |
2 |
||
1294.3.2
by William Grant
Router->Publisher |
3 |
from ivle.webapp.publisher import (INF, InsufficientPathSegments, NoPath, |
4 |
NotFound, RouteConflict, Publisher, ROOT) |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
5 |
|
6 |
class Root(object): |
|
7 |
def __init__(self): |
|
8 |
self.subjects = {} |
|
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
9 |
self.users = {} |
1294.2.1
by William Grant
Add an object-traversal-based router. |
10 |
|
11 |
def add_subject(self, subject): |
|
12 |
self.subjects[subject.name] = subject |
|
13 |
||
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
14 |
def add_user(self, user): |
15 |
self.users[user.login] = user |
|
16 |
||
17 |
class User(object): |
|
18 |
def __init__(self, login): |
|
19 |
self.login = login |
|
20 |
||
1294.2.1
by William Grant
Add an object-traversal-based router. |
21 |
class Subject(object): |
22 |
def __init__(self, name, code): |
|
23 |
self.name = name |
|
24 |
self.code = code |
|
25 |
self.offerings = {} |
|
26 |
||
27 |
def add_offering(self, offering): |
|
28 |
assert self.name == offering.subject.name |
|
29 |
self.offerings[(offering.year, offering.semester)] = offering |
|
30 |
||
31 |
class Offering(object): |
|
32 |
def __init__(self, subject, year, semester): |
|
33 |
self.subject = subject |
|
34 |
self.year = year |
|
35 |
self.semester = semester |
|
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
36 |
self.projects = {} |
37 |
||
38 |
def add_project(self, project): |
|
39 |
assert project.offering is self |
|
40 |
self.projects[project.name] = project |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
41 |
|
1294.2.36
by William Grant
Replace the tests' OfferingProjects with OfferingFiles. |
42 |
class OfferingFiles(object): |
1294.2.22
by William Grant
Test named routes. |
43 |
def __init__(self, offering): |
44 |
self.offering = offering |
|
45 |
||
1294.2.37
by William Grant
Test a route with infinitely many arguments. |
46 |
class OfferingFile(object): |
47 |
def __init__(self, offeringfiles, path): |
|
48 |
self.offering = offeringfiles.offering |
|
49 |
self.path = path |
|
50 |
||
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
51 |
class Project(object): |
52 |
def __init__(self, offering, name): |
|
53 |
self.offering = offering |
|
54 |
self.name = name |
|
55 |
||
1294.2.37
by William Grant
Test a route with infinitely many arguments. |
56 |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
57 |
class View(object): |
58 |
def __init__(self, context): |
|
59 |
self.context = context |
|
60 |
||
61 |
class RootIndex(View): |
|
62 |
pass
|
|
63 |
||
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
64 |
class UserServeView(View): |
65 |
pass
|
|
66 |
||
1294.2.1
by William Grant
Add an object-traversal-based router. |
67 |
class SubjectIndex(View): |
68 |
pass
|
|
69 |
||
70 |
class SubjectEdit(View): |
|
71 |
pass
|
|
72 |
||
73 |
class OfferingIndex(View): |
|
74 |
pass
|
|
75 |
||
76 |
class OfferingEdit(View): |
|
77 |
pass
|
|
78 |
||
1294.2.2
by William Grant
Split out views from normal routes, and add a viewset concept. |
79 |
class OfferingAPIIndex(View): |
80 |
pass
|
|
81 |
||
1294.2.36
by William Grant
Replace the tests' OfferingProjects with OfferingFiles. |
82 |
class OfferingFilesIndex(View): |
1294.2.35
by William Grant
Fix and expand tests to cover new NotFound cases. |
83 |
pass
|
84 |
||
1294.2.37
by William Grant
Test a route with infinitely many arguments. |
85 |
class OfferingFileIndex(View): |
86 |
pass
|
|
87 |
||
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
88 |
class ProjectIndex(View): |
89 |
pass
|
|
90 |
||
1294.2.46
by William Grant
Add tests for default deep views. |
91 |
class OfferingProjects(View): |
92 |
pass
|
|
93 |
||
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
94 |
class OfferingAddProject(View): |
95 |
pass
|
|
96 |
||
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
97 |
def root_to_subject_or_user(root, name): |
98 |
if name.startswith('~'): |
|
99 |
return root.users.get(name[1:]) |
|
1294.2.35
by William Grant
Fix and expand tests to cover new NotFound cases. |
100 |
return root.subjects.get(name) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
101 |
|
102 |
def subject_to_offering(subject, year, semester): |
|
1294.2.35
by William Grant
Fix and expand tests to cover new NotFound cases. |
103 |
return subject.offerings.get((int(year), int(semester))) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
104 |
|
1294.2.36
by William Grant
Replace the tests' OfferingProjects with OfferingFiles. |
105 |
def offering_to_files(offering): |
106 |
return OfferingFiles(offering) |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
107 |
|
1294.2.37
by William Grant
Test a route with infinitely many arguments. |
108 |
def offering_files_to_file(offeringfiles, *path): |
109 |
return OfferingFile(offeringfiles, path) |
|
110 |
||
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
111 |
def offering_to_project(offering, name): |
112 |
return offering.projects.get(name) |
|
113 |
||
1294.2.1
by William Grant
Add an object-traversal-based router. |
114 |
def subject_url(subject): |
115 |
return (ROOT, subject.name) |
|
116 |
||
117 |
def offering_url(offering): |
|
118 |
return (offering.subject, (str(offering.year), str(offering.semester))) |
|
119 |
||
1294.2.40
by William Grant
Test generation of URLs for named routes. |
120 |
def offering_files_url(offeringfiles): |
121 |
return (offeringfiles.offering, '+files') |
|
1294.2.22
by William Grant
Test named routes. |
122 |
|
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
123 |
def project_url(project): |
124 |
return (project.offering, ('+projects', project.name)) |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
125 |
|
126 |
class BaseTest(object): |
|
127 |
def setUp(self): |
|
128 |
r = Root() |
|
129 |
self.r = r |
|
130 |
||
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
131 |
# A user would be nice.
|
132 |
r.add_user(User('jsmith')) |
|
133 |
||
1294.2.1
by William Grant
Add an object-traversal-based router. |
134 |
# Give us some subjects...
|
135 |
r.add_subject(Subject('info1', '600151')) |
|
136 |
r.add_subject(Subject('info2', '600152')) |
|
137 |
r.add_subject(Subject('info3', '600251')) |
|
138 |
||
139 |
# ... and some offerings.
|
|
140 |
r.subjects['info1'].add_offering(Offering(self.r.subjects['info1'], |
|
141 |
2008, 1)) |
|
142 |
r.subjects['info1'].add_offering(Offering(self.r.subjects['info1'], |
|
143 |
2008, 2)) |
|
144 |
r.subjects['info1'].add_offering(Offering(self.r.subjects['info1'], |
|
145 |
2009, 1)) |
|
146 |
r.subjects['info2'].add_offering(Offering(self.r.subjects['info2'], |
|
147 |
2008, 2)) |
|
148 |
r.subjects['info2'].add_offering(Offering(self.r.subjects['info2'], |
|
149 |
2009, 1)) |
|
150 |
r.subjects['info3'].add_offering(Offering(self.r.subjects['info3'], |
|
151 |
2009, 1)) |
|
152 |
||
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
153 |
# A normal project...
|
154 |
r.subjects['info1'].offerings[(2009, 1)].add_project( |
|
155 |
Project(r.subjects['info1'].offerings[(2009, 1)], 'p1') |
|
156 |
)
|
|
157 |
||
158 |
# And one conflicting with a deep view, just to be nasty.
|
|
159 |
r.subjects['info1'].offerings[(2009, 1)].add_project( |
|
160 |
Project(r.subjects['info1'].offerings[(2009, 1)], '+new') |
|
161 |
)
|
|
162 |
||
1294.2.1
by William Grant
Add an object-traversal-based router. |
163 |
class TestResolution(BaseTest): |
1294.2.10
by William Grant
Refactor resolution tests too. |
164 |
def setUp(self): |
165 |
super(TestResolution, self).setUp() |
|
1294.3.2
by William Grant
Router->Publisher |
166 |
self.rtr = Publisher(root=self.r, viewset='browser') |
1294.2.10
by William Grant
Refactor resolution tests too. |
167 |
self.rtr.add_set_switch('api', 'api') |
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
168 |
self.rtr.add_forward(Root, None, root_to_subject_or_user, 1) |
1294.2.10
by William Grant
Refactor resolution tests too. |
169 |
self.rtr.add_forward(Subject, None, subject_to_offering, 2) |
1294.2.36
by William Grant
Replace the tests' OfferingProjects with OfferingFiles. |
170 |
self.rtr.add_forward(Offering, '+files', offering_to_files, 0) |
1294.2.37
by William Grant
Test a route with infinitely many arguments. |
171 |
self.rtr.add_forward(OfferingFiles, None, offering_files_to_file, INF) |
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
172 |
self.rtr.add_forward(Offering, '+projects', offering_to_project, 1) |
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
173 |
self.rtr.add_view(User, None, UserServeView, viewset='browser') |
1294.2.10
by William Grant
Refactor resolution tests too. |
174 |
self.rtr.add_view(Subject, '+index', SubjectIndex, viewset='browser') |
175 |
self.rtr.add_view(Subject, '+edit', SubjectEdit, viewset='browser') |
|
176 |
self.rtr.add_view(Offering, '+index', OfferingIndex, viewset='browser') |
|
177 |
self.rtr.add_view(Offering, '+index', OfferingAPIIndex, viewset='api') |
|
1294.2.36
by William Grant
Replace the tests' OfferingProjects with OfferingFiles. |
178 |
self.rtr.add_view(OfferingFiles, '+index', OfferingFilesIndex, |
1294.2.35
by William Grant
Fix and expand tests to cover new NotFound cases. |
179 |
viewset='browser') |
1294.2.37
by William Grant
Test a route with infinitely many arguments. |
180 |
self.rtr.add_view(OfferingFile, '+index', OfferingFileIndex, |
181 |
viewset='browser') |
|
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
182 |
self.rtr.add_view(Project, '+index', ProjectIndex, viewset='browser') |
183 |
self.rtr.add_view(Offering, ('+projects', '+new'), OfferingAddProject, |
|
184 |
viewset='browser') |
|
1294.2.46
by William Grant
Add tests for default deep views. |
185 |
self.rtr.add_view(Offering, ('+projects', '+index'), OfferingProjects, |
186 |
viewset='browser') |
|
1294.2.10
by William Grant
Refactor resolution tests too. |
187 |
|
1294.2.23
by William Grant
Stop testing resolutions with views. |
188 |
def testOneRoute(self): |
189 |
assert_equal(self.rtr.resolve('/info1'), |
|
190 |
(self.r.subjects['info1'], SubjectIndex, ()) |
|
191 |
)
|
|
192 |
assert_equal(self.rtr.resolve('/info3'), |
|
193 |
(self.r.subjects['info3'], SubjectIndex, ()) |
|
194 |
)
|
|
195 |
||
196 |
def testTwoRoutes(self): |
|
197 |
assert_equal(self.rtr.resolve('/info1/2009/1'), |
|
198 |
(self.r.subjects['info1'].offerings[(2009, 1)], OfferingIndex, ()) |
|
199 |
)
|
|
200 |
assert_equal(self.rtr.resolve('/info2/2008/2'), |
|
201 |
(self.r.subjects['info2'].offerings[(2008, 2)], OfferingIndex, ()) |
|
202 |
)
|
|
1294.2.10
by William Grant
Refactor resolution tests too. |
203 |
|
1294.2.22
by William Grant
Test named routes. |
204 |
def testNamedRoute(self): |
1294.2.36
by William Grant
Replace the tests' OfferingProjects with OfferingFiles. |
205 |
assert_equal(type(self.rtr.resolve('/info1/2009/1/+files')[0]), |
206 |
OfferingFiles
|
|
1294.2.22
by William Grant
Test named routes. |
207 |
)
|
1294.2.36
by William Grant
Replace the tests' OfferingProjects with OfferingFiles. |
208 |
assert_equal(self.rtr.resolve('/info1/2009/1/+files')[0].offering, |
1294.2.22
by William Grant
Test named routes. |
209 |
self.r.subjects['info1'].offerings[(2009, 1)] |
210 |
)
|
|
211 |
||
1294.2.23
by William Grant
Stop testing resolutions with views. |
212 |
def testNonDefaultView(self): |
1294.2.10
by William Grant
Refactor resolution tests too. |
213 |
assert_equal(self.rtr.resolve('/info1/+edit'), |
1294.2.11
by William Grant
Revise generation and resolution tests to involve subpaths. |
214 |
(self.r.subjects['info1'], SubjectEdit, ()) |
1294.2.10
by William Grant
Refactor resolution tests too. |
215 |
)
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
216 |
|
1294.2.3
by William Grant
Add tests to complete coverage. |
217 |
def testDefaultView(self): |
1294.2.10
by William Grant
Refactor resolution tests too. |
218 |
assert_equal(self.rtr.resolve('/info1'), |
1294.2.11
by William Grant
Revise generation and resolution tests to involve subpaths. |
219 |
(self.r.subjects['info1'], SubjectIndex, ()) |
220 |
)
|
|
221 |
||
222 |
def testViewWithSubpath(self): |
|
223 |
assert_equal(self.rtr.resolve('/info1/+edit/foo/bar'), |
|
1294.2.13
by William Grant
Fix view mistake in test. |
224 |
(self.r.subjects['info1'], SubjectEdit, ('foo', 'bar')) |
1294.2.10
by William Grant
Refactor resolution tests too. |
225 |
)
|
226 |
||
1294.2.35
by William Grant
Fix and expand tests to cover new NotFound cases. |
227 |
def testNoDefaultView(self): |
228 |
try: |
|
229 |
self.rtr.default = 'not+index' |
|
230 |
self.rtr.resolve('/info1') |
|
231 |
except NotFound, e: |
|
232 |
assert_equal(e.args, (self.r.subjects['info1'], '+index', ())) |
|
233 |
except: |
|
234 |
raise
|
|
235 |
else: |
|
236 |
raise AssertionError('did not raise NotFound') |
|
237 |
finally: |
|
238 |
self.rtr.default = '+index' |
|
239 |
||
240 |
def testMissingView(self): |
|
241 |
try: |
|
242 |
self.rtr.resolve('/info1/+foo') |
|
243 |
except NotFound, e: |
|
244 |
assert_equal(e.args, (self.r.subjects['info1'], '+foo', ())) |
|
245 |
except: |
|
246 |
raise
|
|
247 |
else: |
|
248 |
raise AssertionError('did not raise NotFound') |
|
249 |
||
1294.2.10
by William Grant
Refactor resolution tests too. |
250 |
def testViewSetSeparation(self): |
1294.2.35
by William Grant
Fix and expand tests to cover new NotFound cases. |
251 |
try: |
252 |
self.rtr.resolve('/api/info1/+edit') |
|
253 |
except NotFound, e: |
|
254 |
assert_equal(e.args, (self.r.subjects['info1'], '+edit', ())) |
|
255 |
except: |
|
256 |
raise
|
|
257 |
else: |
|
258 |
raise AssertionError('did not raise NotFound') |
|
259 |
||
260 |
def testRouteReturningNone(self): |
|
261 |
try: |
|
262 |
self.rtr.resolve('/info9/+index') |
|
263 |
except NotFound, e: |
|
264 |
assert_equal(e.args, (self.r, 'info9', ('+index',))) |
|
265 |
except: |
|
266 |
raise
|
|
267 |
else: |
|
268 |
raise AssertionError('did not raise NotFound') |
|
1294.2.10
by William Grant
Refactor resolution tests too. |
269 |
|
1294.2.37
by William Grant
Test a route with infinitely many arguments. |
270 |
def testRouteWithInfinitelyManyArguments(self): |
271 |
o, v, sp = self.rtr.resolve('/info1/2009/1/+files/foo/bar/baz') |
|
272 |
||
273 |
assert_equal(type(o), OfferingFile) |
|
274 |
assert_equal(o.path, ('foo', 'bar', 'baz')) |
|
275 |
assert_equal(o.offering, self.r.subjects['info1'].offerings[(2009, 1)]) |
|
276 |
assert_equal(v, OfferingFileIndex) |
|
277 |
assert_equal(sp, ()) |
|
278 |
||
1294.2.38
by William Grant
Test behaviour when a nonexistent route is specified. |
279 |
def testMissingRoute(self): |
280 |
try: |
|
281 |
self.rtr.resolve('/info1/2009/1/+foo') |
|
282 |
except NotFound, e: |
|
283 |
assert_equal(e.args, ( |
|
284 |
self.r.subjects['info1'].offerings[(2009, 1)], |
|
285 |
'+foo', |
|
286 |
()
|
|
287 |
))
|
|
288 |
except: |
|
289 |
raise
|
|
290 |
else: |
|
291 |
raise AssertionError('did not raise NotFound') |
|
292 |
||
1294.2.10
by William Grant
Refactor resolution tests too. |
293 |
def testAlternateViewSetWithDefault(self): |
294 |
assert_equal(self.rtr.resolve('/info1/2009/1'), |
|
1294.2.11
by William Grant
Revise generation and resolution tests to involve subpaths. |
295 |
(self.r.subjects['info1'].offerings[(2009, 1)], OfferingIndex, ()) |
296 |
)
|
|
1294.2.2
by William Grant
Split out views from normal routes, and add a viewset concept. |
297 |
|
1294.2.10
by William Grant
Refactor resolution tests too. |
298 |
assert_equal(self.rtr.resolve('/api/info1/2009/1'), |
1294.2.11
by William Grant
Revise generation and resolution tests to involve subpaths. |
299 |
(self.r.subjects['info1'].offerings[(2009, 1)], OfferingAPIIndex, ()) |
300 |
)
|
|
1294.2.3
by William Grant
Add tests to complete coverage. |
301 |
|
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
302 |
def testDeepView(self): |
303 |
assert_equal(self.rtr.resolve('/info1/2009/1/+projects/+new'), |
|
304 |
(self.r.subjects['info1'].offerings[(2009, 1)], |
|
305 |
OfferingAddProject, ()) |
|
306 |
)
|
|
307 |
||
1294.2.46
by William Grant
Add tests for default deep views. |
308 |
def testDefaultDeepView(self): |
309 |
assert_equal(self.rtr.resolve('/info1/2009/1/+projects'), |
|
310 |
(self.r.subjects['info1'].offerings[(2009, 1)], |
|
311 |
OfferingProjects, ()) |
|
312 |
)
|
|
313 |
||
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
314 |
def testNamedRouteWithDeepView(self): |
315 |
assert_equal(self.rtr.resolve('/info1/2009/1/+projects/p1'), |
|
316 |
(self.r.subjects['info1'].offerings[(2009, 1)].projects['p1'], |
|
317 |
ProjectIndex, ()) |
|
318 |
)
|
|
319 |
||
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
320 |
def testNullPathView(self): |
321 |
"""Verify that views can be placed immediately under an object.
|
|
322 |
||
323 |
There are some cases in which it is useful for a view with a
|
|
324 |
subpath to exist immediately under an object, with no name.
|
|
325 |
"""
|
|
326 |
assert_equal(self.rtr.resolve('/~jsmith/foo/bar'), |
|
327 |
(self.r.users['jsmith'], UserServeView, ('foo', 'bar'))) |
|
328 |
||
1294.2.41
by William Grant
Test deep views (views with names consisting of multiple segments). |
329 |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
330 |
class TestGeneration(BaseTest): |
1294.2.9
by William Grant
Refactor generation tests. |
331 |
def setUp(self): |
332 |
super(TestGeneration, self).setUp() |
|
1294.3.2
by William Grant
Router->Publisher |
333 |
self.rtr = Publisher(root=self.r, viewset='browser') |
1294.2.9
by William Grant
Refactor generation tests. |
334 |
self.rtr.add_set_switch('api', 'api') |
335 |
self.rtr.add_reverse(Subject, subject_url) |
|
336 |
self.rtr.add_reverse(Offering, offering_url) |
|
1294.2.40
by William Grant
Test generation of URLs for named routes. |
337 |
self.rtr.add_reverse(OfferingFiles, offering_files_url) |
1294.2.43
by William Grant
Test deep view generation. |
338 |
self.rtr.add_reverse(Project, project_url) |
1294.2.9
by William Grant
Refactor generation tests. |
339 |
self.rtr.add_view(Subject, '+index', SubjectIndex, viewset='browser') |
340 |
self.rtr.add_view(Subject, '+edit', SubjectEdit, viewset='browser') |
|
341 |
self.rtr.add_view(Offering, '+index', OfferingIndex, viewset='browser') |
|
342 |
self.rtr.add_view(Offering, '+index', OfferingAPIIndex, viewset='api') |
|
1294.2.43
by William Grant
Test deep view generation. |
343 |
self.rtr.add_view(Project, '+index', ProjectIndex, viewset='browser') |
344 |
self.rtr.add_view(Offering, ('+projects', '+new'), OfferingAddProject, |
|
345 |
viewset='browser') |
|
1294.2.46
by William Grant
Add tests for default deep views. |
346 |
self.rtr.add_view(Offering, ('+projects', '+index'), OfferingProjects, |
347 |
viewset='browser') |
|
1294.2.9
by William Grant
Refactor generation tests. |
348 |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
349 |
def testOneLevel(self): |
1294.2.9
by William Grant
Refactor generation tests. |
350 |
assert_equal(self.rtr.generate(self.r.subjects['info1']), '/info1') |
1294.2.1
by William Grant
Add an object-traversal-based router. |
351 |
|
352 |
def testTwoLevel(self): |
|
1294.2.9
by William Grant
Refactor generation tests. |
353 |
assert_equal( |
354 |
self.rtr.generate(self.r.subjects['info1'].offerings[(2009, 1)]), |
|
355 |
'/info1/2009/1'
|
|
356 |
)
|
|
357 |
assert_equal( |
|
358 |
self.rtr.generate(self.r.subjects['info2'].offerings[(2008, 2)]), |
|
359 |
'/info2/2008/2'
|
|
360 |
)
|
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
361 |
|
1294.2.40
by William Grant
Test generation of URLs for named routes. |
362 |
def testNamedRoute(self): |
363 |
assert_equal(self.rtr.generate( |
|
364 |
OfferingFiles(self.r.subjects['info1'].offerings[(2009, 1)])), |
|
365 |
'/info1/2009/1/+files'
|
|
366 |
)
|
|
367 |
||
1294.2.9
by William Grant
Refactor generation tests. |
368 |
def testView(self): |
369 |
assert_equal(self.rtr.generate(self.r.subjects['info1'], SubjectEdit), |
|
370 |
'/info1/+edit'
|
|
371 |
)
|
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
372 |
|
1294.2.4
by William Grant
Support generation of view URLs. |
373 |
def testDefaultView(self): |
1294.2.9
by William Grant
Refactor generation tests. |
374 |
assert_equal( |
375 |
self.rtr.generate(self.r.subjects['info1'].offerings[(2009, 1)], |
|
376 |
OfferingIndex
|
|
377 |
),
|
|
378 |
'/info1/2009/1'
|
|
379 |
)
|
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
380 |
|
1294.2.11
by William Grant
Revise generation and resolution tests to involve subpaths. |
381 |
def testViewWithSubpath(self): |
382 |
assert_equal(self.rtr.generate(self.r.subjects['info1'], SubjectEdit, |
|
383 |
('foo', 'bar')), |
|
384 |
'/info1/+edit/foo/bar'
|
|
385 |
)
|
|
386 |
||
387 |
def testViewWithStringSubpath(self): |
|
388 |
assert_equal(self.rtr.generate(self.r.subjects['info1'], SubjectEdit, |
|
389 |
'foo/bar'), |
|
390 |
'/info1/+edit/foo/bar'
|
|
391 |
)
|
|
392 |
||
1294.2.9
by William Grant
Refactor generation tests. |
393 |
def testAlternateViewSetWithDefault(self): |
394 |
assert_equal( |
|
395 |
self.rtr.generate(self.r.subjects['info1'].offerings[(2009, 1)], |
|
396 |
OfferingAPIIndex
|
|
397 |
),
|
|
398 |
'/api/info1/2009/1'
|
|
399 |
)
|
|
1294.2.4
by William Grant
Support generation of view URLs. |
400 |
|
1294.2.43
by William Grant
Test deep view generation. |
401 |
def testDeepView(self): |
402 |
assert_equal( |
|
403 |
self.rtr.generate( |
|
404 |
self.r.subjects['info1'].offerings[(2009, 1)], |
|
405 |
OfferingAddProject
|
|
406 |
),
|
|
407 |
'/info1/2009/1/+projects/+new'
|
|
408 |
)
|
|
409 |
||
1294.2.46
by William Grant
Add tests for default deep views. |
410 |
def testDefaultDeepView(self): |
411 |
assert_equal( |
|
412 |
self.rtr.generate( |
|
413 |
self.r.subjects['info1'].offerings[(2009, 1)], |
|
414 |
OfferingProjects
|
|
415 |
),
|
|
416 |
'/info1/2009/1/+projects'
|
|
417 |
)
|
|
418 |
||
419 |
def testDefaultDeepViewWithSubpath(self): |
|
420 |
assert_equal( |
|
421 |
self.rtr.generate( |
|
422 |
self.r.subjects['info1'].offerings[(2009, 1)], |
|
423 |
OfferingProjects, ('foo', 'bar') |
|
424 |
),
|
|
425 |
'/info1/2009/1/+projects/+index/foo/bar'
|
|
426 |
)
|
|
427 |
||
1294.2.43
by William Grant
Test deep view generation. |
428 |
def testNamedRouteWithDeepView(self): |
429 |
assert_equal( |
|
430 |
self.rtr.generate( |
|
431 |
self.r.subjects['info1'].offerings[(2009, 1)].projects['p1'], |
|
432 |
ProjectIndex
|
|
433 |
),
|
|
434 |
'/info1/2009/1/+projects/p1'
|
|
435 |
)
|
|
436 |
||
1294.3.1
by William Grant
Allow reverse routes to return the real root too. |
437 |
def testRoot(self): |
438 |
assert_equal(self.rtr.generate(self.r), '/') |
|
1294.2.43
by William Grant
Test deep view generation. |
439 |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
440 |
|
441 |
class TestErrors(BaseTest): |
|
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
442 |
def setUp(self): |
443 |
super(TestErrors, self).setUp() |
|
1294.3.2
by William Grant
Router->Publisher |
444 |
self.rtr = Publisher(root=self.r) |
1294.2.136
by William Grant
Add publisher support for nameless views, directly under an object. |
445 |
self.rtr.add_forward(Root, None, root_to_subject_or_user, 1) |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
446 |
self.rtr.add_forward(Subject, '+foo', lambda s: s.name + 'foo', 0) |
447 |
self.rtr.add_forward(Subject, None, subject_to_offering, 2) |
|
448 |
self.rtr.add_reverse(Subject, subject_url) |
|
449 |
self.rtr.add_reverse(Offering, offering_url) |
|
450 |
self.rtr.add_view(Offering, '+index', OfferingIndex) |
|
451 |
self.rtr.add_view(Offering, '+index', OfferingAPIIndex, viewset='api') |
|
452 |
self.rtr.add_set_switch('rest', 'rest') |
|
453 |
||
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
454 |
@raises(RouteConflict) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
455 |
def testForwardConflict(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
456 |
self.rtr.add_forward(Subject, '+foo', object(), 2) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
457 |
|
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
458 |
@raises(RouteConflict) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
459 |
def testReverseConflict(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
460 |
self.rtr.add_reverse(Subject, object()) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
461 |
|
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
462 |
@raises(RouteConflict) |
1294.2.3
by William Grant
Add tests to complete coverage. |
463 |
def testViewConflict(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
464 |
self.rtr.add_view(Offering, '+index', object()) |
465 |
||
466 |
@raises(RouteConflict) |
|
467 |
def testSetSwitchForwardConflict(self): |
|
468 |
self.rtr.add_set_switch('rest', 'foo') |
|
469 |
||
470 |
@raises(RouteConflict) |
|
471 |
def testSetSwitchReverseConflict(self): |
|
472 |
self.rtr.add_set_switch('bar', 'rest') |
|
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
473 |
|
474 |
@raises(NoPath) |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
475 |
def testNoPath(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
476 |
self.rtr.generate(object()) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
477 |
|
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
478 |
@raises(NoPath) |
1294.2.4
by William Grant
Support generation of view URLs. |
479 |
def testNoSetSwitch(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
480 |
self.rtr.generate(self.r.subjects['info1'].offerings[(2009, 1)], |
481 |
OfferingAPIIndex) |
|
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
482 |
|
483 |
@raises(NoPath) |
|
1294.2.4
by William Grant
Support generation of view URLs. |
484 |
def testUnregisteredView(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
485 |
self.rtr.generate(self.r.subjects['info1'], SubjectIndex) |
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
486 |
|
487 |
@raises(NotFound) |
|
1294.2.1
by William Grant
Add an object-traversal-based router. |
488 |
def testNotFound(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
489 |
self.rtr.resolve('/bar') |
1294.2.1
by William Grant
Add an object-traversal-based router. |
490 |
|
1294.2.5
by William Grant
Use nose.tools.raises in the error tests. |
491 |
@raises(InsufficientPathSegments) |
1294.2.1
by William Grant
Add an object-traversal-based router. |
492 |
def testInsufficientPathSegments(self): |
1294.2.6
by William Grant
Refactor the error tests, using a single router. |
493 |
self.rtr.resolve('/info1/foo') |