Django

Code

Changeset 8751

Show
Ignore:
Timestamp:
08/30/08 16:30:02 (3 months ago)
Author:
jacob
Message:

Fixed #8716: correctly handle name and email in comments from authenticated users.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/comments/views/comments.py

    r8589 r8751  
    3737    data = request.POST.copy() 
    3838    if request.user.is_authenticated(): 
    39         if "name" not in data
     39        if not data.get('name', '')
    4040            data["name"] = request.user.get_full_name() 
    41         if "email" not in data
     41        if not data.get('email', '')
    4242            data["email"] = request.user.email 
    4343 
  • django/trunk/tests/regressiontests/comment_tests/fixtures/comment_tests.json

    r8557 r8751  
    3838    "fields" : { 
    3939        "username" : "normaluser", 
    40         "password" : "34ea4aaaf24efcbb4b30d27302f8657f" 
     40        "password" : "34ea4aaaf24efcbb4b30d27302f8657f", 
     41        "first_name": "Joe", 
     42        "last_name": "Normal", 
     43        "email": "joe.normal@example.com" 
    4144    } 
    4245  } 
  • django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py

    r8589 r8751  
    11from django.conf import settings 
     2from django.contrib.auth.models import User 
    23from django.contrib.comments import signals 
    34from django.contrib.comments.models import Comment 
     
    8586        self.assertEqual(c.ip_address, "1.2.3.4") 
    8687        self.assertEqual(c.comment, "This is my comment") 
     88         
     89    def testPostAsAuthenticatedUser(self): 
     90        a = Article.objects.get(pk=1) 
     91        data = self.getValidData(a) 
     92        data['name'] = data['email'] = '' 
     93        self.client.login(username="normaluser", password="normaluser") 
     94        self.response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4") 
     95        self.assertEqual(self.response.status_code, 302) 
     96        self.assertEqual(Comment.objects.count(), 1) 
     97        c = Comment.objects.all()[0] 
     98        self.assertEqual(c.ip_address, "1.2.3.4") 
     99        u = User.objects.get(username='normaluser') 
     100        self.assertEqual(c.user, u) 
     101        self.assertEqual(c.user_name, u.get_full_name()) 
     102        self.assertEqual(c.user_email, u.email) 
    87103 
    88104    def testPreventDuplicateComments(self):