forked from erp-dev/erp
fix: appversions
This commit is contained in:
@@ -555,6 +555,68 @@ class NotifierServiceTestCase(TestCase):
|
||||
notifier=notifier,
|
||||
payload={"mission_id": 12},
|
||||
)
|
||||
|
||||
@patch("notifier.backends.send_jpush_payload")
|
||||
def test_send_notification_with_notifier_uses_jpush_backend(self, mock_send):
|
||||
mock_send.return_value.raw = {"sendno": "123", "msg_id": "456"}
|
||||
|
||||
notifier = Notifier.objects.create(
|
||||
merchant=self.merchant,
|
||||
name="任务创建极光推送",
|
||||
channel=NotifierChannelEnum.JPUSH,
|
||||
template_key="mission_created_jpush",
|
||||
config={
|
||||
"app_key": "app-key-1",
|
||||
"master_secret": "master-secret-1",
|
||||
"alias_prefix": "emp_",
|
||||
"recipient_source": "participants",
|
||||
"platform": "all",
|
||||
"apns_production": True,
|
||||
"android_channel_id": "mission",
|
||||
},
|
||||
)
|
||||
|
||||
result = send_notification_with_notifier(
|
||||
notifier=notifier,
|
||||
payload={
|
||||
"mission_id": 12,
|
||||
"merchant_id": self.merchant.id,
|
||||
"description": "检查打印质量",
|
||||
"participant_ids": [21, 22, 21],
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(result["status"], "sent")
|
||||
self.assertEqual(result["channel"], NotifierChannelEnum.JPUSH)
|
||||
self.assertEqual(result["aliases"], ["emp_21", "emp_22"])
|
||||
mock_send.assert_called_once()
|
||||
self.assertEqual(mock_send.call_args.kwargs["app_key"], "app-key-1")
|
||||
self.assertEqual(mock_send.call_args.kwargs["master_secret"], "master-secret-1")
|
||||
payload = mock_send.call_args.kwargs["payload"]
|
||||
self.assertEqual(payload["audience"], {"alias": ["emp_21", "emp_22"]})
|
||||
self.assertEqual(payload["notification"]["android"]["channel_id"], "mission")
|
||||
self.assertEqual(payload["notification"]["ios"]["sound"], "default")
|
||||
self.assertTrue(payload["options"]["apns_production"])
|
||||
self.assertEqual(payload["notification"]["android"]["extras"]["mission_id"], "12")
|
||||
|
||||
@patch("notifier.backends.send_jpush_payload")
|
||||
def test_send_notification_with_notifier_rejects_jpush_without_aliases(self, mock_send):
|
||||
notifier = Notifier.objects.create(
|
||||
merchant=self.merchant,
|
||||
name="无接收人极光推送",
|
||||
channel=NotifierChannelEnum.JPUSH,
|
||||
template_key="mission_created_jpush",
|
||||
config={"app_key": "app-key-1", "master_secret": "master-secret-1"},
|
||||
)
|
||||
|
||||
with self.assertRaisesMessage(ValueError, "alias 不能为空"):
|
||||
send_notification_with_notifier(
|
||||
notifier=notifier,
|
||||
payload={"mission_id": 12, "description": "检查打印质量"},
|
||||
)
|
||||
mock_send.assert_not_called()
|
||||
|
||||
|
||||
class MessageAPIServiceTestCase(TestCase):
|
||||
@patch("notifier.message_api.urlopen")
|
||||
def test_send_message_api_text_message_calls_message_api_endpoint(self, mock_urlopen):
|
||||
|
||||
Reference in New Issue
Block a user