Skip to content

Commit

Permalink
Add missing WeChat group test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Feb 10, 2015
1 parent e900f3f commit 6eabc27
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
29 changes: 29 additions & 0 deletions tests/fixtures/groups_get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"groups": [
{
"id": 0,
"name": "未分组",
"count": 72596
},
{
"id": 1,
"name": "黑名单",
"count": 36
},
{
"id": 2,
"name": "星标组",
"count": 8
},
{
"id": 104,
"name": "华东媒",
"count": 4
},
{
"id": 106,
"name": "★不测试组★",
"count": 1
}
]
}
3 changes: 3 additions & 0 deletions tests/fixtures/groups_getid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"groupid": 102
}
4 changes: 4 additions & 0 deletions tests/fixtures/groups_members_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
4 changes: 4 additions & 0 deletions tests/fixtures/groups_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
20 changes: 20 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ def test_create_group(self):
self.assertEqual(1, group['group']['id'])
self.assertEqual('test', group['group']['name'])

def test_group_get(self):
with HTTMock(wechat_api_mock):
groups = self.client.group.get()
self.assertEqual(5, len(groups))

def test_group_getid(self):
with HTTMock(wechat_api_mock):
group = self.client.group.get('123456')
self.assertEqual(102, group)

def test_group_update(self):
with HTTMock(wechat_api_mock):
result = self.client.group.update(102, 'test')
self.assertEqual(0, result['errcode'])

def test_group_move_user(self):
with HTTMock(wechat_api_mock):
result = self.client.group.move_user('test', 102)
self.assertEqual(0, result['errcode'])

def test_send_text_message(self):
with HTTMock(wechat_api_mock):
result = self.client.message.send_text(1, 'test')
Expand Down
10 changes: 6 additions & 4 deletions wechatpy/client/api/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ def create(self, name):

def get(self, user_id=None):
"""
查询所有分组或查询用户所在分组
查询所有分组或查询用户所在分组 ID
详情请参考
http://mp.weixin.qq.com/wiki/13/be5272dc4930300ba561d927aead2569.html
:param user_id: 用户 ID,提供时查询该用户所在分组,否则查询所有分组
:return: 返回的 JSON 数据包
:return: 所有分组列表或用户所在分组 ID
"""
if user_id is None:
return self._get('groups/get')
res = self._get('groups/get')
return res['groups']
else:
return self._post(
res = self._post(
'groups/getid',
data={'openid': user_id}
)
return res['groupid']

def update(self, group_id, name):
"""
Expand Down

0 comments on commit 6eabc27

Please sign in to comment.