From b6c9ca633ae7cafe0621e72a34d5b4da6284f9bd Mon Sep 17 00:00:00 2001 From: Spyros Date: Tue, 24 Oct 2023 13:11:44 +0100 Subject: [PATCH] lint --- application/database/db.py | 9 +++++---- application/tests/db_test.py | 8 ++++---- application/tests/web_main_test.py | 7 ++++--- application/utils/hash.py | 4 +++- application/web/web_main.py | 6 ++---- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/application/database/db.py b/application/database/db.py index 9ddc9b853..03681a7db 100644 --- a/application/database/db.py +++ b/application/database/db.py @@ -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]}), diff --git a/application/tests/db_test.py b/application/tests/db_test.py index f119ea51d..edb435bd7 100644 --- a/application/tests/db_test.py +++ b/application/tests/db_test.py @@ -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" diff --git a/application/tests/web_main_test.py b/application/tests/web_main_test.py index 6ca53da1e..dfdfbf0dc 100644 --- a/application/tests/web_main_test.py +++ b/application/tests/web_main_test.py @@ -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): @@ -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`", diff --git a/application/utils/hash.py b/application/utils/hash.py index 0856531d2..6b4f7b400 100644 --- a/application/utils/hash.py +++ b/application/utils/hash.py @@ -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() diff --git a/application/web/web_main.py b/application/web/web_main.py index e5529b79f..91a2a67bd 100644 --- a/application/web/web_main.py +++ b/application/web/web_main.py @@ -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 ( @@ -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)