def test_send_log_key_error(self, mock_post): from django.conf import settings settings.SERVICE_CONF = { "NAME": "sparrow_cloud", } try: send_log("key_error") except Exception as ex: self.assertEqual(type(ex), TypeError)
def test_send_log_key_error(self, mock_post): from django.conf import settings settings.SPARROW_SERVICE_LOG_CONF = { "SERVICE_LOG": "sparrow-log-svc:8001", "PATH": "/service_log/log/", } settings.SERVICE_CONF = { "NAME": "sparrow_cloud", } try: send_log("key_error") except Exception as ex: self.assertEqual(type(ex), TypeError)
def test_send_log(self, token, mock_post, consul): from django.conf import settings settings.SPARROW_SERVICE_LOG_CONF = { "SERVICE_LOG": { "ENV_NAME": "SPARROW_SERVICE_LOG", "VALUE": os.environ.get("SPARROW_SERVICE_LOG", "sparrow-service-log-svc"), }, "PATH": "/service_log/log/", } settings.SERVICE_CONF = { "NAME": "sparrow_cloud", } data = { "object_id": "test_object_id", "object_name": "test_object_name", "user_id": "888888889", "user_name": "tiger", "user_phone": "18700000401", "action": "跑路啦", "message": "enenenenenenenenene" } res = send_log(data) self.assertEqual(res, False)
def test_send_log_key_error(self, token, mock_post, consul): from django.conf import settings settings.SPARROW_SERVICE_LOG_CONF = { "SERVICE_LOG": { "ENV_NAME": "SPARROW_SERVICE_LOG", "VALUE": os.environ.get("SPARROW_SERVICE_LOG", "sparrow-service-log-svc"), }, "PATH": "/service_log/log/", } settings.SERVICE_CONF = { "NAME": "sparrow_cloud", } try: send_log("key_error") except Exception as ex: self.assertEqual(type(ex), TypeError)
def test_send_log_1(self, mock_post): from django.conf import settings settings.SERVICE_CONF = { "NAME": "sparrow_cloud", } data = { "object_id": "test_object_id", "object_name": "test_object_name", "user_id": "888888889", "user_name": "tiger", "user_phone": "18700000401", "action": "跑路啦", "message": "enenenenenenenenene" } res = send_log(data) self.assertEqual(res, False)
def test_send_log(self, mock_post): from django.conf import settings settings.SPARROW_SERVICE_LOG_CONF = { "SERVICE_LOG": "sparrow-log-svc:8001", "PATH": "/service_log/log/", } settings.SERVICE_CONF = { "NAME": "sparrow_cloud", } data = { "object_id": "test_object_id", "object_name": "test_object_name", "user_id": "888888889", "user_name": "tiger", "user_phone": "18700000401", "action": "跑路啦", "message": "enenenenenenenenene" } res = send_log(data) self.assertEqual(res, True)