Exemple #1
0
def test_add_comment_ok(form_intercept, set_mock, user):
    set_mock({'/blog/ajaxaddcomment/': (None, {'data': b'{"sCommentId": 1, "sMsgTitle": "", "sMsg": "", "bStateError": false}'})})
    @form_intercept('/blog/ajaxaddcomment/')
    def add_comment(data, headers):
        assert headers.get('content-type', '').startswith(b'multipart/form-data; boundary=-')

        assert data.get('security_ls_key') == [b'0123456789abcdef0123456789abcdef']
        assert data.get('cmt_target_id') in ([b'1'], [b'2'])
        assert data.get('comment_text') == ['тест'.encode('utf-8')]
        assert data.get('reply') == ([b'0'] if data['cmt_target_id'][0] == b'1' else [b'1'])

    assert user.comment(1, 'тест') == 1
    assert user.comment(1, 'тест', reply=0) == 1
Exemple #2
0
def test_add_comment_fail(set_mock, user):
    err = "Текст комментария должен быть от 2 до 3000 символов и не содержать разного рода каку"
    set_mock({'/blog/ajaxaddcomment/': (None, {'data': ('{"sMsgTitle": "Ошибка", "sMsg": "%s", "bStateError": true}' % err).encode('utf-8')})})
    with pytest.raises(api.TabunResultError) as excinfo:
        user.comment(1, '')
    assert excinfo.value.message == err