Skip to content

Commit

Permalink
Fix notes datetime ISO 8601 format (#827)
Browse files Browse the repository at this point in the history
* fix notes dt Iso8601 format

* add test

* use mockHelpingNowUTC in test

* iso dt update in signaling
  • Loading branch information
rodolfomiranda authored Aug 12, 2024
1 parent 388e392 commit ee5177c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/keri/app/notifying.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
keri.app.notifying module
"""
import datetime
from collections.abc import Iterable
from typing import Union, Type

Expand Down Expand Up @@ -71,7 +70,7 @@ def __init__(self, raw=b'', pad=None, note=None):
raise ValueError(f"invalid notice, missing attributes in {pad}")

if "dt" not in self._pad:
self._pad["dt"] = datetime.datetime.now().isoformat()
self._pad["dt"] = helping.nowIso8601()

@property
def datetime(self):
Expand Down Expand Up @@ -386,7 +385,7 @@ def add(self, attrs):
"""

note = notice(attrs, dt=datetime.datetime.now())
note = notice(attrs, dt=helping.nowIso8601())
cig = self.hby.signator.sign(ser=note.raw)
if self.noter.add(note, cig):
signal = dict(
Expand Down
6 changes: 3 additions & 3 deletions src/keri/app/signaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def signal(attrs, topic, ckey=None, dt=None):
Notice: Notice instance
"""
dt = dt if dt is not None else datetime.datetime.now().isoformat()
dt = dt if dt is not None else helping.nowIso8601()

if hasattr(dt, "isoformat"):
dt = dt.isoformat()
Expand Down Expand Up @@ -117,7 +117,7 @@ def push(self, attrs, topic, ckey=None, dt=None):
Returns:
"""
dt = dt if dt is not None else datetime.datetime.now()
dt = dt if dt is not None else helping.nowIso8601()
sig = signal(attrs=attrs, topic=topic, ckey=ckey, dt=dt)

if sig.ckey is not None:
Expand Down Expand Up @@ -146,7 +146,7 @@ def expireDo(self, tymth=None, tock=0.0):
_ = (yield self.tock)

while True: # loop checking for expired messages
now = datetime.datetime.now()
now = helping.nowUTC()
toRemove = []
for sig in self.signals:
if now - helping.fromIso8601(sig.dt) > self.SignalTimeout: # Expire messages that are too old
Expand Down
19 changes: 12 additions & 7 deletions tests/app/test_notifying.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_dictersuber():
assert res[2].attrs['a'] == 3


def test_noter():
def test_noter(mockHelpingNowUTC):
noter = notifying.Noter()
assert noter.path.endswith("/not/not")
noter.reopen()
Expand Down Expand Up @@ -137,12 +137,14 @@ def test_noter():
notes = noter.getNotes(start=0)
assert len(notes) == 0

dt = datetime.datetime.now()
note = notifying.notice(attrs=dict(a=1))
note = notifying.notice(attrs=dict(a=1),
dt=helping.fromIso8601("2022-07-08T15:01:05.453632"))
assert noter.add(note, cig) is True
note = notifying.notice(attrs=dict(a=2))
note = notifying.notice(attrs=dict(a=2),
dt=helping.fromIso8601("2022-07-08T15:01:06.453632"))
assert noter.add(note, cig) is True
note = notifying.notice(attrs=dict(a=3))
note = notifying.notice(attrs=dict(a=3),
dt=helping.fromIso8601("2022-07-08T15:01:07.453632"))
assert noter.add(note, cig) is True

res = []
Expand All @@ -164,12 +166,13 @@ def test_noter():
res.append(note)

assert len(res) == 5
assert res[0][0].datetime == "2021-01-01T00:00:00.000000+00:00"

cnt = noter.getNoteCnt()
assert cnt == 13


def test_notifier():
def test_notifier(mockHelpingNowUTC):
with habbing.openHby(name="test") as hby:
notifier = notifying.Notifier(hby=hby)
assert notifier.signaler is not None
Expand Down Expand Up @@ -200,14 +203,16 @@ def test_notifier():
assert notifier.rem(note.rid) is True
assert notifier.getNotes() == []

dt = datetime.datetime.now()
dt = helping.nowIso8601()
assert notifier.add(attrs=dict(a=1)) is True
assert notifier.add(attrs=dict(a=2)) is True
assert notifier.add(attrs=dict(a=3)) is True

notes = notifier.getNotes()
assert len(notes) == 3

assert notes[2].datetime == "2021-01-01T00:00:00.000000+00:00"

payload = dict(a=1, b=2, c=3)
dt = helping.fromIso8601("2022-07-08T15:01:05.453632")
cig = coring.Cigar(qb64="AABr1EJXI1sTuI51TXo4F1JjxIJzwPeCxa-Cfbboi7F4Y4GatPEvK629M7G_5c86_Ssvwg8POZWNMV-WreVqBECw")
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_signaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_signaler():
signaler.push(attrs=dict(a=1), topic="/m")
signaler.push(attrs=dict(a=2), topic="/m", ckey="abc")
signaler.push(attrs=dict(a=3), topic="/m")
now = datetime.datetime.now() - datetime.timedelta(minutes=11)
now = helping.nowUTC() - datetime.timedelta(minutes=11)
signaler.push(attrs=dict(a=4), topic="/m", ckey="abc", dt=now)

assert len(signaler.signals) == 3
Expand Down

0 comments on commit ee5177c

Please sign in to comment.