forked from rongcloud/server-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
204 lines (164 loc) · 6.34 KB
/
test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#! /usr/bin/env python
# coding=utf-8
import os
import json
import unittest
import logging
from rong import ApiClient
#app_key = ""
#app_secret = ""
#os.environ.setdefault('rongcloud_app_key', app_key)
#os.environ.setdefault('rongcloud_app_secret', app_secret)
logging.basicConfig(level=logging.INFO)
client = ApiClient()
class ApiTest(unittest.TestCase):
def test_token_get(self):
result = client.user_get_token(
'test-userid1',
'test-name1',
'http://www.rongcloud.cn/images/logo.png')
result2 = client.user_get_token(
'test-userid2',
'test-name2',
'http://www.rongcloud.cn/images/logo.png')
self.assertEqual(result[u'code'], 200)
self.assertEqual(result2[u'code'], 200)
self.assertEqual(result[u'userId'], 'test-userid1')
self.assertEqual(result2[u'userId'], 'test-userid2')
self.assertTrue(u"token" in result)
def test_user_refresh(self):
result = client.user_refresh(
'test-userid2',
'test-name2',
'http://www.rongcloud.cn/images/logo_new.png'
)
self.assertEqual(result[u'code'], 200)
def test_user_check_online(self):
result = client.user_check_online(
'test-userid2'
)
self.assertEqual(result[u'code'], 200)
self.assertTrue(u"status" in result)
def test_user_block(self):
result = client.user_block('test-userid1', 10)
self.assertEqual(result[u'code'], 200)
block_user_list = client.user_block_query()
self.assertEqual(block_user_list[u'code'], 200)
self.assertTrue('test-userid1' in [r.get("userId") for r in block_user_list.get("users")])
def test_user_unblock(self):
result = client.user_unblock('test-userid2')
self.assertEqual(result[u'code'], 200)
block_user_list = client.user_block_query()
self.assertEqual(block_user_list[u'code'], 200)
self.assertTrue('test-userid2' not in [r.get("userId") for r in block_user_list.get("users")], "检查解封是否成功")
def test_user_blocklist_add(self):
result = client.user_blocklist_add('test-userid1', ['test-userid2', 'test-userid3'])
self.assertEqual(result[u'code'], 200)
def test_user_blocklist_query(self):
result = client.user_blocklist_query('test-userid1')
self.assertTrue('test-userid2' in result.get('users'))
self.assertTrue('test-userid3' in result.get('users'))
def test_user_blocklist_remove(self):
client.user_blocklist_remove('test-userid1', ['test-userid2', 'test-userid3'])
result = client.user_blocklist_query('test-userid1')
self.assertTrue('test-userid2' not in result.get('users'))
self.assertTrue('test-userid3' not in result.get('users'))
def test_message_publish(self):
result = client.message_publish(
from_user_id='test-userid1',
to_user_id='test-userid2',
object_name='RC:TxtMsg',
content=json.dumps({"content":"hello"}),
push_content='thisisapush',
push_data='aa')
self.assertEqual(result[u'code'], 200)
def test_message_system_publish(self):
result = client.message_system_publish(
from_user_id='test-userid1',
to_user_id='test-userid2',
object_name='RC:TxtMsg',
content=json.dumps({"content":"hello"}),
push_content='thisisapush',
push_data='aa')
self.assertEqual(result[u'code'], 200)
def test_group_create(self):
result = client.group_create(
user_id_list=["test-userid1", "test-userid2"],
group_id="groupid1",
group_name="groupname1"
)
self.assertEqual(result[u'code'], 200)
def test_message_group_publish(self):
result = client.message_group_publish(
from_user_id='test-userid1',
to_group_id="groupid1",
object_name='RC:TxtMsg',
content=json.dumps({"content":"hello"}),
push_content='this is push content',
push_data='this is pushdata'
)
self.assertEqual(result[u'code'], 200)
def test_chatroom_create(self):
result = client.chatroom_create(
chatrooms={
'tr001':'room1',
'tr002':'room2'
}
)
self.assertEqual(result[u'code'], 200)
def test_message_chatroom_publish(self):
result = client.message_chatroom_publish(
from_user_id="test-userid1",
to_chatroom_id="tr001",
object_name="RC:TxtMsg",
content=json.dumps({"content":"hello"})
)
self.assertEqual(result[u'code'], 200)
def test_message_history(self):
result = client.message_history(
date=2014010101
)
self.assertEqual(result[u'code'], 200)
self.assertTrue(u'url' in result)
def test_group_sync(self):
result = client.group_sync(
user_id='test-userid1',
groups={
"groupid1":"groupname1"
}
)
self.assertEqual(result[u'code'], 200)
def test_group_join(self):
result = client.group_join(
user_id_list=['test-userid1', 'test-userid2'],
group_id="groupid1",
group_name="groupname1"
)
self.assertEqual(result[u'code'], 200)
def test_group_quit(self):
result = client.group_quit(
user_id_list=['test-userid1', 'test-userid2'],
group_id="groupid1"
)
self.assertEqual(result[u'code'], 200)
def test_group_refresh(self):
result = client.group_refresh(
group_id="groupid1",
group_name="groupname1"
)
self.assertEqual(result[u'code'], 200)
def test_group_dismiss(self):
result = client.group_dismiss(
user_id='test-userid1',
group_id="groupid1")
self.assertEqual(result[u'code'], 200)
def test_chatroom_query(self):
result = client.chatroom_query(["tr001","tr002"])
self.assertEqual(result[u'code'], 200)
def test_chatroom_destroy(self):
result = client.chatroom_destroy(
chatroom_id_list=["tr001", "tr002"]
)
self.assertEqual(result[u'code'], 200)
if __name__ == "__main__":
unittest.main()