Nav apraksta

test_routing.py 1020B

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