diff options
| author | Florian Apolloner <apollo13@apolloner.eu> | 2012-09-16 14:00:51 -0700 |
|---|---|---|
| committer | Florian Apolloner <apollo13@apolloner.eu> | 2012-09-16 14:00:51 -0700 |
| commit | a630d08483267fbeb461f2fb06313d0e17ef6d44 (patch) | |
| tree | e0a15f0bd296fecfb1c3b30f5e2d4cbec0403654 | |
| parent | f399a804c9436a5d3ef9e2b73c337904af2c753d (diff) | |
| parent | 210fd7c658a44e51f4696555b3ce71498db55d96 (diff) | |
Merge pull request #360 from calebsmith/add-permalink-wraps-test
Ticket #12836 - Added a test to assure permalink wraps method attributes
| -rw-r--r-- | tests/regressiontests/model_permalink/models.py | 13 | ||||
| -rw-r--r-- | tests/regressiontests/model_permalink/tests.py | 9 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/regressiontests/model_permalink/models.py b/tests/regressiontests/model_permalink/models.py index 4823fd46c7..dacf2a3fb3 100644 --- a/tests/regressiontests/model_permalink/models.py +++ b/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]) diff --git a/tests/regressiontests/model_permalink/tests.py b/tests/regressiontests/model_permalink/tests.py index 8286f6811a..049f338c2e 100644 --- a/tests/regressiontests/model_permalink/tests.py +++ b/tests/regressiontests/model_permalink/tests.py @@ -16,3 +16,12 @@ class PermalinkTests(TestCase): "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') |
