forked from notedit/motiky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_comment.py
68 lines (47 loc) · 1.99 KB
/
test_comment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
import os
import sys
import types
import json
import time
from datetime import datetime
from datetime import timedelta
from StringIO import StringIO
from tests import TestCase
from motiky.logic.models import User,Post,UserLikeAsso,Report,Install,\
UserFollowAsso,Comment,Activity,Action
from motiky.logic import backend
from motiky.configs import db,redis
class TestComment(TestCase):
def test_comment_view(self):
# post
user1 = backend.add_user('username01','photo_url01','weibo_id01')
headers = self.generate_header('weibo_id01')
post1 = backend.add_post('post01',user1['id'],
'video_url','pic_small1')
data = {
'author_id':user1['id'],
'content':'comment01',
'post_id':post1['id']
}
resp = self.client.post('/comment',data=json.dumps(data),headers=headers,
content_type='application/json')
_data = json.loads(resp.data)
assert resp.status_code == 200
assert _data['content'] == 'comment01'
# delete
resp = self.client.delete('/comment/%d'%_data['id'],
headers=headers,content_type='application/json')
print resp.data
assert resp.status_code == 204
def test_post_comment_view(self):
user1 = backend.add_user('username01','photo_url01','weibo_id01')
post1 = backend.add_post('post01',user1['id'],
'video_url','pic_small1')
comment1 = backend.add_comment(post1['id'],'comment1',user1['id'])
comment2 = backend.add_comment(post1['id'],'comment2',user1['id'])
comment3 = backend.add_comment(post1['id'],'comment3',user1['id'])
headers = self.generate_header('weibo_id01')
resp = self.client.get('/post/%d/comment' % post1['id'],headers=headers)
data_get = json.loads(resp.data)
assert len(data_get['comments']) == 3