Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket #12836 - Added a test to assure permalink wraps method attributes #360

Merged
merged 1 commit into from
Sep 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/regressiontests/model_permalink/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
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):
name = models.CharField(max_length=50)
slug = models.CharField(max_length=50)
Expand All @@ -9,3 +16,9 @@ class Guitarist(models.Model):
def url(self):
"Returns the URL for this guitarist."
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])
9 changes: 9 additions & 0 deletions tests/regressiontests/model_permalink/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ 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.")

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')