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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-07-04 08:01:09 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-20090704080109-ndi3c742u8vuj4rw
Test a route with infinitely many arguments.

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.urls import (InsufficientPathSegments, NoPath, NotFound,
 
3
from ivle.webapp.urls import (INF, InsufficientPathSegments, NoPath, NotFound,
4
4
                              RouteConflict, Router, ROOT)
5
5
 
6
6
class Root(object):
30
30
    def __init__(self, offering):
31
31
        self.offering = offering
32
32
 
 
33
class OfferingFile(object):
 
34
    def __init__(self, offeringfiles, path):
 
35
        self.offering = offeringfiles.offering
 
36
        self.path = path
 
37
 
 
38
 
33
39
class View(object):
34
40
    def __init__(self, context):
35
41
        self.context = context
55
61
class OfferingFilesIndex(View):
56
62
    pass
57
63
 
 
64
class OfferingFileIndex(View):
 
65
    pass
 
66
 
58
67
 
59
68
def root_to_subject(root, name):
60
69
    return root.subjects.get(name)
65
74
def offering_to_files(offering):
66
75
    return OfferingFiles(offering)
67
76
 
 
77
def offering_files_to_file(offeringfiles, *path):
 
78
    return OfferingFile(offeringfiles, path)
 
79
 
68
80
def subject_url(subject):
69
81
    return (ROOT, subject.name)
70
82
 
107
119
        self.rtr.add_forward(Root, None, root_to_subject, 1)
108
120
        self.rtr.add_forward(Subject, None, subject_to_offering, 2)
109
121
        self.rtr.add_forward(Offering, '+files', offering_to_files, 0)
 
122
        self.rtr.add_forward(OfferingFiles, None, offering_files_to_file, INF)
110
123
        self.rtr.add_view(Subject, '+index', SubjectIndex, viewset='browser')
111
124
        self.rtr.add_view(Subject, '+edit', SubjectEdit, viewset='browser')
112
125
        self.rtr.add_view(Offering, '+index', OfferingIndex, viewset='browser')
113
126
        self.rtr.add_view(Offering, '+index', OfferingAPIIndex, viewset='api')
114
127
        self.rtr.add_view(OfferingFiles, '+index', OfferingFilesIndex,
115
128
                          viewset='browser')
 
129
        self.rtr.add_view(OfferingFile, '+index', OfferingFileIndex,
 
130
                          viewset='browser')
116
131
 
117
132
    def testOneRoute(self):
118
133
        assert_equal(self.rtr.resolve('/info1'),
196
211
        else:
197
212
            raise AssertionError('did not raise NotFound')
198
213
 
 
214
    def testRouteWithInfinitelyManyArguments(self):
 
215
        o, v, sp = self.rtr.resolve('/info1/2009/1/+files/foo/bar/baz')
 
216
 
 
217
        assert_equal(type(o), OfferingFile)
 
218
        assert_equal(o.path, ('foo', 'bar', 'baz'))
 
219
        assert_equal(o.offering, self.r.subjects['info1'].offerings[(2009, 1)])
 
220
        assert_equal(v, OfferingFileIndex)
 
221
        assert_equal(sp, ())
 
222
 
199
223
    def testAlternateViewSetWithDefault(self):
200
224
        assert_equal(self.rtr.resolve('/info1/2009/1'),
201
225
             (self.r.subjects['info1'].offerings[(2009, 1)], OfferingIndex, ())