~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/routing/test_router.py

  • Committer: William Grant
  • Date: 2009-07-05 08:57:26 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090705085726-w5aqfe833k3s3c0u
Add a breadcrumb generator (indexes plugins on what breadcrumbs they have).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from nose.tools import assert_equal, raises
2
2
 
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)
5
5
 
6
6
class Root(object):
7
7
    def __init__(self):
8
8
        self.subjects = {}
9
 
        self.users = {}
10
9
 
11
10
    def add_subject(self, subject):
12
11
        self.subjects[subject.name] = subject
13
12
 
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
 
 
21
13
class Subject(object):
22
14
    def __init__(self, name, code):
23
15
        self.name = name
61
53
class RootIndex(View):
62
54
    pass
63
55
 
64
 
class UserServeView(View):
65
 
    pass
66
 
 
67
56
class SubjectIndex(View):
68
57
    pass
69
58
 
94
83
class OfferingAddProject(View):
95
84
    pass
96
85
 
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)
101
88
 
102
89
def subject_to_offering(subject, year, semester):
128
115
        r = Root()
129
116
        self.r = r
130
117
 
131
 
        # A user would be nice.
132
 
        r.add_user(User('jsmith'))
133
 
 
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):
164
148
    def setUp(self):
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, ())
318
301
             )
319
302
 
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
 
 
329
303
 
330
304
class TestGeneration(BaseTest):
331
305
    def setUp(self):
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):
442
416
    def setUp(self):
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)