コード例 #1
0
ファイル: test_http_client.py プロジェクト: goriok/lifeguard
 def test_call_post_with_http_proxy(self, mock_requests):
     post("url", data="data", headers="headers")
     mock_requests.post.assert_called_with(
         url="url",
         headers="headers",
         data="data",
         auth=None,
         proxies={"http": "http_proxy"},
     )
    def __post_message(self, text, threads, settings):
        new_threads = []
        rooms = (settings.get("notification",
                              {}).get("google",
                                      {}).get("rooms",
                                              [GOOGLE_DEFAULT_CHAT_ROOM]))

        for index, room in enumerate(rooms):
            try:
                thread = self.__get_thread(threads, index)
                data = {"text": text}

                if thread:
                    data["thread"] = thread

                response = post(room, data=json.dumps(data),
                                headers=HEADERS).json()
                self.__log_response(response)
                new_threads.append(response["thread"])
            except Exception as error:
                logger.error(
                    "error on post message: %s",
                    str(error),
                    extra={"traceback": traceback.format_exc()},
                )
                new_threads.append(None)

        return new_threads
コード例 #3
0
ファイル: test_http_client.py プロジェクト: goriok/lifeguard
 def test_call_post_with_auth(self, mock_requests):
     post("url", data="data", headers="headers", auth=("user", "passwd"))
     mock_requests.post.assert_called_with(url="url",
                                           headers="headers",
                                           data="data",
                                           auth=("user", "passwd"))
コード例 #4
0
ファイル: test_http_client.py プロジェクト: goriok/lifeguard
 def test_call_post_without_proxy(self, mock_requests):
     post("url", data="data", headers="headers")
     mock_requests.post.assert_called_with(url="url",
                                           headers="headers",
                                           data="data",
                                           auth=None)