Skip to content

Commit

Permalink
test and fix for edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
hpk42 committed Mar 28, 2024
1 parent 917da89 commit 30435df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 4 additions & 5 deletions chatmaild/src/chatmaild/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ def __init__(self, vmail_dir):
self.to_notify_queue = Queue()

def get_metadata_dict(self, addr):
addr_path = self.vmail_dir.joinpath(addr)
return FileDict(addr_path / "metadata.marshalled")
return FileDict(self.vmail_dir / addr / "metadata.marshalled")

def add_token(self, addr, token):
with self.get_metadata_dict(addr).modify() as data:
tokens = data.get(METADATA_TOKEN_KEY)
if tokens is None:
data[METADATA_TOKEN_KEY] = tokens = []
if token not in tokens:
data[METADATA_TOKEN_KEY] = [token]
elif token not in tokens:
tokens.append(token)

def remove_token(self, addr, token):
Expand All @@ -52,7 +51,7 @@ def remove_token(self, addr, token):
if tokens:
try:
tokens.remove(token)
except KeyError:
except ValueError:
pass

def get_tokens(self, addr):
Expand Down
7 changes: 7 additions & 0 deletions chatmaild/src/chatmaild/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def test_notifier_persistence(tmp_path, testaddr, testaddr2):
assert notifier1.get_tokens(testaddr2) == ["456"]


def test_remove_nonexisting(tmp_path, testaddr):
notifier1 = Notifier(tmp_path)
notifier1.add_token(testaddr, "123")
notifier1.remove_token(testaddr, "1l23k1l2k3")
assert notifier1.get_tokens(testaddr) == ["123"]


def test_notifier_delete_without_set(notifier, testaddr):
notifier.remove_token(testaddr, "123")
assert not notifier.get_tokens(testaddr)
Expand Down

0 comments on commit 30435df

Please sign in to comment.