From fbd2fc8eaddd4fd2eb09f70fd395883f36980e3d Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 20 Jul 2023 01:00:14 +0000 Subject: [PATCH] test: add test_webxdc_download_on_demand The test checks that if webxdc update is too large to download with the current `download_limit`, it is applied afterwards when the user manually downloads the update message. --- python/src/deltachat/message.py | 3 +++ python/tests/test_1_online.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/python/src/deltachat/message.py b/python/src/deltachat/message.py index e58d97d05..be42b3059 100644 --- a/python/src/deltachat/message.py +++ b/python/src/deltachat/message.py @@ -486,6 +486,9 @@ class Message: dc_msg = ffi.gc(lib.dc_get_msg(self.account._dc_context, self.id), lib.dc_msg_unref) return lib.dc_msg_get_download_state(dc_msg) + def download_full(self) -> None: + lib.dc_download_full_msg(self.account._dc_context, self.id) + # some code for handling DC_MSG_* view types diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index 798deda23..53d933b59 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -2,6 +2,7 @@ import os import queue import sys import time +import base64 from datetime import datetime, timezone import pytest @@ -323,6 +324,33 @@ def test_webxdc_message(acfactory, data, lp): assert len(list(ac2.direct_imap.conn.fetch(AND(seen=True)))) == 1 +def test_webxdc_download_on_demand(acfactory, data, lp): + ac1, ac2 = acfactory.get_online_accounts(2) + acfactory.introduce_each_other([ac1, ac2]) + chat = acfactory.get_accepted_chat(ac1, ac2) + + msg1 = Message.new_empty(ac1, "webxdc") + msg1.set_text("message1") + msg1.set_file(data.get_path("webxdc/minimal.xdc")) + msg1 = chat.send_msg(msg1) + assert msg1.is_webxdc() + assert msg1.filename + + msg2 = ac2._evtracker.wait_next_incoming_message() + assert msg2.is_webxdc() + + lp.sec("ac2 sets download limit") + ac2.set_config("download_limit", "100") + assert msg1.send_status_update({"payload": base64.b64encode(os.urandom(50000))}, "some test data") + ac2_update = ac2._evtracker.wait_next_incoming_message() + assert ac2_update.download_state == dc.const.DC_DOWNLOAD_AVAILABLE + assert not msg2.get_status_updates() + + ac2_update.download_full() + ac2._evtracker.get_matching("DC_EVENT_WEBXDC_STATUS_UPDATE") + assert msg2.get_status_updates() + + def test_mvbox_sentbox_threads(acfactory, lp): lp.sec("ac1: start with mvbox thread") ac1 = acfactory.new_online_configuring_account(mvbox_move=True, sentbox_watch=True)