File: config_test.py

package info (click to toggle)
pyvlx 0.2.28-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,552 kB
  • sloc: python: 7,915; makefile: 39; sh: 5
file content (54 lines) | stat: -rw-r--r-- 2,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
"""Unit test for configuration."""
import unittest
from asyncio import AbstractEventLoop
from unittest.mock import MagicMock

from pyvlx import PyVLX, PyVLXException


# pylint: disable=too-many-public-methods,invalid-name
class TestConfig(unittest.TestCase):
    """Test class for configuration."""

    def setUp(self) -> None:
        """Set up TestCommandSend."""
        self.mocked_loop = MagicMock(spec=AbstractEventLoop)

    def test_config_file(self) -> None:
        """Test host/password configuration via config.yaml."""
        pyvlx = PyVLX(loop=self.mocked_loop, path="test/data/test_config.yaml")  # pylint: disable=E1123
        self.assertEqual(pyvlx.config.password, "velux123")
        self.assertEqual(pyvlx.config.host, "192.168.2.127")
        self.assertEqual(pyvlx.config.port, 51200)

    def test_config_file_with_port(self) -> None:
        """Test host/password configuration via config.yaml."""
        pyvlx = PyVLX(loop=self.mocked_loop, path="test/data/test_config_with_port.yaml")  # pylint: disable=E1123
        self.assertEqual(pyvlx.config.port, 1234)

    def test_config_explicit(self) -> None:
        """Test host/password configuration via parameter."""
        pyvlx = PyVLX(loop=self.mocked_loop, host="192.168.2.127", password="velux123")  # pylint: disable=E1123
        self.assertEqual(pyvlx.config.password, "velux123")
        self.assertEqual(pyvlx.config.host, "192.168.2.127")
        self.assertEqual(pyvlx.config.port, 51200)

    def test_config_wrong1(self) -> None:
        """Test configuration with missing password."""
        with self.assertRaises(PyVLXException):
            PyVLX(loop=self.mocked_loop, path="test/data/test_config_wrong1.yaml")  # pylint: disable=E1123

    def test_config_wrong2(self) -> None:
        """Test configuration with missing host."""
        with self.assertRaises(PyVLXException):
            PyVLX(loop=self.mocked_loop, path="test/data/test_config_wrong2.yaml")  # pylint: disable=E1123

    def test_config_wrong3(self) -> None:
        """Test configuration with missing config node."""
        with self.assertRaises(PyVLXException):
            PyVLX(loop=self.mocked_loop, path="test/data/test_config_wrong3.yaml")  # pylint: disable=E1123

    def test_config_non_existent(self) -> None:
        """Test non existing configuration path."""
        with self.assertRaises(PyVLXException):
            PyVLX(loop=self.mocked_loop, path="test/data/test_config_non_existent.yaml")  # pylint: disable=E1123