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)
216
router.add_forward(Subject, 'foo', object(), 2)
217
except RouteConflict:
220
raise AssertionError("did not raise RouteConflict")
218
router.add_forward(Subject, 'foo', object(), 2)
220
@raises(RouteConflict)
222
221
def testReverseConflict(self):
223
222
router = Router(root=self.r)
224
223
router.add_reverse(Subject, object())
226
router.add_reverse(Subject, object())
227
except RouteConflict:
230
raise AssertionError("did not raise RouteConflict")
224
router.add_reverse(Subject, object())
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')
237
router.add_view(Subject, 'foo', object())
238
except RouteConflict:
241
raise AssertionError("did not raise RouteConflict")
231
router.add_view(Subject, 'foo', object())
233
@raises(RouteConflict)
243
234
def testSetSwitchConflict(self):
244
235
router = Router(root=self.r)
245
236
router.add_set_switch('foo', 'bar')
248
router.add_set_switch('foo', 'baz')
249
except RouteConflict:
252
raise AssertionError("did not raise RouteConflict")
237
router.add_set_switch('foo', 'baz')
254
240
def testNoPath(self):
256
Router(root=self.r).generate(object())
260
raise AssertionError("did not raise NoPath")
241
Router(root=self.r).generate(object())
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')
269
router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
274
raise AssertionError("did not raise NoPath")
249
router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
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)
282
router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
287
raise AssertionError("did not raise NoPath")
257
router.generate(self.r.subjects['info1'].offerings[(2009, 1)],
289
261
def testNotFound(self):
290
262
router = Router(root=self.r)
291
263
router.add_forward(Root, 'foo', object(), 0)
293
router.resolve('/bar')
297
raise AssertionError("did not raise NotFound")
264
router.resolve('/bar')
266
@raises(InsufficientPathSegments)
299
267
def testInsufficientPathSegments(self):
300
268
router = Router(root=self.r)
301
269
router.add_forward(Root, 'foo', object(), 2)
303
router.resolve('/foo/bar')
304
except InsufficientPathSegments:
307
raise AssertionError("did not raise InsufficientPathSegments")
270
router.resolve('/foo/bar')