From 3064a282026ca1cb491e558e9e638dabff9a3e74 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Mon, 26 Feb 2024 23:32:33 +0000 Subject: [PATCH] Tests: Verify Athena QueryResults work in ProxyMode (#7395) --- .github/workflows/tests_proxymode.yml | 2 +- tests/test_athena/test_athena.py | 2 +- tests/test_athena/test_athena_server_api.py | 22 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests_proxymode.yml b/.github/workflows/tests_proxymode.yml index 583e91666..af7c799db 100644 --- a/.github/workflows/tests_proxymode.yml +++ b/.github/workflows/tests_proxymode.yml @@ -41,7 +41,7 @@ jobs: env: TEST_PROXY_MODE: ${{ true }} run: | - pytest -sv tests/test_acmpca tests/test_awslambda tests/test_apigateway tests/test_core/test_proxy.py tests/test_s3 + pytest -sv tests/test_acmpca tests/test_athena tests/test_awslambda tests/test_apigateway tests/test_core/test_proxy.py tests/test_s3 - name: "Stop MotoProxy" if: always() run: | diff --git a/tests/test_athena/test_athena.py b/tests/test_athena/test_athena.py index eb194b927..0ac70daf1 100644 --- a/tests/test_athena/test_athena.py +++ b/tests/test_athena/test_athena.py @@ -287,7 +287,7 @@ def test_get_query_results(): assert result["ResultSet"]["Rows"] == [] assert result["ResultSet"]["ResultSetMetadata"]["ColumnInfo"] == [] - if not settings.TEST_SERVER_MODE: + if settings.TEST_DECORATOR_MODE: backend = athena_backends[DEFAULT_ACCOUNT_ID]["us-east-1"] rows = [{"Data": [{"VarCharValue": ".."}]}] column_info = [ diff --git a/tests/test_athena/test_athena_server_api.py b/tests/test_athena/test_athena_server_api.py index 95b36b3f1..46dc1b5f3 100644 --- a/tests/test_athena/test_athena_server_api.py +++ b/tests/test_athena/test_athena_server_api.py @@ -1,7 +1,7 @@ import boto3 import requests -from moto import mock_aws, settings +from moto import mock_aws, moto_proxy, settings DEFAULT_COLUMN_INFO = [ { @@ -35,9 +35,13 @@ def test_set_athena_result(): } ] } + kwargs = {} + if settings.is_test_proxy_mode(): + add_proxy_details(kwargs) resp = requests.post( f"http://{base_url}/moto-api/static/athena/query-results", json=athena_result, + **kwargs, ) assert resp.status_code == 201 @@ -60,6 +64,9 @@ def test_set_multiple_athena_result(): base_url = ( "localhost:5000" if settings.TEST_SERVER_MODE else "motoapi.amazonaws.com" ) + kwargs = {} + if settings.is_test_proxy_mode(): + add_proxy_details(kwargs) athena_result = { "results": [ @@ -71,6 +78,7 @@ def test_set_multiple_athena_result(): resp = requests.post( f"http://{base_url}/moto-api/static/athena/query-results", json=athena_result, + **kwargs, ) assert resp.status_code == 201 @@ -100,6 +108,9 @@ def test_set_athena_result_with_custom_region_account(): base_url = ( "localhost:5000" if settings.TEST_SERVER_MODE else "motoapi.amazonaws.com" ) + kwargs = {} + if settings.is_test_proxy_mode(): + add_proxy_details(kwargs) athena_result = { "account_id": "222233334444", @@ -116,6 +127,7 @@ def test_set_athena_result_with_custom_region_account(): resp = requests.post( f"http://{base_url}/moto-api/static/athena/query-results", json=athena_result, + **kwargs, ) assert resp.status_code == 201 @@ -157,3 +169,11 @@ def test_set_athena_result_with_custom_region_account(): client = boto3.client("athena", region_name="eu-west-1") details = client.get_query_results(QueryExecutionId="anyid")["ResultSet"] assert details["Rows"] == [] + + +def add_proxy_details(kwargs): + kwargs["proxies"] = { + "http": "http://localhost:5005", + "https": "http://localhost:5005", + } + kwargs["verify"] = moto_proxy.__file__.replace("__init__.py", "ca.crt")