Skip to content

Commit

Permalink
增加企业微信邮箱接口 (#711)
Browse files Browse the repository at this point in the history
* 增加企业邮箱群组接口
* 增加邮箱接口
* 重命名变量
* 添加单元测试
* 重命名

Co-authored-by: yaoqiankun <yaoqiankun@datarc.cn>
  • Loading branch information
yqkcn and yaoqiankun committed Mar 20, 2022
1 parent 8ad2268 commit fdc4688
Show file tree
Hide file tree
Showing 18 changed files with 628 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/fixtures/work/exmail_account_act_email.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/work/exmail_group_create.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/work/exmail_group_delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
28 changes: 28 additions & 0 deletions tests/fixtures/work/exmail_group_get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"errcode": 0,
"errmsg": "ok",
"groupid": "zhangsangroup@gzdev.com",
"groupname": "zhangsangroup",
"email_list": {
"list": ["lisi@gzdev.com", "wangwu@gzdev.com"]
},
"tag_list": {
"list": [2, 5]
},
"department_list": {
"list": [1, 2]
},
"group_list": {
"list": ["aaa@gzdev.com"]
},
"allow_type": 3,
"allow_emaillist": {
"list": ["zhangsanp@gzdev.com"]
},
"allow_departmentlist": {
"list": [1, 2]
},
"allow_taglist": {
"list": [1, 3]
}
}
15 changes: 15 additions & 0 deletions tests/fixtures/work/exmail_group_search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"errcode": 0,
"errmsg": "ok",
"count": 2,
"groups": [
{
"groupid": "zhangsan@gzdev.com",
"groupname": "张三"
},
{
"groupid": "lisi@gzdev.com",
"groupname": "李四"
}
]
}
4 changes: 4 additions & 0 deletions tests/fixtures/work/exmail_group_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
5 changes: 5 additions & 0 deletions tests/fixtures/work/exmail_mail_get_newcount.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"errcode": 0,
"errmsg": "ok",
"count": 100
}
5 changes: 5 additions & 0 deletions tests/fixtures/work/exmail_publicmail_create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"errcode": 0,
"errmsg": "ok",
"id": 100
}
4 changes: 4 additions & 0 deletions tests/fixtures/work/exmail_publicmail_delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
27 changes: 27 additions & 0 deletions tests/fixtures/work/exmail_publicmail_get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"errcode": 0,
"errmsg": "ok",
"list": [{
"id": 1,
"email": "apitest3@gzdev.com",
"name": "测试",
"userid_list": {
"list": [
"member",
"member2"
]
},
"department_list": {
"list": [
1,
2
]
},
"tag_list": {
"list": [
1,
2
]
}
}]
}
16 changes: 16 additions & 0 deletions tests/fixtures/work/exmail_publicmail_search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"errcode": 0,
"errmsg": "ok",
"list": [
{
"id": 11,
"email": "apitest3@gzdev.com",
"name": "apitest3"
},
{
"id": 12,
"email": "apitest4@gzdev.com",
"name": "apitest4"
}
]
}
4 changes: 4 additions & 0 deletions tests/fixtures/work/exmail_publicmail_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
16 changes: 16 additions & 0 deletions tests/fixtures/work/exmail_useroption_get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"errcode": 0,
"errmsg": "ok",
"option": {
"list": [{
"type": 1,
"value": "0"
}, {
"type": 2,
"value": "1"
}, {
"type": 3,
"value": "0"
}]
}
}
4 changes: 4 additions & 0 deletions tests/fixtures/work/exmail_useroption_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errcode": 0,
"errmsg": "ok"
}
85 changes: 85 additions & 0 deletions tests/test_work_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,88 @@ def test_invoice_update_status_batch_with_empty_invoice_list(self):
reimburse_status=reimburse_status,
invoice_list=invoice_list,
)

def test_create_email_group(self):
with HTTMock(wechat_api_mock):
res = self.client.email.create_group(1, "1", email_list=[1])
self.assertEqual(0, res["errcode"])

