File: test_gateway_generic.py

package info (click to toggle)
python-youless-api 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 164 kB
  • sloc: python: 683; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,223 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
from unittest import TestCase
from unittest.mock import patch, Mock, MagicMock

from requests import Response

from youless_api.gateway import fetch_generic_api


def mock_generic_ok(*args, **kwargs) -> Response:
    return Mock(
        ok=True,
        json=lambda: {
                "cnt": "141950,625",
                "pwr": 750,
                "lvl": 90,
                "dev": "(±3%)",
                "det": "",
                "con": "OK",
                "sts": "(33)",
                "raw": 743
            })


class GatewayGenericTest(TestCase):

    @patch('youless_api.gateway.requests.get', side_effect=mock_generic_ok)
    def test_generic_ok(self, mock_get: MagicMock):
        dataset = fetch_generic_api('localhost', None)

        self.assertEqual(dataset['cnt'], 141950.625)
        self.assertEqual(dataset['pwr'], 750)
        self.assertEqual(dataset['lvl'], 90)
        self.assertEqual(dataset['dev'], '(±3%)')
        self.assertEqual(dataset['det'], "")
        self.assertEqual(dataset['con'], 'OK')
        self.assertEqual(dataset['sts'], "(33)")
        self.assertEqual(dataset['raw'], 743)

        mock_get.assert_any_call('http://localhost/a?f=j', auth=None, timeout=2)