File: disconnect_response_test.py

package info (click to toggle)
python-xknx 3.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,064 kB
  • sloc: python: 40,895; javascript: 8,556; makefile: 32; sh: 12
file content (34 lines) | stat: -rw-r--r-- 1,281 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
"""Unit test for KNX/IP DisconnectResponse objects."""

import pytest

from xknx.exceptions import CouldNotParseKNXIP
from xknx.knxip import DisconnectResponse, ErrorCode, KNXIPFrame


class TestKNXIPDisconnectResponse:
    """Test class for KNX/IP DisconnectResponse objects."""

    def test_disconnect_response(self) -> None:
        """Test parsing and streaming DisconnectResponse KNX/IP packet."""
        raw = bytes((0x06, 0x10, 0x02, 0x0A, 0x00, 0x08, 0x15, 0x25))
        knxipframe, _ = KNXIPFrame.from_knx(raw)

        assert isinstance(knxipframe.body, DisconnectResponse)

        assert knxipframe.body.communication_channel_id == 21
        assert knxipframe.body.status_code == ErrorCode.E_NO_MORE_UNIQUE_CONNECTIONS

        disconnect_response = DisconnectResponse(
            communication_channel_id=21,
            status_code=ErrorCode.E_NO_MORE_UNIQUE_CONNECTIONS,
        )
        knxipframe2 = KNXIPFrame.init_from_body(disconnect_response)

        assert knxipframe2.to_knx() == raw

    def test_from_knx_wrong_length(self) -> None:
        """Test parsing and streaming wrong DisconnectResponse."""
        raw = bytes((0x06, 0x10, 0x02, 0x0A, 0x00, 0x08, 0x15))
        with pytest.raises(CouldNotParseKNXIP):
            KNXIPFrame.from_knx(raw)