Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole committed Oct 24, 2023
1 parent d18184b commit b6c9ca6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
9 changes: 5 additions & 4 deletions application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,13 +1837,14 @@ def gap_analysis(

# conn.set(cache_key, flask_json.dumps({"result": grouped_paths}))
cre_db.add_gap_analysis_result(
cache_key=cache_key, ga_object={"result": grouped_paths}
)
cache_key=cache_key, ga_object={"result": grouped_paths}
)

for key in extra_paths_dict:
cre_db.add_gap_analysis_result(
cache_key=make_cache_key(node_names,key), ga_object={"result": extra_paths_dict[key]}
)
cache_key=make_cache_key(node_names, key),
ga_object={"result": extra_paths_dict[key]},
)
# conn.set(
# cache_key + "->" + key,
# flask_json.dumps({"result": extra_paths_dict[key]}),
Expand Down
8 changes: 4 additions & 4 deletions application/tests/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,12 +1569,12 @@ def test_gap_analysis_dump_to_cache(self, gap_mock):
self.assertEqual(response, (expected_response[0], {}, {}))
self.assertEqual(
collection.get_gap_analysis_result("d8160c9b3dc20d4e931aeb4f45262155"),
flask_json.dumps({"result": expected_response[1]})
)
flask_json.dumps({"result": expected_response[1]}),
)
self.assertEqual(
collection.get_gap_analysis_result("d8160c9b3dc20d4e931aeb4f45262155->a"),
flask_json.dumps({"result": expected_response[2]["a"]}),
)
flask_json.dumps({"result": expected_response[2]["a"]}),
)

def test_neo_db_parse_node_code(self):
name = "name"
Expand Down
7 changes: 4 additions & 3 deletions application/tests/web_main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from application.web import web_main
from application.utils.hash import make_array_hash, make_cache_key


class MockJob:
@property
def id(self):
Expand Down Expand Up @@ -687,10 +688,10 @@ def test_gap_analysis_weak_links_no_cache(self) -> None:
def test_gap_analysis_weak_links_response(self, redis_conn_mock) -> None:
expected = {"result": "hello"}
collection = db.Node_collection()
standards =["aaa","bbb"]
standards = ["aaa", "bbb"]
key = "ccc"
cache_key = make_cache_key(standards=standards,key=key)
collection.add_gap_analysis_result(cache_key=cache_key,ga_object=expected)
cache_key = make_cache_key(standards=standards, key=key)
collection.add_gap_analysis_result(cache_key=cache_key, ga_object=expected)
with self.app.test_client() as client:
response = client.get(
"/rest/v1/map_analysis_weak_links?standard=aaa&standard=bbb&key=ccc`",
Expand Down
4 changes: 3 additions & 1 deletion application/utils/hash.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import hashlib

def make_cache_key(standards:list, key:str)->str:

def make_cache_key(standards: list, key: str) -> str:
return make_array_hash(standards) + "->" + key


def make_array_hash(array: list):
return hashlib.md5(":".join(array).encode("utf-8")).hexdigest()
6 changes: 2 additions & 4 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ def gap_analysis() -> Any:
gap_analysis_dict = json.loads(gap_analysis_results)
if gap_analysis_dict.get("job_id"):
try:
res = job.Job.fetch(
id=gap_analysis_dict.get("job_id"), connection=conn
)
res = job.Job.fetch(id=gap_analysis_dict.get("job_id"), connection=conn)
except exceptions.NoSuchJobError as nje:
abort(404, "No such job")
if (
Expand Down Expand Up @@ -269,7 +267,7 @@ def gap_analysis() -> Any:
def gap_analysis_weak_links() -> Any:
standards = request.args.getlist("standard")
key = request.args.get("key")
cache_key = make_cache_key(standards=standards,key=key)
cache_key = make_cache_key(standards=standards, key=key)

database = db.Node_collection()
result = database.get_gap_analysis_result(cache_key=cache_key)
Expand Down

0 comments on commit b6c9ca6

Please sign in to comment.