File: test_rooms.py

package info (click to toggle)
python-aiopvapi 3.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 684 kB
  • sloc: python: 3,123; xml: 850; makefile: 5
file content (72 lines) | stat: -rw-r--r-- 2,578 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
71
72
from aiopvapi.resources.room import Room
from aiopvapi.rooms import Rooms

from tests.fake_server import TestFakeServer


class TestRooms(TestFakeServer):

    def test_get_resources_200(self):
        """Test get resources with status 200."""

        async def go():
            await self.start_fake_server()
            rooms = Rooms(self.request)
            resources = await rooms.get_resources()
            return resources

        resources = self.loop.run_until_complete(go())
        self.assertEqual(2, len(resources['roomIds']))
        self.assertEqual(2, len(resources['roomData']))
        self.assertEqual('Repeaters',
                         resources['roomData'][0]['name_unicode'])
        self.assertEqual('Dining Room',
                         resources['roomData'][1]['name_unicode'])

    # def test_get_resources_201(self):
    #     """Test get resources with wrong status."""
    #     mocked.get('http://127.0.0.1/api/rooms',
    #                body=RETURN_VALUE,
    #                status=201,
    #                headers={'content-type': 'application/json'})
    #
    #     with self.assertRaises(PvApiResponseStatusError):
    #         resources = self.loop.run_until_complete(
    #             self.rooms.get_resources())
    #
    #

    def test_get_instance(self):
        async def go():
            await self.start_fake_server()
            rooms = Rooms(self.request)
            response = await rooms.get_instance(1234)
            return response

        resp = self.loop.run_until_complete(go())
        self.assertIsInstance(resp, Room)
        self.assertEqual(resp.name, 'Living room')

    def test_create_room_201(self):
        """Tests create new room."""

        async def go():
            await self.start_fake_server()
            rooms = Rooms(self.request)
            response = await rooms.create_room(
                'New room', color_id=1, icon_id=2)
            return response

        resp = self.loop.run_until_complete(go())
        self.assertEqual(resp['id'], 1)
        self.assertEqual(resp['name'], 'TmV3IHJvb20=')

    # def test_create_room_202(self):
    #     """Tests create new room with wrong status code."""
    #     mocked.post('http://127.0.0.1/api/rooms',
    #                 body='"ok"',
    #                 status=202,
    #                 headers={'content-type': 'application/json'})
    #     with self.assertRaises(PvApiResponseStatusError):
    #         resp = self.loop.run_until_complete(
    #             self.rooms.create_room('New room', color_id=1, icon_id=2))