# Path: tabun_api/compat.py
# PY2 = sys.version_info.major == 2


import time
import json
import pytest
import tabun_api as api
from io import BytesIO
from tabun_api.compat import text
from testutil import UserTest, load_file, form_intercept, as_guest, set_mock, user, assert_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


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)


def test_get_posts_types_ok(user):
    posts = reversed(user.get_posts('/'))
    for post in posts:
        assert isinstance(post.author, text)

# Path: tabun_api/compat.py
# PY2 = sys.version_info.major == 2


# Path: test/test_posts.py
import time
import json
import pytest
import tabun_api as api
from io import BytesIO
from tabun_api.compat import text
from testutil import UserTest, load_file, form_intercept, as_guest, set_mock, user, assert_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


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)


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)