297 | 298 | |
298 | 299 | def test_simple_included_name(self): |
299 | 300 | "Normal lookups work on names included from other patterns" |
300 | 301 | self.assertEqual('/included/normal/', reverse('inc-normal-view')) |
301 | 302 | self.assertEqual('/included/normal/37/42/', reverse('inc-normal-view', args=[37,42])) |
302 | 303 | self.assertEqual('/included/normal/42/37/', reverse('inc-normal-view', kwargs={'arg1':42, 'arg2':37})) |
303 | 305 | |
304 | 306 | def test_namespace_object(self): |
305 | 307 | "Dynamic URL objects can be found using a namespace" |
306 | 308 | self.assertEqual('/test1/inner/', reverse('test-ns1:urlobject-view')) |
307 | 309 | self.assertEqual('/test1/inner/37/42/', reverse('test-ns1:urlobject-view', args=[37,42])) |
308 | 310 | self.assertEqual('/test1/inner/42/37/', reverse('test-ns1:urlobject-view', kwargs={'arg1':42, 'arg2':37})) |
309 | 312 | |
310 | 313 | def test_embedded_namespace_object(self): |
311 | 314 | "Namespaces can be installed anywhere in the URL pattern tree" |
312 | 315 | self.assertEqual('/included/test3/inner/', reverse('test-ns3:urlobject-view')) |
313 | 316 | self.assertEqual('/included/test3/inner/37/42/', reverse('test-ns3:urlobject-view', args=[37,42])) |
314 | 317 | self.assertEqual('/included/test3/inner/42/37/', reverse('test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37})) |
315 | 319 | |
316 | 320 | def test_namespace_pattern(self): |
317 | 321 | "Namespaces can be applied to include()'d urlpatterns" |
318 | 322 | self.assertEqual('/ns-included1/normal/', reverse('inc-ns1:inc-normal-view')) |
319 | 323 | self.assertEqual('/ns-included1/normal/37/42/', reverse('inc-ns1:inc-normal-view', args=[37,42])) |
320 | 324 | self.assertEqual('/ns-included1/normal/42/37/', reverse('inc-ns1:inc-normal-view', kwargs={'arg1':42, 'arg2':37})) |
328 | 335 | |
329 | 336 | def test_multiple_namespace_pattern(self): |
330 | 337 | "Namespaces can be embedded" |
331 | 338 | self.assertEqual('/ns-included1/test3/inner/', reverse('inc-ns1:test-ns3:urlobject-view')) |
332 | 339 | self.assertEqual('/ns-included1/test3/inner/37/42/', reverse('inc-ns1:test-ns3:urlobject-view', args=[37,42])) |
333 | 340 | self.assertEqual('/ns-included1/test3/inner/42/37/', reverse('inc-ns1:test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37})) |
334 | 342 | |
335 | 343 | def test_nested_namespace_pattern(self): |
336 | 344 | "Namespaces can be nested" |
337 | 345 | self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view')) |
338 | 346 | self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/37/42/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', args=[37,42])) |
339 | 347 | self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/42/37/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37})) |
340 | 349 | |
341 | 350 | def test_app_lookup_object(self): |
342 | 351 | "A default application namespace can be used for lookup" |
343 | 352 | self.assertEqual('/default/inner/', reverse('testapp:urlobject-view')) |
344 | 353 | self.assertEqual('/default/inner/37/42/', reverse('testapp:urlobject-view', args=[37,42])) |
345 | 354 | self.assertEqual('/default/inner/42/37/', reverse('testapp:urlobject-view', kwargs={'arg1':42, 'arg2':37})) |
346 | 356 | |
347 | 357 | def test_app_lookup_object_with_default(self): |
348 | 358 | "A default application namespace is sensitive to the 'current' app can be used for lookup" |
349 | 359 | self.assertEqual('/included/test3/inner/', reverse('testapp:urlobject-view', current_app='test-ns3')) |
350 | 360 | self.assertEqual('/included/test3/inner/37/42/', reverse('testapp:urlobject-view', args=[37,42], current_app='test-ns3')) |
351 | 361 | self.assertEqual('/included/test3/inner/42/37/', reverse('testapp:urlobject-view', kwargs={'arg1':42, 'arg2':37}, current_app='test-ns3')) |
352 | 363 | |
353 | 364 | def test_app_lookup_object_without_default(self): |
354 | 365 | "An application namespace without a default is sensitive to the 'current' app can be used for lookup" |
355 | 366 | self.assertEqual('/other2/inner/', reverse('nodefault:urlobject-view')) |
356 | 367 | self.assertEqual('/other2/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42])) |
357 | 368 | self.assertEqual('/other2/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37})) |
| 376 | def test_special_chars_namespace(self): |
| 377 | self.assertEqual('/+%5C$*/included/normal/', reverse('special:inc-normal-view')) |
| 378 | self.assertEqual('/+%5C$*/included/normal/37/42/', reverse('special:inc-normal-view', args=[37,42])) |
| 379 | self.assertEqual('/+%5C$*/included/normal/42/37/', reverse('special:inc-normal-view', kwargs={'arg1':42, 'arg2':37})) |
| 380 | self.assertEqual('/+%5C$*/included/+%5C$*/', reverse('special:inc-special-view')) |
| 381 | |