From 76749ea7d29c1a9c7bd85bff0676fc62f547c5f9 Mon Sep 17 00:00:00 2001 From: docktermj Date: Mon, 29 Jul 2024 11:19:59 -0400 Subject: [PATCH] #3 Working unittest --- .mypy.ini | 4 ++-- examples/szengine/search_by_attributes.py | 6 ++++-- src/senzing_grpc/szengine.py | 6 +++--- tests/szengine_test.py | 8 +++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index d43be3b7..544a83e2 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -3,5 +3,5 @@ [mypy-grpc.*] ignore_missing_imports = True -[mypy-pytest_schema.*] -ignore_missing_imports = True +[mypy-senzing_grpc.*] +disable_error_code = attr-defined,no-untyped-call diff --git a/examples/szengine/search_by_attributes.py b/examples/szengine/search_by_attributes.py index e00e9f1e..77ff23ae 100755 --- a/examples/szengine/search_by_attributes.py +++ b/examples/szengine/search_by_attributes.py @@ -1,10 +1,12 @@ #! /usr/bin/env python3 +import json + import grpc from senzing_grpc import SzEngine, SzEngineFlags, SzError -ATTRIBUTES = {"NAME_FULL": "BOB SMITH", "EMAIL_ADDRESS": "bsmith@work.com"} +ATTRIBUTES = json.dumps({"NAME_FULL": "BOB SMITH", "EMAIL_ADDRESS": "bsmith@work.com"}) FLAGS = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS GRPC_URL = "localhost:8261" SEARCH_PROFILE = "" @@ -12,7 +14,7 @@ try: grpc_channel = grpc.insecure_channel(GRPC_URL) sz_engine = SzEngine(grpc_channel=grpc_channel) - RESULT = sz_engine.search_by_attributes(ATTRIBUTES, SEARCH_PROFILE, FLAGS) + RESULT = sz_engine.search_by_attributes(ATTRIBUTES, FLAGS, SEARCH_PROFILE) print(RESULT[:66], "...") except SzError as err: print(f"\nError:\n{err}\n") diff --git a/src/senzing_grpc/szengine.py b/src/senzing_grpc/szengine.py index a68f1c09..af8abcef 100644 --- a/src/senzing_grpc/szengine.py +++ b/src/senzing_grpc/szengine.py @@ -537,7 +537,7 @@ def reinitialize(self, config_id: int, **kwargs: Any) -> None: def search_by_attributes( self, - attributes: Union[str, Dict[Any, Any]], + attributes: str, flags: int = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS, search_profile: str = "", **kwargs: Any, @@ -545,9 +545,9 @@ def search_by_attributes( _ = kwargs try: request = szengine_pb2.SearchByAttributesRequest( # type: ignore[unused-ignore] - attributes=as_str(attributes), - searchProfile=search_profile, + attributes=attributes, flags=flags, + searchProfile=search_profile, ) response = self.stub.SearchByAttributes(request) return str(response.result) diff --git a/tests/szengine_test.py b/tests/szengine_test.py index b918e380..7e091d2d 100755 --- a/tests/szengine_test.py +++ b/tests/szengine_test.py @@ -898,10 +898,12 @@ def test_search_by_attributes(sz_engine: SzEngine) -> None: ("CUSTOMERS", "1003"), ] add_records(sz_engine, test_records) - attributes = {"NAME_FULL": "BOB SMITH", "EMAIL_ADDRESS": "bsmith@work.com"} + attributes = json.dumps( + {"NAME_FULL": "BOB SMITH", "EMAIL_ADDRESS": "bsmith@work.com"} + ) search_profile = "" flags = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS - actual = sz_engine.search_by_attributes(attributes, search_profile, flags) + actual = sz_engine.search_by_attributes(attributes, flags, search_profile) delete_records(sz_engine, test_records) if len(actual) > 0: actual_as_dict = json.loads(actual) @@ -914,7 +916,7 @@ def test_search_by_attributes_bad_attributes(sz_engine: SzEngine) -> None: search_profile = "" flags = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS with pytest.raises(SzBadInputError): - _ = sz_engine.search_by_attributes(bad_attributes, search_profile, flags) + _ = sz_engine.search_by_attributes(bad_attributes, flags, search_profile) def test_why_entities(sz_engine: SzEngine) -> None: