Esempio n. 1
0
def test_get_posts_data_ok(user):
    post_data = json.loads(load_file('index_posts.json', template=False).decode('utf-8'))
    posts = list(reversed(user.get_posts('/')))

    assert len(posts) == len(post_data)
    for data, post in zip(post_data, posts):
        assert post.post_id == data['post_id']
        assert_data(post, data)
Esempio n. 2
0
def test_get_posts_profile_data_ok(user, set_mock):
    set_mock({'/profile/test/created/topics/': 'profile_topics.html'})

    post_data = json.loads(load_file('profile_topics.json', template=False).decode('utf-8'))
    posts = list(reversed(user.get_posts('/profile/test/created/topics/')))

    assert len(posts) == len(post_data)
    for data, post in zip(post_data, posts):
        assert post.post_id == data['post_id']
        assert_data(post, data)
Esempio n. 3
0
def test_get_posts_types_ok(user):
    posts = reversed(user.get_posts('/'))
    for post in posts:
        assert isinstance(post.author, text)
        assert post.blog is None or isinstance(post.blog, text)
        assert isinstance(post.blog_name, text)
        assert isinstance(post.title, text)
        assert isinstance(post.raw_body, text)
        assert isinstance(post.tags[0], text)
        assert isinstance(post.comments_count, int)
        assert isinstance(post.comments_new_count, int)
Esempio n. 4
0
def test_get_posts_data_ok(user):
    post_data = json.loads(load_file('index_posts.json', template=False).decode('utf-8'))
    posts = reversed(user.get_posts('/'))

    for data, post in zip(post_data, posts):
        assert post.post_id == data['post_id']

        for key, value in data.items():
            if key == 'time':
                assert time.strftime("%Y-%m-%d %H:%M:%S", post.time) == value
            elif key != "post_id":
                assert getattr(post, key) == value
Esempio n. 5
0
def test_get_posts_context_guest_ok(user, as_guest):
    posts = reversed(user.get_posts('/'))
    for post in posts:
        c = post.context
        assert isinstance(c['username'], type(None))
        assert isinstance(c['http_host'], text)
        assert isinstance(c['url'], text)
        assert isinstance(c['can_comment'], type(None))  # not available no lists
        assert isinstance(c['can_edit'], bool)
        assert isinstance(c['can_delete'], bool)
        assert isinstance(c['can_vote'], bool)
        assert isinstance(c['vote_value'], (int, type(None)))  # None is not voted
        assert isinstance(c['favourited'], bool)
        assert isinstance(c['subscribed_to_comments'], type(None))  # not available on lists
        assert isinstance(c['unread_comments_count'], int)
Esempio n. 6
0
def test_get_posts_data_ok_without_escape(user):
    def noescape(data, may_be_short=False):
        return data

    old_escape = api.utils.escape_topic_contents
    api.utils.escape_topic_contents = noescape
    try:
        post_data = json.loads(load_file('index_posts.json', template=False).decode('utf-8'))
        posts = list(reversed(user.get_posts('/')))

        assert len(posts) == len(post_data)
        for data, post in zip(post_data, posts):
            assert post.post_id == data['post_id']
            assert_data(post, data)
    finally:
        api.utils.escape_topic_contents = old_escape
Esempio n. 7
0
def test_post_hashsum_part(user):
    p = user.get_posts('/')
    assert p[0].post_id == 100000
    assert p[0].hashsum(('title', 'body', 'tags')) == 'efeff4792ac7666c280b06d6d0ae1136'
    assert p[1].post_id == 131909
    assert p[1].hashsum(('title', 'body', 'tags')) == 'dacf2a4631636a1ab796681d607c11e0'
    assert p[2].post_id == 131911
    assert p[2].hashsum(('title', 'body', 'tags')) == '1381908ebf93038617b400f59d97646a'
    assert p[3].post_id == 131915
    assert p[3].hashsum(('title', 'body', 'tags')) == '9fbca162a43f2a2b1dff8c5764864fdf'
    assert p[4].post_id == 131904
    assert p[4].hashsum(('title', 'body', 'tags')) == '61a43c4d0f33313bfb4926fb86560450'
    assert p[5].post_id == 131937
    assert p[5].hashsum(('title', 'body', 'tags')) == 'a49976cb3879a540334a3e93f57a752e'

    # Потому что смешивать \n и \r\n в файлах так же, как и на сайте, очень геморройно
    p[0].raw_body = p[0].raw_body.replace('\n', '\r\n')
    assert p[0].hashsum(('title', 'body', 'tags')) == '1364ee5a2fee913325d3b220d43623a5'
Esempio n. 8
0
def test_post_hashsum_default(user):
    p = user.get_posts('/')
    oldver_fields = ('post_id', 'time', 'draft', 'author', 'blog', 'title', 'body', 'tags')
    assert p[0].post_id == 100000
    assert p[0].hashsum(oldver_fields) == 'e93efead3145c59b9aac26037b9c5fcf'
    assert p[1].post_id == 131909
    assert p[1].hashsum(oldver_fields) == 'b6147c9ba6dbc7e8e07db958390108bd'
    assert p[2].post_id == 131911
    assert p[2].hashsum(oldver_fields) == '33b7a175c45eea8e5f68f4bc885f324b'
    assert p[3].post_id == 131915
    assert p[3].hashsum(oldver_fields) == '51b480ee57ee3166750e4f15f6a48f1f'
    assert p[4].post_id == 131904
    assert p[4].hashsum(oldver_fields) == 'd28e3ff695cd4cdc1f63e5919da95516'
    assert p[5].post_id == 131937
    assert p[5].hashsum(oldver_fields) == '93ef694d929b03b2f48b702ef68ce77b'

    assert p[0].hashsum() == '2f452e09ee106a2beeb5a48927ad72b3'
    assert p[1].hashsum() == '5308ccc03831ea4f4f3f3661440fcc75'
    assert p[2].hashsum() == 'fb329febe4d073359b1d974098557994'
    assert p[3].hashsum() == 'bed41b4d1ab3fa5b6b340f186067d6d5'
    assert p[4].hashsum() == '2c49d10769e1fb28cb78cfaf8ac6cd0e'
    assert p[5].hashsum() == '6c35ba542fd4f65ab9aac97943ca6672'