示例#1
0
def test_get_comments(user, url, data_file, rev):
    comments_data = json.loads(load_file(data_file, template=False).decode('utf-8'))
    if url:
        comments = user.get_comments(url)
    else:
        comments = user.get_comments()

    assert list(sorted(comments.keys(), reverse=rev)) == [x['comment_id'] for x in comments_data]

    for data in comments_data:
        comment = comments[data['comment_id']]
        assert data['comment_id'] == comment.comment_id
        assert_data(comment, data)
示例#2
0
def test_get_comments_types_ok(user):
    comments = user.get_comments()
    comments.update(user.get_comments('/blog/132085.html'))
    for comment_id, comment in comments.items():
        assert isinstance(comment_id, int)
        assert comment.blog is None or isinstance(comment.blog, text)
        if comment.deleted:
            assert comment.author is None
            assert comment.raw_body is None
            assert comment.vote_total is None
        else:
            assert isinstance(comment.author, text)
            assert isinstance(comment.raw_body, text)
            assert isinstance(comment.vote_total, int)
示例#3
0
def test_get_comments(user, url, data_file, rev):
    comments_data = json.loads(load_file(data_file, template=False).decode('utf-8'))
    if url:
        comments = user.get_comments(url)
    else:
        comments = user.get_comments()

    assert list(sorted(comments.keys(), reverse=rev)) == [x['comment_id'] for x in comments_data]

    for data in comments_data:
        comment = comments[data['comment_id']]
        assert data['comment_id'] == comment.comment_id

        for key, value in data.items():
            if key == 'time' and value is not None:
                assert time.strftime("%Y-%m-%d %H:%M:%S", comment.time) == value
            elif key != "comment_id":
                assert getattr(comment, key) == value
示例#4
0
def test_comments_hashsum_part(user):
    c = list(sorted(user.get_comments().items()))
    assert c[0][0] == 9445361
    assert c[0][1].hashsum(('body',)) == '5768f420c77973975c835ba44e8bd285'
    assert c[1][0] == 9445595
    assert c[1][1].hashsum(('body',)) == 'be8d648dd8bb53a957b0bd861dfb548f'

    # Потому что смешивать \n и \r\n в файлах так же, как и на сайте, очень геморройно
    c[1][1].raw_body = c[1][1].raw_body.replace('\n', '\r\n')
    assert c[1][1].hashsum(('body',)) == '10b2ae8cd48a8e9bc86bf5138ebfa18d'
示例#5
0
def test_comments_hashsum_default(user):
    c = list(sorted(user.get_comments().items()))
    assert c[0][0] == 9445361
    assert c[0][1].hashsum() == '21e86981a1eb1110c55f8f59c6b7e684'
    assert c[1][0] == 9445595
    assert c[1][1].hashsum() == 'c8c7a9621120fc5f9f1f10caa2941ec0'