| Total Complexity | 3 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | :Copyright: 2007-2021 Jochen Kupperschmidt |
||
| 3 | :License: MIT, see LICENSE for details. |
||
| 4 | """ |
||
| 5 | |||
| 6 | import pytest |
||
| 7 | |||
| 8 | from syslog2irc.network import Port, TransportProtocol |
||
| 9 | from syslog2irc.router import map_channel_names_to_ports, Router |
||
| 10 | |||
| 11 | |||
| 12 | def create_port(number): |
||
| 13 | return Port(number, TransportProtocol.UDP) |
||
| 14 | |||
| 15 | |||
| 16 | @pytest.mark.parametrize( |
||
| 17 | 'routes, expected', |
||
| 18 | [ |
||
| 19 | ( |
||
| 20 | { |
||
| 21 | create_port(514): ['#example1'], |
||
| 22 | }, |
||
| 23 | { |
||
| 24 | '#example1': {create_port(514)}, |
||
| 25 | }, |
||
| 26 | ), |
||
| 27 | ( |
||
| 28 | { |
||
| 29 | create_port(514): ['#example1', '#example2'], |
||
| 30 | create_port(55514): ['#example2'], |
||
| 31 | }, |
||
| 32 | { |
||
| 33 | '#example1': {create_port(514)}, |
||
| 34 | '#example2': {create_port(514), create_port(55514)}, |
||
| 35 | }, |
||
| 36 | ), |
||
| 37 | ], |
||
| 38 | ) |
||
| 39 | def test_map_channel_names_to_ports(routes, expected): |
||
| 40 | assert map_channel_names_to_ports(routes) == expected |
||
| 41 | |||
| 42 | |||
| 43 | def test_do_not_enable_channel_without_routed_ports(): |
||
| 44 | router = Router({create_port(514): {'#one'}}) |
||
| 45 | |||
| 46 | router.enable_channel(None, channel_name='#one') |
||
| 47 | router.enable_channel(None, channel_name='#two') |
||
| 48 | |||
| 49 | assert router.is_channel_enabled('#one') |
||
| 50 | assert not router.is_channel_enabled('#two') |
||
| 51 |