Nessuna descrizione

conftest.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.v201 import ChargePoint, call
  10. chargingStation = {
  11. "vendorName": "ICU Eve Mini",
  12. "firmwareVersion": "#1:3.4.0-2990#N:217H;1.0-223",
  13. "model": "ICU Eve Mini",
  14. }
  15. @pytest.fixture
  16. def heartbeat_call():
  17. return Call(unique_id=1, action="Heartbeat", payload={}).to_json()
  18. @pytest.fixture
  19. def boot_notification_call():
  20. return Call(
  21. unique_id="1",
  22. action="BootNotification",
  23. payload={
  24. "reason": "PowerUp",
  25. "chargingStation": chargingStation,
  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. reason="PowerUp",
  40. charging_station=chargingStation,
  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