Ejemplo n.º 1
0
def test_get_more_activity(user, set_mock):
    answer = '{"iStreamLastId":"15000","result":%DATA%,"events_count":11,"sMsgTitle":"","sMsg":"","bStateError":false}'
    answer = answer.replace('%DATA%', json.dumps(load_file('activity_items.html', template=False).decode('utf-8')))

    set_mock(
        {
            '/stream/get_more_all/': (None, {
                'data': answer.encode('utf-8'),
                'headers': {'Content-Type': 'application/json'},
            })
        }
    )

    items_data = json.loads(load_file('activity_items.json', template=False).decode('utf-8'))

    last_id, items = user.get_more_activity()
    assert last_id == 15000

    # assert len(items) == len(items_data)
    for data, item in zip(items_data, items):
        for key, value in data.items():
            if key == "date":
                assert time.strftime("%Y-%m-%d %H:%M", item.date) == value
            else:
                assert getattr(item, key) == value
Ejemplo n.º 2
0
def tmpl(args):
    if '--guest' in args:
        guest = True
        args.remove('--guest')
    else:
        guest = False

    if '--raw' in args:
        raw = True
        args.remove('--raw')
    else:
        raw = False
    if not args or not args[0]:
        print_help()
        return

    if guest:
        testutil.guest_mode = True

    data = testutil.load_file(args[0]).decode('utf-8')

    if not raw:
        data = data.replace('src="//', 'src="https://')
        data = data.replace('href="//', 'href="https://')

    print(data)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def test_get_activity_tabun(user):
    items_data = json.loads(load_file('activity_items.json', template=False).decode('utf-8'))

    last_id, items = user.get_activity()
    assert last_id == 15000

    # assert len(items) == len(items_data)
    for data, item in zip(items_data, items):
        for key, value in data.items():
            if key == "date":
                assert time.strftime("%Y-%m-%d %H:%M", item.date) == value
            else:
                assert getattr(item, key) == value
Ejemplo n.º 8
0
def test_get_activity_livestreet(user, set_mock):
    set_mock({'/stream/all/': 'activity_ls.html'})
    items_data = json.loads(load_file('activity_items.json', template=False).decode('utf-8'))

    last_id, items = user.get_activity()
    assert last_id == 15000

    # assert len(items) == len(items_data)
    for data, item in zip(items_data, items):
        for key, value in data.items():
            if key == "date":
                assert time.strftime("%Y-%m-%d %H:%M", item.date) == value
            else:
                assert getattr(item, key) == value
Ejemplo n.º 9
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
Ejemplo n.º 10
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