Skip to content

Commit

Permalink
Fixed #8803 -- Allow authenticated users without first_name/last_name…
Browse files Browse the repository at this point in the history
… values set to post comments.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Oct 5, 2008
1 parent 16d0a61 commit 227a93b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django/contrib/comments/views/comments.py
Expand Up @@ -37,7 +37,7 @@ def post_comment(request, next=None):
data = request.POST.copy() data = request.POST.copy()
if request.user.is_authenticated(): if request.user.is_authenticated():
if not data.get('name', ''): if not data.get('name', ''):
data["name"] = request.user.get_full_name() data["name"] = request.user.get_full_name() or request.user.username
if not data.get('email', ''): if not data.get('email', ''):
data["email"] = request.user.email data["email"] = request.user.email


Expand Down
21 changes: 19 additions & 2 deletions tests/regressiontests/comment_tests/tests/comment_view_tests.py
Expand Up @@ -85,7 +85,7 @@ def testCreateValidComment(self):
c = Comment.objects.all()[0] c = Comment.objects.all()[0]
self.assertEqual(c.ip_address, "1.2.3.4") self.assertEqual(c.ip_address, "1.2.3.4")
self.assertEqual(c.comment, "This is my comment") self.assertEqual(c.comment, "This is my comment")

def testPostAsAuthenticatedUser(self): def testPostAsAuthenticatedUser(self):
a = Article.objects.get(pk=1) a = Article.objects.get(pk=1)
data = self.getValidData(a) data = self.getValidData(a)
Expand All @@ -101,6 +101,23 @@ def testPostAsAuthenticatedUser(self):
self.assertEqual(c.user_name, u.get_full_name()) self.assertEqual(c.user_name, u.get_full_name())
self.assertEqual(c.user_email, u.email) self.assertEqual(c.user_email, u.email)


def testPostAsAuthenticatedUserWithoutFullname(self):
"""
Check that the user's name in the comment is populated for
authenticated users without first_name and last_name.
"""
user = User.objects.create_user(username='jane_other',
email='jane@example.com', password='jane_other')
a = Article.objects.get(pk=1)
data = self.getValidData(a)
data['name'] = data['email'] = ''
self.client.login(username="jane_other", password="jane_other")
self.response = self.client.post("/post/", data, REMOTE_ADDR="1.2.3.4")
c = Comment.objects.get(user=user)
self.assertEqual(c.ip_address, "1.2.3.4")
self.assertEqual(c.user_name, 'jane_other')
user.delete()

def testPreventDuplicateComments(self): def testPreventDuplicateComments(self):
"""Prevent posting the exact same comment twice""" """Prevent posting the exact same comment twice"""
a = Article.objects.get(pk=1) a = Article.objects.get(pk=1)
Expand Down Expand Up @@ -131,7 +148,7 @@ def receive(sender, **kwargs):
# Post a comment and check the signals # Post a comment and check the signals
self.testCreateValidComment() self.testCreateValidComment()
self.assertEqual(received_signals, excepted_signals) self.assertEqual(received_signals, excepted_signals)

def testWillBePostedSignal(self): def testWillBePostedSignal(self):
""" """
Test that the comment_will_be_posted signal can prevent the comment from Test that the comment_will_be_posted signal can prevent the comment from
Expand Down

0 comments on commit 227a93b

Please sign in to comment.