store tokens in guid-directories
This commit is contained in:
parent
c44f4efced
commit
1a2b73a862
@ -30,17 +30,22 @@ class Notifier:
|
||||
|
||||
def set_token(self, guid, token):
|
||||
guid_path = self.metadata_dir.joinpath(guid)
|
||||
write_path = guid_path.with_suffix(".tmp")
|
||||
if not guid_path.exists():
|
||||
guid_path.mkdir()
|
||||
token_path = guid_path / "token"
|
||||
write_path = token_path.with_suffix(".tmp")
|
||||
write_path.write_text(token)
|
||||
write_path.rename(guid_path)
|
||||
write_path.rename(token_path)
|
||||
|
||||
def del_token(self, guid):
|
||||
self.metadata_dir.joinpath(guid).unlink(missing_ok=True)
|
||||
self.metadata_dir.joinpath(guid).joinpath("token").unlink(missing_ok=True)
|
||||
|
||||
def get_token(self, guid):
|
||||
guid_path = self.metadata_dir / guid
|
||||
if guid_path.exists():
|
||||
return guid_path.read_text()
|
||||
token_path = guid_path / "token"
|
||||
if token_path.exists():
|
||||
return token_path.read_text()
|
||||
|
||||
def new_message_for_guid(self, guid):
|
||||
self.to_notify_queue.put(guid)
|
||||
|
@ -31,6 +31,11 @@ def test_notifier_persistence(tmp_path):
|
||||
assert notifier1.get_token("guid00") is None
|
||||
|
||||
|
||||
def test_notifier_delete_without_set(notifier):
|
||||
notifier.del_token("guid00")
|
||||
assert not notifier.get_token("guid00")
|
||||
|
||||
|
||||
def test_handle_dovecot_request_lookup_fails(notifier):
|
||||
res = handle_dovecot_request("Lpriv/123/chatmail", {}, notifier)
|
||||
assert res == "N\n"
|
||||
|
Loading…
Reference in New Issue
Block a user