Author: jacob
Date: 2008-08-30 16:30:02 -0500 (Sat, 30 Aug 2008)
New Revision: 8751

Modified:
   django/trunk/django/contrib/comments/views/comments.py
   django/trunk/tests/regressiontests/comment_tests/fixtures/comment_tests.json
   django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py
Log:
Fixed #8716: correctly handle name and email in comments from authenticated 
users.

Modified: django/trunk/django/contrib/comments/views/comments.py
===================================================================
--- django/trunk/django/contrib/comments/views/comments.py      2008-08-30 
20:50:41 UTC (rev 8750)
+++ django/trunk/django/contrib/comments/views/comments.py      2008-08-30 
21:30:02 UTC (rev 8751)
@@ -36,9 +36,9 @@
     # Fill out some initial data fields from an authenticated user, if present
     data = request.POST.copy()
     if request.user.is_authenticated():
-        if "name" not in data:
+        if not data.get('name', ''):
             data["name"] = request.user.get_full_name()
-        if "email" not in data:
+        if not data.get('email', ''):
             data["email"] = request.user.email
 
     # Look up the object we're trying to comment about

Modified: 
django/trunk/tests/regressiontests/comment_tests/fixtures/comment_tests.json
===================================================================
--- 
django/trunk/tests/regressiontests/comment_tests/fixtures/comment_tests.json    
    2008-08-30 20:50:41 UTC (rev 8750)
+++ 
django/trunk/tests/regressiontests/comment_tests/fixtures/comment_tests.json    
    2008-08-30 21:30:02 UTC (rev 8751)
@@ -37,7 +37,10 @@
     "pk" : 100,
     "fields" : {
         "username" : "normaluser",
-        "password" : "34ea4aaaf24efcbb4b30d27302f8657f"
+        "password" : "34ea4aaaf24efcbb4b30d27302f8657f",
+        "first_name": "Joe",
+        "last_name": "Normal",
+        "email": "[EMAIL PROTECTED]"
     }
   }
 ]

Modified: 
django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py
===================================================================
--- 
django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py    
    2008-08-30 20:50:41 UTC (rev 8750)
+++ 
django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py    
    2008-08-30 21:30:02 UTC (rev 8751)
@@ -1,4 +1,5 @@
 from django.conf import settings
+from django.contrib.auth.models import User
 from django.contrib.comments import signals
 from django.contrib.comments.models import Comment
 from regressiontests.comment_tests.models import Article
@@ -84,6 +85,21 @@
         c = Comment.objects.all()[0]
         self.assertEqual(c.ip_address, "1.2.3.4")
         self.assertEqual(c.comment, "This is my comment")
+        
+    def testPostAsAuthenticatedUser(self):
+        a = Article.objects.get(pk=1)
+        data = self.getValidData(a)
+        data['name'] = data['email'] = ''
+        self.client.login(username="normaluser", password="normaluser")
+        self.response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
+        self.assertEqual(self.response.status_code, 302)
+        self.assertEqual(Comment.objects.count(), 1)
+        c = Comment.objects.all()[0]
+        self.assertEqual(c.ip_address, "1.2.3.4")
+        u = User.objects.get(username='normaluser')
+        self.assertEqual(c.user, u)
+        self.assertEqual(c.user_name, u.get_full_name())
+        self.assertEqual(c.user_email, u.email)
 
     def testPreventDuplicateComments(self):
         """Prevent posting the exact same comment twice"""


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to