Nenhuma Descrição

conftest.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. try:
  2. from unittest.mock import AsyncMock
  3. except ImportError:
  4. # Python 3.7 and below don't include unittest.mock.AsyncMock. Hence,
  5. # we need to resolve to a package on pypi.
  6. from asynctest import CoroutineMock as AsyncMock
  7. import pytest
  8. from ocpp.messages import Call, CallResult
  9. from ocpp.v16 import ChargePoint, call
  10. from ocpp.v16.enums import Action
  11. @pytest.fixture
  12. def heartbeat_call():
  13. return Call(unique_id=1, action=Action.Heartbeat, payload={}).to_json()
  14. @pytest.fixture
  15. def not_supported_call():
  16. return Call(unique_id=1, action="InvalidAction", payload={}).to_json()
  17. @pytest.fixture
  18. def boot_notification_call():
  19. return Call(
  20. unique_id="1",
  21. action=Action.BootNotification,
  22. payload={
  23. "chargePointVendor": "Alfen BV",
  24. "chargePointModel": "ICU Eve Mini",
  25. "firmwareVersion": "#1:3.4.0-2990#N:217H;1.0-223",
  26. },
  27. ).to_json()
  28. @pytest.fixture
  29. def base_central_system(connection):
  30. cs = ChargePoint(
  31. id=1234,
  32. connection=connection,
  33. )
  34. cs._unique_id_generator = lambda: 1337
  35. return cs
  36. @pytest.fixture
  37. def mock_boot_request():
  38. return call.BootNotificationPayload(
  39. charge_point_vendor="dummy_vendor",
  40. charge_point_model="dummy_model",
  41. )
  42. @pytest.fixture
  43. def mock_base_central_system(base_central_system):
  44. mock_result_call = CallResult(
  45. unique_id=str(base_central_system._unique_id_generator()),
  46. action="BootNotification",
  47. payload={
  48. "currentTime": "2018-05-29T17:37:05.495259",
  49. "interval": 350,
  50. "status": "Accepted",
  51. },
  52. )
  53. base_central_system._send = AsyncMock()
  54. mock_response = AsyncMock()
  55. mock_response.return_value = mock_result_call
  56. base_central_system._get_specific_response = mock_response
  57. return base_central_system