mirror of https://github.com/django/django.git
Merge pull request #360 from calebsmith/add-permalink-wraps-test
Ticket #12836 - Added a test to assure permalink wraps method attributes
This commit is contained in:
commit
a630d08483
|
@ -1,6 +1,13 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
def set_attr(name, value):
|
||||||
|
def wrapper(function):
|
||||||
|
setattr(function, name, value)
|
||||||
|
return function
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class Guitarist(models.Model):
|
class Guitarist(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
slug = models.CharField(max_length=50)
|
slug = models.CharField(max_length=50)
|
||||||
|
@ -9,3 +16,9 @@ class Guitarist(models.Model):
|
||||||
def url(self):
|
def url(self):
|
||||||
"Returns the URL for this guitarist."
|
"Returns the URL for this guitarist."
|
||||||
return ('guitarist_detail', [self.slug])
|
return ('guitarist_detail', [self.slug])
|
||||||
|
|
||||||
|
@models.permalink
|
||||||
|
@set_attr('attribute', 'value')
|
||||||
|
def url_with_attribute(self):
|
||||||
|
"Returns the URL for this guitarist and holds an attribute"
|
||||||
|
return ('guitarist_detail', [self.slug])
|
||||||
|
|
|
@ -16,3 +16,12 @@ class PermalinkTests(TestCase):
|
||||||
"Methods using the @permalink decorator retain their docstring."
|
"Methods using the @permalink decorator retain their docstring."
|
||||||
g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
|
g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
|
||||||
self.assertEqual(g.url.__doc__, "Returns the URL for this guitarist.")
|
self.assertEqual(g.url.__doc__, "Returns the URL for this guitarist.")
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
Loading…
Reference in New Issue