def test_send_message_typeerror(self, request): from django.conf import settings settings.SPARROW_DING_TALK_CONF = { "SERVICE_DING_TALK": "ding-talk:8001", "PATH": "/send/message/", } try: send_message(1, {}) except Exception as ex: self.assertEqual(type(ex), TypeError)
def test_send_message_400(self, request): from django.conf import settings settings.SPARROW_DING_TALK_CONF = { "SERVICE_DING_TALK": "ding-talk:8001", "PATH": "/send/message/", } self.assertEqual( send_message("test", ["123"], "wechat", "text").status_code, 400) self.assertEqual( send_message("test", ["123"], "wechat", "text").detail, XX.detail)
def test_send_message_400(self, request): from django.conf import settings settings.SPARROW_DING_TALK_CONF = { "SERVICE_DING_TALK": { "ENV_NAME": "SERVICE_DING_TALK_HOST", "VALUE": os.environ.get("SERVICE_DING_TALK", "ding-talk"), }, "PATH": "/send/message/", } self.assertEqual( send_message("test", ["123"], "wechat", "text").status_code, 400) self.assertEqual( send_message("test", ["123"], "wechat", "text").detail, XX.detail)
def test_send_message_typeerror(self, request): from django.conf import settings settings.SPARROW_DING_TALK_CONF = { "SERVICE_DING_TALK": { "ENV_NAME": "SERVICE_DING_TALK_HOST", "VALUE": os.environ.get("SERVICE_DING_TALK", "ding-talk"), }, "PATH": "/send/message/", } try: send_message(1, {}) except Exception as ex: self.assertEqual(type(ex), TypeError)
def process_exception(self, request, exception): debug = settings.DEBUG code = getattr(settings, "CLOUD_ERROR_NOTIFICATION_ROBOT", "cloud_error_notification_robot") service_name = getattr(settings, "SERVICE_CONF", None).get("NAME", None) if debug is True: pass else: exception_info = traceback.format_exc()[-800:-1] try: msg = MESSAGE_LINE.format(service_name=service_name, exception_info=exception_info) logger.info("sparrow_cloud log, service process_exception info : {}".format(msg)) send_message(msg=msg, code_list=[code], channel="wechat", message_type="markdown") except Exception as ex: logger.error("sparrow_cloud 发送服务异常信息通知失败,原因: {}".format(ex))
def test_send_message(self, request): from django.conf import settings settings.SPARROW_DING_TALK_CONF = { "SERVICE_DING_TALK": "ding-talk:8001", "PATH": "/send/message/", } res = send_message("test", ["123"], "wechat", "text") self.assertEqual(res.get("data"), {"code": 0, "message": "success"})
def test_send_message(self, request): from django.conf import settings settings.SPARROW_DING_TALK_CONF = { "SERVICE_DING_TALK": { "ENV_NAME": "SERVICE_DING_TALK_HOST", "VALUE": os.environ.get("SERVICE_DING_TALK", "ding-talk"), }, "PATH": "/send/message/", } res = send_message("test", ["123"], "wechat", "text") self.assertEqual(res.get("data"), {"code": 0, "message": "success"})
def test_send_message_typeerror(self, request): try: send_message(1, {}) except Exception as ex: self.assertEqual(type(ex), TypeError)
def test_send_message_400(self, request): self.assertEqual( send_message("test", ["123"], "wechat", "text").status_code, 400) self.assertEqual( send_message("test", ["123"], "wechat", "text").detail, XX.detail)
def test_send_message(self, request): res = send_message("test", ["123"], "wechat", "text") self.assertEqual(res.get("data"), {"code": 0, "message": "success"})