diff options
Diffstat (limited to 'tests/model_permalink')
| -rw-r--r-- | tests/model_permalink/__init__.py | 0 | ||||
| -rw-r--r-- | tests/model_permalink/models.py | 24 | ||||
| -rw-r--r-- | tests/model_permalink/tests.py | 27 | ||||
| -rw-r--r-- | tests/model_permalink/urls.py | 5 |
4 files changed, 56 insertions, 0 deletions
diff --git a/tests/model_permalink/__init__.py b/tests/model_permalink/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/model_permalink/__init__.py diff --git a/tests/model_permalink/models.py b/tests/model_permalink/models.py new file mode 100644 index 0000000000..dacf2a3fb3 --- /dev/null +++ b/tests/model_permalink/models.py @@ -0,0 +1,24 @@ +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) + + @models.permalink + 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/model_permalink/tests.py b/tests/model_permalink/tests.py new file mode 100644 index 0000000000..049f338c2e --- /dev/null +++ b/tests/model_permalink/tests.py @@ -0,0 +1,27 @@ +from __future__ import absolute_import + +from django.test import TestCase + +from .models import Guitarist + + +class PermalinkTests(TestCase): + urls = 'regressiontests.model_permalink.urls' + + 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.") + + 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') diff --git a/tests/model_permalink/urls.py b/tests/model_permalink/urls.py new file mode 100644 index 0000000000..409fc222c8 --- /dev/null +++ b/tests/model_permalink/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls import patterns, url + +urlpatterns = patterns('', + url(r'^guitarists/(\w{1,50})/$', 'unimplemented_view_placeholder', name='guitarist_detail'), +) |
