diff --git a/src/keri/app/notifying.py b/src/keri/app/notifying.py index 371815f9..4ad03d22 100644 --- a/src/keri/app/notifying.py +++ b/src/keri/app/notifying.py @@ -3,7 +3,6 @@ keri.app.notifying module """ -import datetime from collections.abc import Iterable from typing import Union, Type @@ -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): @@ -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( diff --git a/src/keri/app/signaling.py b/src/keri/app/signaling.py index f32e9dbe..fa44c18f 100644 --- a/src/keri/app/signaling.py +++ b/src/keri/app/signaling.py @@ -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() @@ -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: @@ -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 diff --git a/tests/app/test_notifying.py b/tests/app/test_notifying.py index b02bd91c..a62bb620 100644 --- a/tests/app/test_notifying.py +++ b/tests/app/test_notifying.py @@ -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() @@ -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 = [] @@ -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 @@ -200,7 +203,7 @@ 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 @@ -208,6 +211,8 @@ def test_notifier(): 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") diff --git a/tests/app/test_signaling.py b/tests/app/test_signaling.py index 9010d9e8..fb8f8558 100644 --- a/tests/app/test_signaling.py +++ b/tests/app/test_signaling.py @@ -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