當前位置: 首頁>>代碼示例>>Python>>正文


Python sqlalchemystorage.Session類代碼示例

本文整理匯總了Python中sphinx.websupport.storage.sqlalchemystorage.Session的典型用法代碼示例。如果您正苦於以下問題:Python Session類的具體用法?Python Session怎麽用?Python Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Session類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_voting

def test_voting(support):
    session = Session()
    nodes = session.query(Node).all()
    node = nodes[0]

    comment = support.get_data(node.id)['comments'][0]

    def check_rating(val):
        data = support.get_data(node.id)
        comment = data['comments'][0]
        assert comment['rating'] == val, '%s != %s' % (comment['rating'], val)

    support.process_vote(comment['id'], 'user_one', '1')
    support.process_vote(comment['id'], 'user_two', '1')
    support.process_vote(comment['id'], 'user_three', '1')
    check_rating(3)
    support.process_vote(comment['id'], 'user_one', '-1')
    check_rating(1)
    support.process_vote(comment['id'], 'user_one', '0')
    check_rating(2)

    # Make sure a vote with value > 1 or < -1 can't be cast.
    with pytest.raises(ValueError):
        support.process_vote(comment['id'], 'user_one', '2')
    with pytest.raises(ValueError):
        support.process_vote(comment['id'], 'user_one', '-2')

    # Make sure past voting data is associated with comments when they are
    # fetched.
    data = support.get_data(str(node.id), username='user_two')
    comment = data['comments'][0]
    assert comment['vote'] == 1, '%s != 1' % comment['vote']
開發者ID:nwf,項目名稱:sphinx,代碼行數:32,代碼來源:test_websupport.py

示例2: test_proposals

def test_proposals(support):
    session = Session()
    node = session.query(Node).first()

    data = support.get_data(node.id)

    source = data['source']
    proposal = source[:5] + source[10:15] + 'asdf' + source[15:]

    support.add_comment('Proposal comment',
                        node_id=node.id,
                        proposal=proposal)
開發者ID:nwf,項目名稱:sphinx,代碼行數:12,代碼來源:test_websupport.py

示例3: test_update_username

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').all()
    assert len(votes) == 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').all()
    assert len(votes) == 0
開發者ID:nwf,項目名稱:sphinx,代碼行數:15,代碼來源:test_websupport.py

示例4: test_comments

def test_comments(support):
    session = Session()
    nodes = session.query(Node).all()
    first_node = nodes[0]
    second_node = nodes[1]

    # Create a displayed comment and a non displayed comment.
    comment = support.add_comment('First test comment',
                                  node_id=first_node.id,
                                  username='user_one')
    hidden_comment = support.add_comment('Hidden comment',
                                         node_id=first_node.id,
                                         displayed=False)
    # Make sure that comments can't be added to a comment where
    # displayed == False, since it could break the algorithm that
    # converts a nodes comments to a tree.
    with pytest.raises(CommentNotAllowedError):
        support.add_comment('Not allowed', parent_id=str(hidden_comment['id']))
    # Add a displayed and not displayed child to the displayed comment.
    support.add_comment('Child test comment', parent_id=str(comment['id']),
                        username='user_one')
    support.add_comment('Hidden child test comment',
                        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=second_node.id,
                        username='user_two')

    # Access the comments as a moderator.
    data = support.get_data(first_node.id, moderator=True)
    comments = data['comments']
    children = comments[0]['children']
    assert len(comments) == 2
    assert comments[1]['text'] == '<p>Hidden comment</p>\n'
    assert len(children) == 2
    assert children[1]['text'] == '<p>Hidden child test comment</p>\n'

    # Access the comments without being a moderator.
    data = support.get_data(first_node.id)
    comments = data['comments']
    children = comments[0]['children']
    assert len(comments) == 1
    assert comments[0]['text'] == '<p>First test comment</p>\n'
    assert len(children) == 1
    assert children[0]['text'] == '<p>Child test comment</p>\n'
開發者ID:nwf,項目名稱:sphinx,代碼行數:45,代碼來源:test_websupport.py

示例5: test_moderation

def test_moderation(support):
    session = Session()
    nodes = session.query(Node).all()
    node = nodes[7]
    session.close()
    accepted = support.add_comment('Accepted Comment', node_id=node.id,
                                   displayed=False)
    deleted  = support.add_comment('Comment to delete', node_id=node.id,
                                   displayed=False)
    # Make sure the moderation_callback is called.
    assert called
    # Make sure the user must be a moderator.
    raises(UserNotAuthorizedError, support.accept_comment, accepted['id'])
    raises(UserNotAuthorizedError, support.delete_comment, deleted['id'])
    support.accept_comment(accepted['id'], moderator=True)
    support.delete_comment(deleted['id'], moderator=True)
    comments = support.get_data(node.id)['comments']
    assert len(comments) == 1
    comments = support.get_data(node.id, moderator=True)['comments']
    assert len(comments) == 1
開發者ID:AlexEshoo,項目名稱:sphinx,代碼行數:20,代碼來源:test_websupport.py

示例6: get_comment

 def get_comment():
     session = Session()
     node = session.query(Node).first()
     session.close()
     return support.get_data(node.id, moderator=True)['comments'][1]
開發者ID:nwf,項目名稱:sphinx,代碼行數:5,代碼來源:test_websupport.py


注:本文中的sphinx.websupport.storage.sqlalchemystorage.Session類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。