4
4
from django .test import TestCase
5
5
from django .contrib .contenttypes .models import ContentType
6
6
7
- from regressiontests .views .models import Author , Article
7
+ from regressiontests .views .models import Author , Article , UrlArticle
8
8
9
9
class DefaultsTests (TestCase ):
10
10
"""Test django views in django/views/defaults.py"""
@@ -15,7 +15,7 @@ def test_shortcut_with_absolute_url(self):
15
15
for obj in Author .objects .all ():
16
16
short_url = '/views/shortcut/%s/%s/' % (ContentType .objects .get_for_model (Author ).id , obj .pk )
17
17
response = self .client .get (short_url )
18
- self .assertRedirects (response , 'http://testserver%s' % obj .get_absolute_url (),
18
+ self .assertRedirects (response , 'http://testserver%s' % obj .get_absolute_url (),
19
19
status_code = 302 , target_status_code = 404 )
20
20
21
21
def test_shortcut_no_absolute_url (self ):
@@ -59,3 +59,11 @@ def test_server_error(self):
59
59
"The server_error view raises a 500 status"
60
60
response = self .client .get ('/views/server_error/' )
61
61
self .assertEquals (response .status_code , 500 )
62
+
63
+ def test_get_absolute_url_attributes (self ):
64
+ "A model can set attributes on the get_absolute_url method"
65
+ self .assertTrue (getattr (UrlArticle .get_absolute_url , 'purge' , False ),
66
+ 'The attributes of the original get_absolute_url must be added.' )
67
+ article = UrlArticle .objects .get (pk = 1 )
68
+ self .assertTrue (getattr (article .get_absolute_url , 'purge' , False ),
69
+ 'The attributes of the original get_absolute_url must be added.' )
0 commit comments