Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/use_notify/channels/chanify.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def headers(self):

@staticmethod
def build_api_body(content, title=None):
return {"text": f"{title}\n{content}"}
text = f"{title}\n{content}" if title else content
return {"text": text}

def send(self, content, title=None):
api_body = self.build_api_body(content, title)
Expand Down
3 changes: 2 additions & 1 deletion src/use_notify/channels/wechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def headers(self):
return {"Content-Type": "application/json"}

def build_api_body(self, title, content):
content = f"## {title}\n\n{content}"
if title:
content = f"## {title}\n\n{content}"
api_body = {"markdown": {"content": content}, "msgtype": "markdown"}

if self.config.mentioned_list:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def test_chanify_send_builds_expected_request(mock_client):
response.raise_for_status.assert_called_once_with()


def test_chanify_omits_title_when_missing():
channel = useNotifyChannel.Chanify({"token": "token"})

assert channel.build_api_body("hello") == {"text": "hello"}


def test_ding_build_api_body_includes_mentions():
channel = useNotifyChannel.Ding(
{
Expand Down Expand Up @@ -240,6 +246,15 @@ def test_wechat_build_api_body_includes_mentions():
}


def test_wechat_omits_title_when_missing():
channel = useNotifyChannel.WeChat({"token": "token"})

assert channel.build_api_body(None, "hello") == {
"markdown": {"content": "hello"},
"msgtype": "markdown",
}


@patch("httpx.Client")
def test_wechat_send_rejects_business_error_response(mock_client):
response = _mock_sync_http_response({"errcode": 40001, "errmsg": "invalid credential"})
Expand Down