File: test_scenes.py

package info (click to toggle)
pysmartthings 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,268 kB
  • sloc: python: 8,394; makefile: 3
file content (70 lines) | stat: -rw-r--r-- 2,018 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Tests for the scene module."""

from aiohttp.hdrs import METH_GET, METH_POST
from aioresponses import aioresponses
from syrupy import SnapshotAssertion

from pysmartthings import SmartThings
from tests import load_fixture
from tests.const import MOCK_URL, HEADERS


async def test_fetching_all_scenes(
    client: SmartThings,
    responses: aioresponses,
    snapshot: SnapshotAssertion,
) -> None:
    """Test getting all scenes."""
    responses.get(
        f"{MOCK_URL}/v1/scenes",
        status=200,
        body=load_fixture("scenes.json"),
    )
    assert await client.get_scenes() == snapshot
    responses.assert_called_once_with(
        f"{MOCK_URL}/v1/scenes",
        METH_GET,
        headers=HEADERS,
        params={},
        json=None,
    )


async def test_fetch_scenes_for_location(
    client: SmartThings,
    responses: aioresponses,
) -> None:
    """Test getting all scenes."""
    responses.get(
        f"{MOCK_URL}/v1/scenes?locationId=397678e5-9995-4a39-9d9f-ae6ba310236b",
        status=200,
        body=load_fixture("scenes.json"),
    )
    assert await client.get_scenes("397678e5-9995-4a39-9d9f-ae6ba310236b")
    responses.assert_called_once_with(
        f"{MOCK_URL}/v1/scenes",
        METH_GET,
        headers=HEADERS,
        params={"locationId": "397678e5-9995-4a39-9d9f-ae6ba310236b"},
        json=None,
    )


async def test_executing_scene(
    client: SmartThings,
    responses: aioresponses,
) -> None:
    """Test executing a scene."""
    responses.post(
        f"{MOCK_URL}/v1/scenes/3a570170-7c10-4e5a-bef8-0d02175798f2/execute",
        status=200,
        body=load_fixture("scene_execute.json"),
    )
    await client.execute_scene("3a570170-7c10-4e5a-bef8-0d02175798f2")
    responses.assert_called_once_with(
        f"{MOCK_URL}/v1/scenes/3a570170-7c10-4e5a-bef8-0d02175798f2/execute",
        METH_POST,
        headers=HEADERS,
        params=None,
        json=None,
    )