def test_update_email_group(self):
with HTTMock(wechat_api_mock):
res = self.client.email.update_group(1, "1", email_list=[1])
self.assertEqual(0, res["errcode"])

def test_delete_email_group(self):
with HTTMock(wechat_api_mock):
res = self.client.email.delete_group(1)
self.assertEqual(0, res["errcode"])

def test_get_email_group(self):
with HTTMock(wechat_api_mock):
res = self.client.email.get_group(1)
self.assertEqual(0, res["errcode"])
self.assertEqual("zhangsangroup@gzdev.com", res["groupid"])
self.assertEqual("zhangsangroup", res["groupname"])

def test_search_email_group(self):
with HTTMock(wechat_api_mock):
res = self.client.email.search_group(1)
self.assertEqual("zhangsan@gzdev.com", res[0]["groupid"])
self.assertEqual("张三", res[0]["groupname"])
self.assertEqual("lisi@gzdev.com", res[1]["groupid"])
self.assertEqual("李四", res[1]["groupname"])

def test_create_public_email(self):
with HTTMock(wechat_api_mock):
res = self.client.email.create_public_email("1@1", "1")
self.assertEqual(100, res)

def test_update_public_email(self):
with HTTMock(wechat_api_mock):
res = self.client.email.update_public_email("1@1", "1")
self.assertEqual(0, res["errcode"])

def test_delete_public_email(self):
with HTTMock(wechat_api_mock):
res = self.client.email.delete_public_email("1@1")
self.assertEqual(0, res["errcode"])

def test_get_public_email(self):
with HTTMock(wechat_api_mock):
res = self.client.email.get_public_email("1@1")
self.assertEqual("apitest3@gzdev.com", res["email"])

def test_batch_get_public_email(self):
with HTTMock(wechat_api_mock):
res = self.client.email.batch_get_public_email(["1@1"])
self.assertEqual("apitest3@gzdev.com", res[0]["email"])

def test_search_public_email(self):
with HTTMock(wechat_api_mock):
res = self.client.email.search_public_email("1@1")
self.assertEqual("apitest3@gzdev.com", res[0]["email"])
self.assertEqual("apitest4@gzdev.com", res[1]["email"])

def test_active_email(self):
with HTTMock(wechat_api_mock):
res = self.client.email.active_email("1")
self.assertEqual(0, res["errcode"])

res = self.client.email.inactive_email("1")
self.assertEqual(0, res["errcode"])

def test_get_user_option(self):
with HTTMock(wechat_api_mock):
res = self.client.email.get_user_option(1, [1])
self.assertEqual(1, res[0]["type"])
self.assertEqual("0", res[0]["value"])

def test_update_user_option(self):
with HTTMock(wechat_api_mock):
res = self.client.email.update_user_option(1, {})
self.assertEqual(0, res["errcode"])

def get_new_email_count(self):
with HTTMock(wechat_api_mock):
res = self.client.email.get_new_email_count(1)
self.assertEqual(100, res)
1 change: 1 addition & 0 deletions wechatpy/work/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class WeChatClient(BaseWeChatClient):
batch = api.WeChatBatch()
calendar = api.WeChatCalendar()
department = api.WeChatDepartment()
email = api.WeChatEMail()
external_contact = api.WeChatExternalContact()
external_contact_group_chat = api.WeChatExternalContactGroupChat()
jsapi = api.WeChatJSAPI()
Expand Down
1 change: 1 addition & 0 deletions wechatpy/work/client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from wechatpy.work.client.api.batch import WeChatBatch # NOQA
from wechatpy.work.client.api.calendar import WeChatCalendar # NOQA
from wechatpy.work.client.api.department import WeChatDepartment # NOQA
from wechatpy.work.client.api.email import WeChatEMail # NOQA
from wechatpy.work.client.api.external_contact import WeChatExternalContact # NOQA
from wechatpy.work.client.api.external_contact_group_chat import WeChatExternalContactGroupChat
from wechatpy.work.client.api.invoice import WeChatInvoice # NOQA
Expand Down

0 comments on commit fdc4688

Please sign in to comment.