2011-10-14 05:34:56 +08:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2011-03-14 13:22:39 +08:00
|
|
|
from django.test import TestCase
|
2011-10-14 05:34:56 +08:00
|
|
|
|
|
|
|
from .models import Guitarist
|
|
|
|
|
2011-03-14 13:22:39 +08:00
|
|
|
|
|
|
|
class PermalinkTests(TestCase):
|
2013-02-26 20:19:18 +08:00
|
|
|
urls = 'model_permalink.urls'
|
2011-03-14 13:22:39 +08:00
|
|
|
|
|
|
|
def test_permalink(self):
|
|
|
|
g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
|
|
|
|
self.assertEqual(g.url(), '/guitarists/adrienmoignard/')
|
|
|
|
|
|
|
|
def test_wrapped_docstring(self):
|
|
|
|
"Methods using the @permalink decorator retain their docstring."
|
|
|
|
g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
|
|
|
|
self.assertEqual(g.url.__doc__, "Returns the URL for this guitarist.")
|
2012-09-08 23:58:48 +08:00
|
|
|
|
|
|
|
def test_wrapped_attribute(self):
|
|
|
|
"""
|
|
|
|
Methods using the @permalink decorator can have attached attributes
|
|
|
|
from other decorators
|
|
|
|
"""
|
|
|
|
g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
|
|
|
|
self.assertTrue(hasattr(g.url_with_attribute, 'attribute'))
|
|
|
|
self.assertEqual(g.url_with_attribute.attribute, 'value')
|