From 069d70cacdfcbdfe31111937799604e77af1fd63 Mon Sep 17 00:00:00 2001 From: zmezei Date: Thu, 6 Jul 2023 20:22:49 +0100 Subject: [PATCH] fix compute_digest test --- src/uagents/models.py | 10 +++++++--- src/uagents/protocol.py | 2 +- tests/test_field_descr.py | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/uagents/models.py b/src/uagents/models.py index 15aa0b9f..28bcd797 100644 --- a/src/uagents/models.py +++ b/src/uagents/models.py @@ -1,5 +1,5 @@ import hashlib -from typing import Type, Union, Dict +from typing import Type, Union, Dict, Any import json from pydantic import BaseModel @@ -22,10 +22,14 @@ def remove_descriptions(schema: Dict[str, Dict[str, str]]): Model.remove_descriptions(definition) @classmethod - def schema_json_no_descr(cls) -> str: + def schema_no_descr(cls) -> Dict[str, Any]: orig_schema = json.loads(cls.schema_json(indent=None, sort_keys=True)) Model.remove_descriptions(orig_schema) - return json.dumps(orig_schema) + return orig_schema + + @classmethod + def schema_json_no_descr(cls) -> str: + return json.dumps(cls.schema_no_descr()) @staticmethod def build_schema_digest(model: Union["Model", Type["Model"]]) -> str: diff --git a/src/uagents/protocol.py b/src/uagents/protocol.py index bf990e83..8fa93069 100644 --- a/src/uagents/protocol.py +++ b/src/uagents/protocol.py @@ -176,7 +176,7 @@ def manifest(self) -> Dict[str, Any]: for schema_digest, model in all_models.items(): manifest["models"].append( - {"digest": schema_digest, "schema": model.schema_json_no_descr()} + {"digest": schema_digest, "schema": model.schema_no_descr()} ) for request, responses in self._replies.items(): diff --git a/tests/test_field_descr.py b/tests/test_field_descr.py index f13a3c97..671b680f 100644 --- a/tests/test_field_descr.py +++ b/tests/test_field_descr.py @@ -113,8 +113,8 @@ def test_compute_digest(self): def _(_ctx, _sender, _msg): pass - # computed_digest = Protocol.compute_digest(protocol.manifest()) - # self.assertEqual(protocol.digest, computed_digest) + computed_digest = Protocol.compute_digest(protocol.manifest()) + self.assertEqual(protocol.digest, computed_digest) if __name__ == "__main__":