Debian Codegraph @

tests/test_routing.py

raw
1 from ocpp.routing import after, create_route_map, on
2 from ocpp.v16.enums import Action
3
4
5 def test_create_route_map():
6 """
7 This test validates that route map is created correctly and holds all
8 functions decorated with the @on() and @after decorators.
9
10 """
11
12 class ChargePoint:
13 @on(Action.heartbeat, skip_schema_validation=True)
14 def on_heartbeat(self):
15 pass
16
17 @after(Action.heartbeat)
18 def after_heartbeat(self):
19 pass
20
21 @on(Action.meter_values)
22 def meter_values(self):
23 pass
24
25 def undecorated(self):
26 pass
27
28 cp = ChargePoint()
29 route_map = create_route_map(cp)
30
31 assert route_map == {
32 Action.heartbeat: {
33 "_on_action": cp.on_heartbeat,
34 "_after_action": cp.after_heartbeat,
35 "_skip_schema_validation": True,
36 },
37 Action.meter_values: {
38 "_on_action": cp.meter_values,
39 "_skip_schema_validation": False,
40 },
41 }