test and fix for edge case
This commit is contained in:
parent
16f237dc60
commit
6ab3e9657d
@ -35,25 +35,23 @@ class Notifier:
|
||||
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):
|
||||
with self.get_metadata_dict(addr).modify() as data:
|
||||
tokens = data.get(METADATA_TOKEN_KEY)
|
||||
if tokens:
|
||||
try:
|
||||
tokens.remove(token)
|
||||
except KeyError:
|
||||
pass
|
||||
tokens = data.get(METADATA_TOKEN_KEY, [])
|
||||
try:
|
||||
tokens.remove(token)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def get_tokens(self, addr):
|
||||
return self.get_metadata_dict(addr).read().get(METADATA_TOKEN_KEY, [])
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user