Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8716: correctly handle name and email in comments from authent…

…icated users.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8751 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ae72e25b354f6cc185eeb42a81ac79b83c5a636c 1 parent eebc7ca
Jacob Kaplan-Moss authored August 30, 2008
4  django/contrib/comments/views/comments.py
@@ -36,9 +36,9 @@ def post_comment(request, next=None):
36 36
     # Fill out some initial data fields from an authenticated user, if present
37 37
     data = request.POST.copy()
38 38
     if request.user.is_authenticated():
39  
-        if "name" not in data:
  39
+        if not data.get('name', ''):
40 40
             data["name"] = request.user.get_full_name()
41  
-        if "email" not in data:
  41
+        if not data.get('email', ''):
42 42
             data["email"] = request.user.email
43 43
 
44 44
     # Look up the object we're trying to comment about
5  tests/regressiontests/comment_tests/fixtures/comment_tests.json
@@ -37,7 +37,10 @@
37 37
     "pk" : 100,
38 38
     "fields" : {
39 39
         "username" : "normaluser",
40  
-        "password" : "34ea4aaaf24efcbb4b30d27302f8657f"
  40
+        "password" : "34ea4aaaf24efcbb4b30d27302f8657f",
  41
+        "first_name": "Joe",
  42
+        "last_name": "Normal",
  43
+        "email": "joe.normal@example.com"
41 44
     }
42 45
   }
43 46
 ]
16  tests/regressiontests/comment_tests/tests/comment_view_tests.py
... ...
@@ -1,4 +1,5 @@
1 1
 from django.conf import settings
  2
+from django.contrib.auth.models import User
2 3
 from django.contrib.comments import signals
3 4
 from django.contrib.comments.models import Comment
4 5
 from regressiontests.comment_tests.models import Article
@@ -84,6 +85,21 @@ def testCreateValidComment(self):
84 85
         c = Comment.objects.all()[0]
85 86
         self.assertEqual(c.ip_address, "1.2.3.4")
86 87
         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)
87 103
 
88 104
     def testPreventDuplicateComments(self):
89 105
         """Prevent posting the exact same comment twice"""

0 notes on commit ae72e25

Please sign in to comment.
Something went wrong with that request. Please try again.