1
1
from nose.tools import assert_equal, raises
3
from ivle.webapp.publisher import (INF, InsufficientPathSegments, NoPath,
4
NotFound, RouteConflict, Publisher, ROOT)
3
from ivle.webapp.routing import (INF, InsufficientPathSegments, NoPath,
4
NotFound, RouteConflict, Router, ROOT)
11
10
def add_subject(self, subject):
12
11
self.subjects[subject.name] = subject
14
def add_user(self, user):
15
self.users[user.login] = user
18
def __init__(self, login):
21
13
class Subject(object):
22
14
def __init__(self, name, code):
94
83
class OfferingAddProject(View):
97
def root_to_subject_or_user(root, name):
98
if name.startswith('~'):
99
return root.users.get(name[1:])
86
def root_to_subject(root, name):
100
87
return root.subjects.get(name)
102
89
def subject_to_offering(subject, year, semester):
131
# A user would be nice.
132
r.add_user(User('jsmith'))
134
118
# Give us some subjects...
135
119
r.add_subject(Subject('info1', '600151'))
136
120
r.add_subject(Subject('info2', '600152'))
163
147
class TestResolution(BaseTest):
165
149
super(TestResolution, self).setUp()
166
self.rtr = Publisher(root=self.r, viewset='browser')
150
self.rtr = Router(root=self.r, viewset='browser')
167
151
self.rtr.add_set_switch('api', 'api')
168
self.rtr.add_forward(Root, None, root_to_subject_or_user, 1)
152
self.rtr.add_forward(Root, None, root_to_subject, 1)
169
153
self.rtr.add_forward(Subject, None, subject_to_offering, 2)
170
154
self.rtr.add_forward(Offering, '+files', offering_to_files, 0)
171
155
self.rtr.add_forward(OfferingFiles, None, offering_files_to_file, INF)
172
156
self.rtr.add_forward(Offering, '+projects', offering_to_project, 1)
173
self.rtr.add_view(User, None, UserServeView, viewset='browser')
174
157
self.rtr.add_view(Subject, '+index', SubjectIndex, viewset='browser')
175
158
self.rtr.add_view(Subject, '+edit', SubjectEdit, viewset='browser')
176
159
self.rtr.add_view(Offering, '+index', OfferingIndex, viewset='browser')
317
300
ProjectIndex, ())
320
def testNullPathView(self):
321
"""Verify that views can be placed immediately under an object.
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.
326
assert_equal(self.rtr.resolve('/~jsmith/foo/bar'),
327
(self.r.users['jsmith'], UserServeView, ('foo', 'bar')))
330
304
class TestGeneration(BaseTest):
332
306
super(TestGeneration, self).setUp()
333
self.rtr = Publisher(root=self.r, viewset='browser')
307
self.rtr = Router(root=self.r, viewset='browser')
334
308
self.rtr.add_set_switch('api', 'api')
335
309
self.rtr.add_reverse(Subject, subject_url)
336
310
self.rtr.add_reverse(Offering, offering_url)
441
415
class TestErrors(BaseTest):
443
417
super(TestErrors, self).setUp()
444
self.rtr = Publisher(root=self.r)
445
self.rtr.add_forward(Root, None, root_to_subject_or_user, 1)
418
self.rtr = Router(root=self.r)
419
self.rtr.add_forward(Root, None, root_to_subject, 1)
446
420
self.rtr.add_forward(Subject, '+foo', lambda s: s.name + 'foo', 0)
447
421
self.rtr.add_forward(Subject, None, subject_to_offering, 2)
448
422
self.rtr.add_reverse(Subject, subject_url)