Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@calebsmith

The fix diff at the top of the ticket was already applied: https://code.djangoproject.com/ticket/12836

The test diff provided further down was a doc test, and was not applied or was removed along with the other doc tests.

This pull request includes a test that assures the permalink decorator passes on attributes attached to the function it wraps. The test fails if the @wraps decorator is removed from permalink, and succeeds otherwise.

@apollo13 apollo13 merged commit a630d08 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
13 tests/regressiontests/model_permalink/models.py
@@ -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)
@@ -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])
View
9 tests/regressiontests/model_permalink/tests.py
@@ -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')
Something went wrong with that request. Please try again.