From 4cf6f930565da7d99196809767bc92816502f36c Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Sat, 27 Jul 2024 09:27:54 -0300 Subject: [PATCH 1/4] fix notes dt Iso8601 format --- src/keri/app/notifying.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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( From 209a1be3c6cc278c6d07432eec4b201c313e02ab Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Tue, 30 Jul 2024 19:01:10 -0300 Subject: [PATCH 2/4] add test --- tests/app/test_notifying.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/app/test_notifying.py b/tests/app/test_notifying.py index b02bd91c..f1678883 100644 --- a/tests/app/test_notifying.py +++ b/tests/app/test_notifying.py @@ -154,6 +154,8 @@ def test_noter(): assert res[1][0].attrs['a'] == 2 assert res[2][0].attrs['a'] == 3 + assert res[2][0].datetime[-6:] == "+00:00" + # test paginated iteration for i in range(10): note = notifying.notice(attrs=dict(a=i)) @@ -208,6 +210,8 @@ def test_notifier(): notes = notifier.getNotes() assert len(notes) == 3 + assert notes[2].datetime[-6:] == "+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") From 0c5daaaa50f204699dc3462251352bee039afdf6 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Wed, 31 Jul 2024 17:59:00 -0300 Subject: [PATCH 3/4] use mockHelpingNowUTC in test --- tests/app/test_notifying.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/app/test_notifying.py b/tests/app/test_notifying.py index f1678883..2f3d294d 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 = [] @@ -154,8 +156,6 @@ def test_noter(): assert res[1][0].attrs['a'] == 2 assert res[2][0].attrs['a'] == 3 - assert res[2][0].datetime[-6:] == "+00:00" - # test paginated iteration for i in range(10): note = notifying.notice(attrs=dict(a=i)) @@ -166,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 @@ -210,7 +211,7 @@ def test_notifier(): notes = notifier.getNotes() assert len(notes) == 3 - assert notes[2].datetime[-6:] == "+00:00" + 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") From ace0eb347fce8e286f6245c8e02cfe940645c83b Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Wed, 31 Jul 2024 18:38:37 -0300 Subject: [PATCH 4/4] iso dt update in signaling --- src/keri/app/signaling.py | 6 +++--- tests/app/test_notifying.py | 2 +- tests/app/test_signaling.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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 2f3d294d..a62bb620 100644 --- a/tests/app/test_notifying.py +++ b/tests/app/test_notifying.py @@ -203,7 +203,7 @@ def test_notifier(mockHelpingNowUTC): 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 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