2023-04-03 16:18:10 +00:00
|
|
|
import boto3
|
|
|
|
import requests
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws, settings
|
2023-04-03 16:18:10 +00:00
|
|
|
|
|
|
|
# See our Development Tips on writing tests for hints on how to write good tests:
|
|
|
|
# http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html
|
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-04-03 16:18:10 +00:00
|
|
|
def test_execute_statement():
|
|
|
|
rdsdata = boto3.client("rds-data", region_name="eu-west-1")
|
|
|
|
|
|
|
|
resp = rdsdata.execute_statement(
|
|
|
|
resourceArn="not applicable",
|
|
|
|
secretArn="not applicable",
|
|
|
|
sql="SELECT some FROM thing",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert resp["records"] == []
|
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-04-03 16:18:10 +00:00
|
|
|
def test_set_query_results():
|
|
|
|
base_url = (
|
2023-12-01 23:26:18 +00:00
|
|
|
settings.test_server_mode_endpoint()
|
|
|
|
if settings.TEST_SERVER_MODE
|
|
|
|
else "http://motoapi.amazonaws.com"
|
2023-04-03 16:18:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
sql_result = {
|
|
|
|
"results": [
|
|
|
|
{
|
|
|
|
"records": [[{"isNull": True}], [{"isNull": False}]],
|
|
|
|
"columnMetadata": [{"name": "a"}],
|
|
|
|
"formattedRecords": "some json",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"region": "us-west-1",
|
|
|
|
}
|
|
|
|
resp = requests.post(
|
2023-12-01 23:26:18 +00:00
|
|
|
f"{base_url}/moto-api/static/rds-data/statement-results",
|
2023-04-03 16:18:10 +00:00
|
|
|
json=sql_result,
|
|
|
|
)
|
|
|
|
assert resp.status_code == 201
|
|
|
|
|
|
|
|
rdsdata = boto3.client("rds-data", region_name="us-west-1")
|
|
|
|
|
|
|
|
resp = rdsdata.execute_statement(
|
|
|
|
resourceArn="not applicable",
|
|
|
|
secretArn="not applicable",
|
|
|
|
sql="SELECT some FROM thing",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert resp["records"] == [[{"isNull": True}], [{"isNull": False}]]
|
|
|
|
assert resp["formattedRecords"] == "some json"
|