File: test_rdsdata.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (56 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import boto3
import requests

from moto import mock_aws, settings

# 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


@mock_aws
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"] == []


@mock_aws
def test_set_query_results():
    base_url = (
        settings.test_server_mode_endpoint()
        if settings.TEST_SERVER_MODE
        else "http://motoapi.amazonaws.com"
    )

    sql_result = {
        "results": [
            {
                "records": [[{"isNull": True}], [{"isNull": False}]],
                "columnMetadata": [{"name": "a"}],
                "formattedRecords": "some json",
            }
        ],
        "region": "us-west-1",
    }
    resp = requests.post(
        f"{base_url}/moto-api/static/rds-data/statement-results",
        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"