mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
added update_username method
This commit is contained in:
parent
69a2c07396
commit
790715d37b
@ -268,3 +268,16 @@ class WebSupport(object):
|
|||||||
if not -1 <= value <= 1:
|
if not -1 <= value <= 1:
|
||||||
raise ValueError('vote value %s out of range (-1, 1)' % value)
|
raise ValueError('vote value %s out of range (-1, 1)' % value)
|
||||||
self.storage.process_vote(comment_id, username, 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)
|
||||||
|
@ -16,7 +16,7 @@ from sphinx.websupport import WebSupport
|
|||||||
from sphinx.websupport.errors import *
|
from sphinx.websupport.errors import *
|
||||||
from sphinx.websupport.storage.differ import CombinedHtmlDiff
|
from sphinx.websupport.storage.differ import CombinedHtmlDiff
|
||||||
from sphinx.websupport.storage.sqlalchemystorage import Session, \
|
from sphinx.websupport.storage.sqlalchemystorage import Session, \
|
||||||
SQLAlchemyStorage
|
SQLAlchemyStorage, Comment, CommentVote
|
||||||
from sphinx.websupport.storage.db import Node
|
from sphinx.websupport.storage.db import Node
|
||||||
from util import *
|
from util import *
|
||||||
|
|
||||||
@ -90,7 +90,8 @@ def test_comments(support):
|
|||||||
parent_id=str(comment['id']), displayed=False)
|
parent_id=str(comment['id']), displayed=False)
|
||||||
# Add a comment to another node to make sure it isn't returned later.
|
# Add a comment to another node to make sure it isn't returned later.
|
||||||
support.add_comment('Second test comment',
|
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.
|
# Access the comments as a moderator.
|
||||||
data = support.get_data(str(first_node.id), moderator=True)
|
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['username'] == '[deleted]'
|
||||||
assert comment['text'] == '[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():
|
def test_differ():
|
||||||
differ = CombinedHtmlDiff()
|
differ = CombinedHtmlDiff()
|
||||||
|
Loading…
Reference in New Issue
Block a user