diff --git a/functions/adoption/libs/network.py b/functions/adoption/libs/network.py index 59532bc..76a731f 100644 --- a/functions/adoption/libs/network.py +++ b/functions/adoption/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) \ No newline at end of file diff --git a/functions/adoption/libs/utils.py b/functions/adoption/libs/utils.py index 36b3a96..997c85e 100644 --- a/functions/adoption/libs/utils.py +++ b/functions/adoption/libs/utils.py @@ -1,11 +1,6 @@ import json from urllib.parse import unquote -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/adoption/main.py b/functions/adoption/main.py index 7faece9..65865dc 100644 --- a/functions/adoption/main.py +++ b/functions/adoption/main.py @@ -1,9 +1,8 @@ import functions_framework from .libs.validator import Validator -from .libs.utils import output from .libs.queries import list_data -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): @@ -11,11 +10,6 @@ def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } - args = request.args.to_dict() validator = Validator(params=args) @@ -23,8 +17,8 @@ def dispatcher(request): if result.failure(): print("error", result.errors) - return output(result) + return respond(result) response = list_data(result.result) - return output(response, headers) + return respond(response) diff --git a/functions/categories/libs/network.py b/functions/categories/libs/network.py index 59532bc..76a731f 100644 --- a/functions/categories/libs/network.py +++ b/functions/categories/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) \ No newline at end of file diff --git a/functions/categories/libs/utils.py b/functions/categories/libs/utils.py index 63890f1..29692f4 100644 --- a/functions/categories/libs/utils.py +++ b/functions/categories/libs/utils.py @@ -1,11 +1,6 @@ import json from urllib.parse import unquote -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/categories/main.py b/functions/categories/main.py index f69e8c2..e14f7ac 100644 --- a/functions/categories/main.py +++ b/functions/categories/main.py @@ -1,20 +1,14 @@ import functions_framework from .libs.validator import Validator -from .libs.utils import output from .libs.queries import list_data -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } args = request.args.to_dict() @@ -23,8 +17,8 @@ def dispatcher(request): if result.failure(): print("error", result.errors) - return output(result) + return respond(result) response = list_data(result.result) - return output(response, headers) \ No newline at end of file + return respond(response) \ No newline at end of file diff --git a/functions/cwvtech/libs/network.py b/functions/cwvtech/libs/network.py index 59532bc..d097aa8 100644 --- a/functions/cwvtech/libs/network.py +++ b/functions/cwvtech/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) diff --git a/functions/cwvtech/libs/utils.py b/functions/cwvtech/libs/utils.py index 63890f1..29692f4 100644 --- a/functions/cwvtech/libs/utils.py +++ b/functions/cwvtech/libs/utils.py @@ -1,11 +1,6 @@ import json from urllib.parse import unquote -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/cwvtech/main.py b/functions/cwvtech/main.py index 0450183..b68f15e 100644 --- a/functions/cwvtech/main.py +++ b/functions/cwvtech/main.py @@ -1,21 +1,15 @@ import functions_framework from .libs.validator import Validator -from .libs.utils import output from .libs.queries import list_data -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } - + args = request.args.to_dict() validator = Validator(params=args) @@ -23,8 +17,8 @@ def dispatcher(request): if result.failure(): print("error", result.errors) - return output(result) + return respond(result) response = list_data(result.result) - return output(response, headers) \ No newline at end of file + return respond(response) \ No newline at end of file diff --git a/functions/geos/libs/network.py b/functions/geos/libs/network.py index 59532bc..76a731f 100644 --- a/functions/geos/libs/network.py +++ b/functions/geos/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) \ No newline at end of file diff --git a/functions/geos/libs/utils.py b/functions/geos/libs/utils.py index 8706e4e..a79faab 100644 --- a/functions/geos/libs/utils.py +++ b/functions/geos/libs/utils.py @@ -1,10 +1,5 @@ import json -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/geos/main.py b/functions/geos/main.py index 0d1c686..0fd5e9d 100644 --- a/functions/geos/main.py +++ b/functions/geos/main.py @@ -1,21 +1,15 @@ import functions_framework -from .libs.utils import output from .libs.utils import ( COUNTRIES ) from .libs.result import Result -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } - + response = Result(result=COUNTRIES) - return output(response, headers) \ No newline at end of file + return respond(response) \ No newline at end of file diff --git a/functions/lighthouse/libs/network.py b/functions/lighthouse/libs/network.py index 59532bc..d097aa8 100644 --- a/functions/lighthouse/libs/network.py +++ b/functions/lighthouse/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) diff --git a/functions/lighthouse/libs/utils.py b/functions/lighthouse/libs/utils.py index 63890f1..29692f4 100644 --- a/functions/lighthouse/libs/utils.py +++ b/functions/lighthouse/libs/utils.py @@ -1,11 +1,6 @@ import json from urllib.parse import unquote -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/lighthouse/main.py b/functions/lighthouse/main.py index 0450183..3fab032 100644 --- a/functions/lighthouse/main.py +++ b/functions/lighthouse/main.py @@ -1,9 +1,8 @@ import functions_framework from .libs.validator import Validator -from .libs.utils import output from .libs.queries import list_data -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): @@ -11,11 +10,6 @@ def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } - args = request.args.to_dict() validator = Validator(params=args) @@ -23,8 +17,8 @@ def dispatcher(request): if result.failure(): print("error", result.errors) - return output(result) + return respond(result) response = list_data(result.result) - return output(response, headers) \ No newline at end of file + return respond(response) \ No newline at end of file diff --git a/functions/page-weight/libs/network.py b/functions/page-weight/libs/network.py index 59532bc..76a731f 100644 --- a/functions/page-weight/libs/network.py +++ b/functions/page-weight/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) \ No newline at end of file diff --git a/functions/page-weight/libs/utils.py b/functions/page-weight/libs/utils.py index 36b3a96..997c85e 100644 --- a/functions/page-weight/libs/utils.py +++ b/functions/page-weight/libs/utils.py @@ -1,11 +1,6 @@ import json from urllib.parse import unquote -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/page-weight/main.py b/functions/page-weight/main.py index 0450183..3fab032 100644 --- a/functions/page-weight/main.py +++ b/functions/page-weight/main.py @@ -1,9 +1,8 @@ import functions_framework from .libs.validator import Validator -from .libs.utils import output from .libs.queries import list_data -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): @@ -11,11 +10,6 @@ def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } - args = request.args.to_dict() validator = Validator(params=args) @@ -23,8 +17,8 @@ def dispatcher(request): if result.failure(): print("error", result.errors) - return output(result) + return respond(result) response = list_data(result.result) - return output(response, headers) \ No newline at end of file + return respond(response) \ No newline at end of file diff --git a/functions/ranks/libs/network.py b/functions/ranks/libs/network.py index 59532bc..d097aa8 100644 --- a/functions/ranks/libs/network.py +++ b/functions/ranks/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) diff --git a/functions/ranks/libs/utils.py b/functions/ranks/libs/utils.py index d8f3e02..923a1fb 100644 --- a/functions/ranks/libs/utils.py +++ b/functions/ranks/libs/utils.py @@ -1,10 +1,5 @@ import json -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/ranks/main.py b/functions/ranks/main.py index a742748..0b9147b 100644 --- a/functions/ranks/main.py +++ b/functions/ranks/main.py @@ -1,9 +1,8 @@ import functions_framework -from .libs.utils import output from .libs.utils import ( RANKS ) from .libs.result import Result -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): @@ -11,11 +10,6 @@ def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } - response = Result(result=RANKS) - return output(response, headers) \ No newline at end of file + return respond(response) \ No newline at end of file diff --git a/functions/technologies/libs/network.py b/functions/technologies/libs/network.py index 59532bc..d097aa8 100644 --- a/functions/technologies/libs/network.py +++ b/functions/technologies/libs/network.py @@ -5,15 +5,22 @@ Handles formatting responses to match the tuple pattern required by the flask/GCP wrapper for Cloud Functions. """ +import json +from .utils import convert_to_hashes PREFLIGHT_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Headers": "Content-Type, Timing-Allow-Origin", "Access-Control-Max-Age": "3600", } -HEADERS = {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"} +HEADERS = { + "Access-Control-Allow-Origin": "*", + "Content-Type": "application/json", + "cache-control": "public, max-age=21600", + "Timing-Allow-Origin": "*" + } def respond_cors(): """ @@ -21,8 +28,10 @@ def respond_cors(): """ return ("", 204, PREFLIGHT_HEADERS) -def respond(data, status=200): +def respond(result, headers=HEADERS): """ To be used to return responses to satisfy CORS requests. """ - return (data, status, HEADERS) + status = 200 if result.success() else 400 + payload = result.result if result.success() else convert_to_hashes(result.errors) + return (json.dumps(payload), status, headers) diff --git a/functions/technologies/libs/queries.py b/functions/technologies/libs/queries.py index f84c2d9..9b9c2b3 100644 --- a/functions/technologies/libs/queries.py +++ b/functions/technologies/libs/queries.py @@ -7,7 +7,6 @@ from .utils import convert_to_array from .presenters import Presenters - DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE')) def list_data(params): @@ -30,6 +29,9 @@ def list_data(params): params_array = convert_to_array(params['category']) query = query.where(filter=FieldFilter('category_obj', 'array_contains_any', params_array)) + if 'client' in params: + query = query.where(filter=FieldFilter('client', '==', params['client'])) + if 'onlyname' in params: onlyname = True diff --git a/functions/technologies/libs/utils.py b/functions/technologies/libs/utils.py index 63890f1..29692f4 100644 --- a/functions/technologies/libs/utils.py +++ b/functions/technologies/libs/utils.py @@ -1,11 +1,6 @@ import json from urllib.parse import unquote -def output(result, headers={}): - status = 200 if result.success() else 400 - payload = result.result if result.success() else convert_to_hashes(result.errors) - return (json.dumps(payload), status, headers) - def convert_to_hashes(arr): hashes_arr = [] for inner_arr in arr: diff --git a/functions/technologies/main.py b/functions/technologies/main.py index 6bcdd8c..3fab032 100644 --- a/functions/technologies/main.py +++ b/functions/technologies/main.py @@ -1,9 +1,8 @@ import functions_framework from .libs.validator import Validator -from .libs.utils import output from .libs.queries import list_data -from .libs.network import respond_cors +from .libs.network import respond_cors, respond @functions_framework.http def dispatcher(request): @@ -11,10 +10,6 @@ def dispatcher(request): if request.method == "OPTIONS": return respond_cors() - headers = { - "Access-Control-Allow-Origin": "*", - "cache-control": "public, max-age=21600" - } args = request.args.to_dict() validator = Validator(params=args) @@ -22,8 +17,8 @@ def dispatcher(request): if result.failure(): print("error", result.errors) - return output(result) + return respond(result) response = list_data(result.result) - return output(response, headers) \ No newline at end of file + return respond(response) \ No newline at end of file diff --git a/tests/test_ranks/libs/test_ranks_utils.py b/tests/test_ranks/libs/test_ranks_utils.py index 82f9bca..cfe142a 100644 --- a/tests/test_ranks/libs/test_ranks_utils.py +++ b/tests/test_ranks/libs/test_ranks_utils.py @@ -2,27 +2,6 @@ from functions.ranks.libs.result import Result import json -def test_output(): - # Create a mock result object with a successful status - result_success = Result(status="success", result={"message": "Hello, world!"}) - - # Call the output function with the mock result object - output_result_success = output(result_success) - - # Verify that the output has the correct HTTP status code and payload - assert output_result_success[1] == 200 - assert json.loads(output_result_success[0]) == {"message": "Hello, world!"} - - # Create a mock result object with an error status - result_error = Result(status="error", errors=[["param", "Invalid request"]]) - - # Call the output function with the mock result object - output_result_error = output(result_error) - - # Verify that the output has the correct HTTP status code and payload - assert output_result_error[1] == 400 - assert json.loads(output_result_error[0]) == [{"param": "Invalid request"}] - def test_convert_to_hashes(): input_arr = [["geo", "missing geo parameters"], ["app", "missing geo parameters"]] expected_output_arr = [{'geo': 'missing geo parameters'}, {'app': 'missing geo parameters'}] diff --git a/tests/test_technologies/libs/test_technologies_utils.py b/tests/test_technologies/libs/test_technologies_utils.py index 2fd433c..797ba38 100644 --- a/tests/test_technologies/libs/test_technologies_utils.py +++ b/tests/test_technologies/libs/test_technologies_utils.py @@ -2,27 +2,6 @@ from functions.technologies.libs.result import Result import json -def test_output(): - # Create a mock result object with a successful status - result_success = Result(status="success", result={"message": "Hello, world!"}) - - # Call the output function with the mock result object - output_result_success = output(result_success) - - # Verify that the output has the correct HTTP status code and payload - assert output_result_success[1] == 200 - assert json.loads(output_result_success[0]) == {"message": "Hello, world!"} - - # Create a mock result object with an error status - result_error = Result(status="error", errors=[["param", "Invalid request"]]) - - # Call the output function with the mock result object - output_result_error = output(result_error) - - # Verify that the output has the correct HTTP status code and payload - assert output_result_error[1] == 400 - assert json.loads(output_result_error[0]) == [{"param": "Invalid request"}] - def test_convert_to_hashes(): input_arr = [["geo", "missing geo parameters"], ["app", "missing geo parameters"]] expected_output_arr = [{'geo': 'missing geo parameters'}, {'app': 'missing geo parameters'}]