Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maximusunc committed Dec 11, 2023
1 parent 7715db1 commit 6be0daf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/service_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int):
# We told the world what we can do!
# Workflow will be a list of the functions, and the parameters if there are any

try:
query_graph = message["message"]["query_graph"]
except KeyError:
return f"No query graph", 422
results_cache = ResultsCache()
override_cache = (message.get("parameters") or {}).get("override_cache")
override_cache = override_cache if type(override_cache) is bool else False
Expand All @@ -185,10 +189,6 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int):
logger.info(f"{guid}: Results cache miss")
else:
if not override_cache:
try:
query_graph = message["message"]["query_graph"]
except KeyError:
return f"No query graph", 422
results = results_cache.get_lookup_result(workflow_def, query_graph)
if results is not None:
logger.info(f"{guid}: Returning results cache lookup")
Expand All @@ -210,8 +210,7 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int):

if infer:
results_cache.set_result(input_id, predicate, qualifiers, source_input, caller, workflow_def, final_answer)
else:
query_graph = message["query_graph"]
else:
results_cache.set_lookup_result(workflow_def, query_graph, final_answer)

# return the answer
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/redisMock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import gzip
import json

async def redisMock(connection_pool=None):
def redisMock(host=None, port=None, db=None, password=None):
# Here's where I got documentation for how to do async fakeredis:
# https://github.com/cunla/fakeredis-py/issues/66#issuecomment-1316045893
redis = await fakeredis.FakeStrictRedis
redis = fakeredis.FakeStrictRedis()
# set up mock function
return redis
4 changes: 2 additions & 2 deletions tests/test_aragorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def xtest_async(mock_callback):


def test_aragorn_wf(monkeypatch):
monkeypatch.setattr(redis, "Redis", redisMock)
monkeypatch.setattr(redis, "StrictRedis", redisMock)
init_db()
workflow_A1("aragorn")

Expand Down Expand Up @@ -300,7 +300,7 @@ def x_test_standup_2():
assert found

def test_null_results(monkeypatch):
monkeypatch.setattr(redis, "Redis", redisMock)
monkeypatch.setattr(redis, "StrictRedis", redisMock)
init_db()
#make sure that aragorn can handle cases where results is null (as opposed to missing)
query= {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
jsondir = 'InputJson_1.2'

def test_bad_ops(monkeypatch):
monkeypatch.setattr(redis, "Redis", redisMock)
monkeypatch.setattr(redis, "StrictRedis", redisMock)
# get the location of the test file
dir_path: str = os.path.dirname(os.path.realpath(__file__))
test_filename = os.path.join(dir_path, jsondir, 'workflow_422.json')
Expand All @@ -30,7 +30,7 @@ def test_bad_ops(monkeypatch):

def test_lookup_only(monkeypatch):
"""This has a workflow with a single op (lookup). So the result should not have scores"""
monkeypatch.setattr(redis, "Redis", redisMock)
monkeypatch.setattr(redis, "StrictRedis", redisMock)
init_db()
dir_path: str = os.path.dirname(os.path.realpath(__file__))
test_filename = os.path.join(dir_path, jsondir, 'workflow_200.json')
Expand Down

0 comments on commit 6be0daf

Please sign in to comment.