Django

Code

Ticket #9956: comments_urls_9956.diff

File comments_urls_9956.diff, 8.4 kB (added by kkubasik, 1 year ago)
  • a/django/contrib/comments/urls.py

    old new  
    1313) 
    1414 
    1515urlpatterns += patterns('', 
    16     url(r'^cr/(\d+)/(\w+)/$', 'django.views.defaults.shortcut', name='comments-url-redirect'), 
     16    url(r'^cr/(\d+)/((\w|-)+)/$', 'django.views.defaults.shortcut', name='comments-url-redirect'), 
    1717) 
    1818 
  • a/tests/regressiontests/comment_tests/fixtures/comment_utils.xml

    old new  
    1212      <field type="DateField" name="pub_date">2008-01-02</field> 
    1313      <field type="BooleanField" name="enable_comments">False</field> 
    1414  </object> 
     15  <object pk="1" model="comment_tests.slugpost"> 
     16      <field type="SlugField" name="slug">test-this</field> 
     17  </object> 
    1518</django-objects> 
  • a/tests/regressiontests/comment_tests/models.py

    old new  
    2828 
    2929    def __str__(self): 
    3030        return self.title 
     31 
     32class SlugPost(models.Model): 
     33    """A Post like model whos PK is a slug""" 
     34    slug = models.SlugField(primary_key=True,max_length=100) 
     35     
     36    def __str__(self): 
     37        return self.slug 
     38     
     39     
  • a/tests/regressiontests/comment_tests/tests/__init__.py

    old new  
    44from django.contrib.contenttypes.models import ContentType 
    55from django.contrib.sites.models import Site 
    66from django.test import TestCase 
    7 from regressiontests.comment_tests.models import Article, Author 
     7from regressiontests.comment_tests.models import Article, Author, SlugPost 
    88 
    99# Shortcut 
    1010CT = ContentType.objects.get_for_model 
     
    5555            comment = "Damn, I wanted to be first.", 
    5656            site = Site.objects.get_current(), 
    5757        ) 
     58         
    5859        c4 = Comment.objects.create( 
    5960            content_type = CT(Author), 
    6061            object_pk = "2", 
     
    6364            comment = "You get here first, too?", 
    6465            site = Site.objects.get_current(), 
    6566        ) 
     67         
     68        c5 = Comment.objects.create( 
     69            content_type = CT(SlugPost), 
     70            object_pk = "test-this", 
     71            user = user, 
     72            user_url = "http://example.com/~frank/", 
     73            comment = "Wonder how the slugs work", 
     74            site = Site.objects.get_current(), 
     75        ) 
    6676 
    67         return c1, c2, c3, c4 
     77        return c1, c2, c3, c4, c5 
    6878 
    6979    def getData(self): 
    7080        return { 
  • a/tests/regressiontests/comment_tests/tests/comment_view_tests.py

    old new  
    33from django.contrib.auth.models import User 
    44from django.contrib.comments import signals 
    55from django.contrib.comments.models import Comment 
    6 from regressiontests.comment_tests.models import Article 
     6from django.core import urlresolvers 
     7from regressiontests.comment_tests.models import Article, SlugPost 
    78from regressiontests.comment_tests.tests import CommentTestCase 
    89 
    910post_redirect_re = re.compile(r'^http://testserver/posted/\?c=(?P<pk>\d+$)') 
     
    206207        response = self.client.get(location) 
    207208        self.assertTemplateUsed(response, "comments/posted.html") 
    208209        self.assertEqual(response.context[0]["comment"], Comment.objects.get(pk=pk)) 
    209  
     210         
     211    #---------------------------------------------------------------------- 
     212    def testCommentUrlLookup(self): 
     213        """""" 
     214        c1, c2, c3, c4, c5 = self.createSomeComments() 
     215        c5.save() 
     216        sp = Comment.objects.get(object_pk='test-this') 
     217        url = urlresolvers.reverse("comments-url-redirect",  
     218                                   args=(c5.content_type_id, c5.object_pk)) 
     219        self.assertEqual(url,'/cr/%i/%s/' % (c5.content_type_id,c5.object_pk) ) 
  • a/tests/regressiontests/comment_tests/tests/model_tests.py

    old new  
    99            self.failIfEqual(c.submit_date, None) 
    1010 
    1111    def testUserProperties(self): 
    12         c1, c2, c3, c4 = self.createSomeComments() 
     12        c1, c2, c3, c4, c5 = self.createSomeComments() 
    1313        self.assertEqual(c1.name, "Joe Somebody") 
    1414        self.assertEqual(c2.email, "jsomebody@example.com") 
    1515        self.assertEqual(c3.name, "Frank Nobody") 
     
    2121 
    2222    def testInModeration(self): 
    2323        """Comments that aren't public are considered in moderation""" 
    24         c1, c2, c3, c4 = self.createSomeComments() 
     24        c1, c2, c3, c4, c5 = self.createSomeComments() 
    2525        c1.is_public = False 
    2626        c2.is_public = False 
    2727        c1.save() 
     
    3131 
    3232    def testRemovedCommentsNotInModeration(self): 
    3333        """Removed comments are not considered in moderation""" 
    34         c1, c2, c3, c4 = self.createSomeComments() 
     34        c1, c2, c3, c4, c5 = self.createSomeComments() 
    3535        c1.is_public = False 
    3636        c2.is_public = False 
    3737        c2.is_removed = True 
     
    4141        self.assertEqual(moderated_comments, [c1]) 
    4242 
    4343    def testForModel(self): 
    44         c1, c2, c3, c4 = self.createSomeComments() 
     44        c1, c2, c3, c4, c5 = self.createSomeComments() 
    4545        article_comments = list(Comment.objects.for_model(Article).order_by("id")) 
    4646        author_comments = list(Comment.objects.for_model(Author.objects.get(pk=1))) 
    4747        self.assertEqual(article_comments, [c1, c3]) 
  • a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py

    old new  
    130130 
    131131    def testApprovePost(self): 
    132132        """POSTing the delete view should mark the comment as removed""" 
    133         c1, c2, c3, c4 = self.createSomeComments() 
     133        c1, c2, c3, c4, c5 = self.createSomeComments() 
    134134        c1.is_public = False; c1.save() 
    135135 
    136136        makeModerator("normaluser") 
     
    174174 
    175175    def testModerationQueueContents(self): 
    176176        """Moderation queue should display non-public, non-removed comments.""" 
    177         c1, c2, c3, c4 = self.createSomeComments() 
     177        c1, c2, c3, c4, c5 = self.createSomeComments() 
    178178        makeModerator("normaluser") 
    179179        self.client.login(username="normaluser", password="normaluser") 
    180180 
  • a/tests/regressiontests/comment_tests/tests/templatetag_tests.py

    old new  
    5252        self.testGetCommentCount("{% get_comment_count for a as cc %}") 
    5353 
    5454    def testGetCommentList(self, tag=None): 
    55         c1, c2, c3, c4 = self.createSomeComments() 
     55        c1, c2, c3, c4, c5 = self.createSomeComments() 
    5656        t = "{% load comments %}" + (tag or "{% get_comment_list for comment_tests.author a.id as cl %}") 
    5757        ctx, out = self.render(t, a=Author.objects.get(pk=1)) 
    5858        self.assertEqual(out, "")