|
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.routing import map_channel_names_to_ports, Route, 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
|
|
|
routes = { |
|
45
|
|
|
Route(create_port(514), '#one'), |
|
46
|
|
|
} |
|
47
|
|
|
router = Router(routes) |
|
48
|
|
|
|
|
49
|
|
|
router.enable_channel(None, channel_name='#one') |
|
50
|
|
|
router.enable_channel(None, channel_name='#two') |
|
51
|
|
|
|
|
52
|
|
|
assert router.is_channel_enabled('#one') |
|
53
|
|
|
assert not router.is_channel_enabled('#two') |
|
54
|
|
|
|