Debian Codegraph @

tests/v16/conftest.py

raw
1 from dataclasses import dataclass
2 from unittest.mock import AsyncMock
3
4 import pytest
5
6 from ocpp.messages import Call, CallResult
7 from ocpp.v16 import ChargePoint, call
8 from ocpp.v16.enums import Action
9
10
11 @pytest.fixture
12 def heartbeat_call():
13 return Call(unique_id=1, action=Action.heartbeat, payload={}).to_json()
14
15
16 @pytest.fixture
17 def not_supported_call():
18 return Call(unique_id=1, action="InvalidAction", payload={}).to_json()
19
20
21 @pytest.fixture
22 def boot_notification_call():
23 return Call(
24 unique_id="1",
25 action=Action.boot_notification,
26 payload={
27 "chargePointVendor": "Alfen BV",
28 "chargePointModel": "ICU Eve Mini",
29 "firmwareVersion": "#1:3.4.0-2990#N:217H;1.0-223",
30 },
31 ).to_json()
32
33
34 @pytest.fixture
35 def base_central_system(connection):
36 cs = ChargePoint(
37 id=1234,
38 connection=connection,
39 )
40
41 cs._unique_id_generator = lambda: 1337
42
43 return cs
44
45
46 @pytest.fixture
47 def mock_boot_request():
48 return call.BootNotification(
49 charge_point_vendor="dummy_vendor",
50 charge_point_model="dummy_model",
51 )
52
53
54 @pytest.fixture
55 def mock_invalid_boot_request():
56 @dataclass
57 class BootNotification:
58 custom_field: str
59
60 return BootNotification(custom_field="custom_field")
61
62
63 @pytest.fixture
64 def mock_base_central_system(base_central_system):
65 mock_result_call = CallResult(
66 unique_id=str(base_central_system._unique_id_generator()),
67 action=Action.boot_notification,
68 payload={
69 "currentTime": "2018-05-29T17:37:05.495259",
70 "interval": 350,
71 "status": "Accepted",
72 },
73 )
74
75 base_central_system._send = AsyncMock()
76
77 mock_response = AsyncMock()
78 mock_response.return_value = mock_result_call
79 base_central_system._get_specific_response = mock_response
80
81 return base_central_system