From 790715d37b1247a606437392a65711187885b34a Mon Sep 17 00:00:00 2001 From: Jacob Mason Date: Thu, 5 Aug 2010 12:20:15 -0500 Subject: [PATCH] added update_username method --- sphinx/websupport/__init__.py | 13 +++++++++++++ tests/test_websupport.py | 22 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/sphinx/websupport/__init__.py b/sphinx/websupport/__init__.py index 03b9c8e8b..f137ce2c3 100644 --- a/sphinx/websupport/__init__.py +++ b/sphinx/websupport/__init__.py @@ -268,3 +268,16 @@ class WebSupport(object): if not -1 <= value <= 1: raise ValueError('vote value %s out of range (-1, 1)' % value) self.storage.process_vote(comment_id, username, value) + + def update_username(self, old_username, new_username): + """To remain decoupled from a webapp's authentication system, the + web support package stores a user's username with each of their + comments and votes. If the authentication system allows a user to + change their username, this can lead to stagnate data in the web + support system. To avoid this, each time a username is changed, this + method should be called. + + :param old_username: The original username. + :param new_username: The new username. + """ + self.storage.update_username(old_username, new_username) diff --git a/tests/test_websupport.py b/tests/test_websupport.py index ca64ec2d1..d0956916d 100644 --- a/tests/test_websupport.py +++ b/tests/test_websupport.py @@ -16,7 +16,7 @@ from sphinx.websupport import WebSupport from sphinx.websupport.errors import * from sphinx.websupport.storage.differ import CombinedHtmlDiff from sphinx.websupport.storage.sqlalchemystorage import Session, \ - SQLAlchemyStorage + SQLAlchemyStorage, Comment, CommentVote from sphinx.websupport.storage.db import Node from util import * @@ -90,7 +90,8 @@ def test_comments(support): parent_id=str(comment['id']), displayed=False) # Add a comment to another node to make sure it isn't returned later. support.add_comment('Second test comment', - node_id=str(second_node.id)) + node_id=str(second_node.id), + username='user_two') # Access the comments as a moderator. data = support.get_data(str(first_node.id), moderator=True) @@ -193,6 +194,23 @@ def test_moderator_delete_comments(support): assert comment['username'] == '[deleted]' assert comment['text'] == '[deleted]' +@with_support() +def test_update_username(support): + support.update_username('user_two', 'new_user_two') + session = Session() + comments = session.query(Comment).\ + filter(Comment.username == 'user_two').all() + assert len(comments) == 0 + votes = session.query(CommentVote).\ + filter(CommentVote.username == 'user_two') + assert len(comments) == 0 + comments = session.query(Comment).\ + filter(Comment.username == 'new_user_two').all() + assert len(comments) == 1 + votes = session.query(CommentVote).\ + filter(CommentVote.username == 'new_user_two') + assert len(comments) == 1 + def test_differ(): differ = CombinedHtmlDiff()