~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-02 05:20:08 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: me@williamgrant.id.au-20090702052008-vuoz48indtmidbz2
Use nose.tools.raises in the error tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from nose.tools import assert_equal, raises
 
2
 
1
3
from ivle.webapp.urls import (InsufficientPathSegments, NoPath, NotFound,
2
4
                              RouteConflict, Router, ROOT)
3
5
 
209
211
 
210
212
 
211
213
class TestErrors(BaseTest):
 
214
    @raises(RouteConflict)
212
215
    def testForwardConflict(self):
213
216
        router = Router(root=self.r)
214
217
        router.add_forward(Subject, 'foo', object(), 1)
215
 
        try:
216
 
            router.add_forward(Subject, 'foo', object(), 2)
217
 
        except RouteConflict:
218
 
            pass
219
 
        else:
220
 
            raise AssertionError("did not raise RouteConflict")
 
218
        router.add_forward(Subject, 'foo', object(), 2)
221
219
 
 
220
    @raises(RouteConflict)
222
221
    def testReverseConflict(self):
223
222
        router = Router(root=self.r)
224
223
        router.add_reverse(Subject, object())
225
 
        try:
226
 
            router.add_reverse(Subject, object())
227
 
        except RouteConflict:
228
 
            pass
229
 
        else:
230
 
            raise AssertionError("did not raise RouteConflict")
 
224
        router.add_reverse(Subject, object())
231
225
 
 
226
    @raises(RouteConflict)
232
227
    def testViewConflict(self):
233
228
        router = Router(root=self.r)
234
229
        router.add_view(Subject, 'foo', object())
235
230
        router.add_view(Subject, 'foo', object(), viewset='bar')
236
 
        try:
237
 
            router.add_view(Subject, 'foo', object())
238
 
        except RouteConflict:
239
 
            pass
240
 
        else:
241
 
            raise AssertionError("did not raise RouteConflict")
 
231
        router.add_view(Subject, 'foo', object())
242
232
 
 
233
    @raises(RouteConflict)
243
234
    def testSetSwitchConflict(self):
244
235
        router = Router(root=self.r)
245
236
        router.add_set_switch('foo', 'bar')
246
 
 
247
 
        try:
248
 
            router.add_set_switch('foo', 'baz')
249
 
        except RouteConflict:
250
 
            pass
251
 
        else:
252
 
            raise AssertionError("did not raise RouteConflict")
253
 
 
 
237
        router.add_set_switch('foo', 'baz')
 
238
 
 
239
    @raises(NoPath)
254
240
    def testNoPath(self):
255
 
        try:
256
 
            Router(root=self.r).generate(object())
257
 
        except NoPath:
258
 
            pass
259
 
        else:
260
 
            raise AssertionError("did not raise NoPath")
 
241
        Router(root=self.r).generate(object())
261
242
 
 
243
    @raises(NoPath)
262
244
    def testNoSetSwitch(self):
263
245
        router = Router(root=self.r)
264
246
        router.add_reverse(Subject, subject_url)
265
247
        router.add_reverse(Offering, offering_url)
266
248
        router.add_view(Offering, '+index', OfferingAPIIndex, viewset='api')
267
 
 
268
 
        try:
269
 
            router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
270
 
                            OfferingAPIIndex)
271
 
        except NoPath:
272
 
            pass
273
 
        else:
274
 
            raise AssertionError("did not raise NoPath")
275
 
 
 
249
        router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
 
250
                        OfferingAPIIndex)
 
251
 
 
252
    @raises(NoPath)
276
253
    def testUnregisteredView(self):
277
254
        router = Router(root=self.r)
278
255
        router.add_reverse(Subject, subject_url)
279
256
        router.add_reverse(Offering, offering_url)
280
 
 
281
 
        try:
282
 
            router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
283
 
                            OfferingAPIIndex)
284
 
        except NoPath:
285
 
            pass
286
 
        else:
287
 
            raise AssertionError("did not raise NoPath")
288
 
 
 
257
        router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
 
258
                        OfferingAPIIndex)
 
259
 
 
260
    @raises(NotFound)
289
261
    def testNotFound(self):
290
262
        router = Router(root=self.r)
291
263
        router.add_forward(Root, 'foo', object(), 0)
292
 
        try:
293
 
            router.resolve('/bar')
294
 
        except NotFound:
295
 
            pass
296
 
        else:
297
 
            raise AssertionError("did not raise NotFound")
 
264
        router.resolve('/bar')
298
265
 
 
266
    @raises(InsufficientPathSegments)
299
267
    def testInsufficientPathSegments(self):
300
268
        router = Router(root=self.r)
301
269
        router.add_forward(Root, 'foo', object(), 2)
302
 
        try:
303
 
            router.resolve('/foo/bar')
304
 
        except InsufficientPathSegments:
305
 
            pass
306
 
        else:
307
 
            raise AssertionError("did not raise InsufficientPathSegments")
 
270
        router.resolve('/foo/bar')