File: test_iot_integration.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 (27 lines) | stat: -rw-r--r-- 909 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
import json

import boto3

from moto import mock_aws


@mock_aws
def test_search_things_include_named_shadow():
    iot_client = boto3.client("iot", region_name="ap-northeast-1")
    iotdata_client = boto3.client("iot-data", region_name="ap-northeast-1")
    raw_payload = b'{"state": {"desired": {"led": "on"}, "reported": {"led": "off"}}}'

    thing_name = "test-thing-name"
    iot_client.create_thing(thingName=thing_name)
    iotdata_client.update_thing_shadow(
        thingName=thing_name, shadowName="test_shadow", payload=raw_payload
    )

    resp = iot_client.search_index(queryString=f"thingName:{thing_name}")

    assert len(resp["things"]) == 1
    shadow = json.loads(resp["things"][0]["shadow"])

    assert shadow["name"]["test_shadow"]["desired"] == {"led": "on"}
    assert shadow["name"]["test_shadow"]["reported"] == {"led": "off"}
    assert shadow["name"]["test_shadow"]["hasDelta"]