Skip to content

Commit

Permalink
#3 Working unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj committed Jul 29, 2024
1 parent 498c163 commit 76749ea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions examples/szengine/search_by_attributes.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#! /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 = ""

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")
6 changes: 3 additions & 3 deletions src/senzing_grpc/szengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,17 @@ 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,
) -> str:
_ = 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)
Expand Down
8 changes: 5 additions & 3 deletions tests/szengine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 76749ea

Please sign in to comment.