From 0242322d247442e2365634d0aec39b426950ffad Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Sun, 9 Feb 2020 17:59:52 +0100 Subject: [PATCH] Tweak error halding a little - Python should raise exceptions on error. Not return False. - Negative durations are nonense. - ChatID validity is already checked by the Rust API, let's not duplicate. --- deltachat-ffi/src/lib.rs | 2 +- python/src/deltachat/chat.py | 6 ++++-- python/tests/test_account.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 70fad4937..6d57a1906 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1415,7 +1415,7 @@ pub unsafe extern "C" fn dc_set_chat_mute_duration( chat_id: u32, duration: i64, ) -> libc::c_int { - if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 { + if context.is_null() { eprintln!("ignoring careless call to dc_set_chat_mute_duration()"); return 0; } diff --git a/python/src/deltachat/chat.py b/python/src/deltachat/chat.py index 30c8ff53a..4ad437bbf 100644 --- a/python/src/deltachat/chat.py +++ b/python/src/deltachat/chat.py @@ -101,13 +101,15 @@ class Chat(object): """ mutes the chat :param duration: Number of seconds to mute the chat for. None to mute until unmuted again. - :returns: + :returns: None """ if duration is None: mute_duration = -1 else: mute_duration = duration - return bool(lib.dc_set_chat_mute_duration(self._dc_context, self.id, mute_duration)) + ret = lib.dc_set_chat_mute_duration(self._dc_context, self.id, mute_duration) + if not bool(ret): + raise ValueError("Call to dc_set_chat_mute_duration failed") def unmute(self): """ unmutes the chat diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 0ae067675..4d99683ad 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -229,8 +229,8 @@ class TestOfflineChat: assert not chat.is_muted() assert chat.mute(50) assert chat.is_muted() - assert chat.mute(-51) - assert not chat.is_muted() + with pytest.raises(ValueError): + chat.mute(-51) def test_delete_and_send_fails(self, ac1, chat1): chat1.delete()