From d313bea97f866ebfae2db715af44a780b276306e Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 30 Mar 2024 22:45:44 +0100 Subject: [PATCH] some more renaming --- chatmaild/src/chatmaild/metadata.py | 8 ++--- .../src/chatmaild/tests/test_metadata.py | 36 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index 8e3385c..a294bab 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -60,11 +60,11 @@ class Notifier: except ValueError: pass - def get_tokens(self, addr): + def get_tokens_for_addr(self, addr): return self.get_metadata_dict(addr).read().get(METADATA_TOKEN_KEY, []) def new_message_for_addr(self, addr): - for token in self.get_tokens(addr): + for token in self.get_tokens_for_addr(addr): self.notification_dir.joinpath(token).write_text(addr) self.add_token_for_retry(token) @@ -158,7 +158,7 @@ def handle_dovecot_request(msg, transactions, notifier): keyname = keyparts[2] addr = parts[1] if keyname == METADATA_TOKEN_KEY: - res = " ".join(notifier.get_tokens(addr)) + res = " ".join(notifier.get_tokens_for_addr(addr)) return f"O{res}\n" logging.warning("lookup ignored: %r", msg) return "N\n" @@ -192,7 +192,7 @@ def handle_dovecot_request(msg, transactions, notifier): value = parts[2] if len(parts) > 2 else "" addr = transactions[transaction_id]["addr"] if keyname[0] == "priv" and keyname[2] == METADATA_TOKEN_KEY: - notifier.add_token(addr, value) + notifier.add_token_to_addr(addr, value) elif keyname[0] == "priv" and keyname[2] == "messagenew": notifier.new_message_for_addr(addr) else: diff --git a/chatmaild/src/chatmaild/tests/test_metadata.py b/chatmaild/src/chatmaild/tests/test_metadata.py index fe75f70..63069c2 100644 --- a/chatmaild/src/chatmaild/tests/test_metadata.py +++ b/chatmaild/src/chatmaild/tests/test_metadata.py @@ -52,28 +52,28 @@ def get_mocked_requests(statuslist): def test_notifier_persistence(tmp_path, testaddr, testaddr2): notifier1 = Notifier(tmp_path) notifier2 = Notifier(tmp_path) - assert not notifier1.get_tokens(testaddr) - assert not notifier2.get_tokens(testaddr) + assert not notifier1.get_tokens_for_addr(testaddr) + assert not notifier2.get_tokens_for_addr(testaddr) notifier1.add_token_to_addr(testaddr, "01234") notifier1.add_token_to_addr(testaddr2, "456") - assert notifier2.get_tokens(testaddr) == ["01234"] - assert notifier2.get_tokens(testaddr2) == ["456"] + assert notifier2.get_tokens_for_addr(testaddr) == ["01234"] + assert notifier2.get_tokens_for_addr(testaddr2) == ["456"] notifier2.remove_token_from_addr(testaddr, "01234") - assert not notifier1.get_tokens(testaddr) - assert notifier1.get_tokens(testaddr2) == ["456"] + assert not notifier1.get_tokens_for_addr(testaddr) + assert notifier1.get_tokens_for_addr(testaddr2) == ["456"] def test_remove_nonexisting(tmp_path, testaddr): notifier1 = Notifier(tmp_path) notifier1.add_token_to_addr(testaddr, "123") notifier1.remove_token_from_addr(testaddr, "1l23k1l2k3") - assert notifier1.get_tokens(testaddr) == ["123"] + assert notifier1.get_tokens_for_addr(testaddr) == ["123"] def test_notifier_remove_without_set(notifier, testaddr): notifier.remove_token_from_addr(testaddr, "123") - assert not notifier.get_tokens(testaddr) + assert not notifier.get_tokens_for_addr(testaddr) def test_handle_dovecot_request_lookup_fails(notifier, testaddr): @@ -88,20 +88,20 @@ def test_handle_dovecot_request_happy_path(notifier, testaddr, token): tx = "1111" msg = f"B{tx}\t{testaddr}" res = handle_dovecot_request(msg, transactions, notifier) - assert not res and not notifier.get_tokens(testaddr) + assert not res and not notifier.get_tokens_for_addr(testaddr) assert transactions == {tx: dict(addr=testaddr, res="O\n")} msg = f"S{tx}\tpriv/guid00/devicetoken\t{token}" res = handle_dovecot_request(msg, transactions, notifier) assert not res assert len(transactions) == 1 - assert notifier.get_tokens(testaddr) == [token] + assert notifier.get_tokens_for_addr(testaddr) == [token] msg = f"C{tx}" res = handle_dovecot_request(msg, transactions, notifier) assert res == "O\n" assert len(transactions) == 0 - assert notifier.get_tokens(testaddr) == [token] + assert notifier.get_tokens_for_addr(testaddr) == [token] # trigger notification for incoming message tx2 = "2222" @@ -128,7 +128,7 @@ def test_handle_dovecot_protocol_set_devicetoken(notifier): wfile = io.BytesIO() handle_dovecot_protocol(rfile, wfile, notifier) assert wfile.getvalue() == b"O\n" - assert notifier.get_tokens("user@example.org") == ["01234"] + assert notifier.get_tokens_for_addr("user@example.org") == ["01234"] def test_handle_dovecot_protocol_set_get_devicetoken(notifier): @@ -144,7 +144,7 @@ def test_handle_dovecot_protocol_set_get_devicetoken(notifier): ) wfile = io.BytesIO() handle_dovecot_protocol(rfile, wfile, notifier) - assert notifier.get_tokens("user@example.org") == ["01234"] + assert notifier.get_tokens_for_addr("user@example.org") == ["01234"] assert wfile.getvalue() == b"O\n" rfile = io.BytesIO( @@ -176,7 +176,7 @@ def test_notifier_thread_firstrun(notifier, testaddr): notifier.thread_retry_one(reqmock, numtries=0) url, data, timeout = reqmock.requests[0] assert data == "01234" - assert notifier.get_tokens(testaddr) == ["01234"] + assert notifier.get_tokens_for_addr(testaddr) == ["01234"] notifier.requeue_persistent_pending_tokens() assert notifier.retry_queues[0].qsize() == 0 @@ -188,14 +188,14 @@ def test_notifier_thread_run(notifier, testaddr): notifier.thread_retry_one(reqmock, numtries=0) url, data, timeout = reqmock.requests[0] assert data == "01234" - assert notifier.get_tokens(testaddr) == ["01234"] + assert notifier.get_tokens_for_addr(testaddr) == ["01234"] notifier.requeue_persistent_pending_tokens() assert notifier.retry_queues[0].qsize() == 0 @pytest.mark.parametrize("status", [requests.exceptions.RequestException(), 404, 500]) def test_notifier_thread_connection_failures(notifier, testaddr, status, caplog): - """ test that tokens keep getting retried until they are given up. """ + """test that tokens keep getting retried until they are given up.""" notifier.add_token_to_addr(testaddr, "01234") notifier.new_message_for_addr(testaddr) notifier.NOTIFICATION_RETRY_DELAY = 5 @@ -232,7 +232,7 @@ def test_multi_device_notifier(notifier, testaddr): assert data == "01234" url, data, timeout = reqmock.requests[1] assert data == "56789" - assert notifier.get_tokens(testaddr) == ["01234", "56789"] + assert notifier.get_tokens_for_addr(testaddr) == ["01234", "56789"] def test_notifier_thread_run_gone_removes_token(notifier, testaddr): @@ -246,6 +246,6 @@ def test_notifier_thread_run_gone_removes_token(notifier, testaddr): assert data == "01234" url, data, timeout = reqmock.requests[1] assert data == "45678" - assert notifier.get_tokens(testaddr) == ["45678"] + assert notifier.get_tokens_for_addr(testaddr) == ["45678"] assert notifier.retry_queues[0].qsize() == 0 assert notifier.retry_queues[1].qsize() == 0