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