Debian Codegraph @

tests/v201/conftest.py

raw
1 from unittest.mock import AsyncMock
2
3 import pytest
4
5 from ocpp.messages import Call, CallResult
6 from ocpp.v201 import ChargePoint, call
7 from ocpp.v201.enums import Action
8
9 chargingStation = {
10 "vendorName": "ICU Eve Mini",
11 "firmwareVersion": "#1:3.4.0-2990#N:217H;1.0-223",
12 "model": "ICU Eve Mini",
13 }
14
15
16 @pytest.fixture
17 def heartbeat_call():
18 return Call(unique_id=1, action=Action.heartbeat, 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 "reason": "PowerUp",
28 "chargingStation": chargingStation,
29 },
30 ).to_json()
31
32
33 @pytest.fixture
34 def base_central_system(connection):
35 cs = ChargePoint(
36 id=1234,
37 connection=connection,
38 )
39
40 cs._unique_id_generator = lambda: 1337
41
42 return cs
43
44
45 @pytest.fixture
46 def mock_boot_request():
47 return call.BootNotification(
48 reason="PowerUp",
49 charging_station=chargingStation,
50 )
51
52
53 @pytest.fixture
54 def mock_base_central_system(base_central_system):
55 mock_result_call = CallResult(
56 unique_id=str(base_central_system._unique_id_generator()),
57 action=Action.boot_notification,
58 payload={
59 "currentTime": "2018-05-29T17:37:05.495259",
60 "interval": 350,
61 "status": "Accepted",
62 },
63 )
64
65 base_central_system._send = AsyncMock()
66
67 mock_response = AsyncMock()
68 mock_response.return_value = mock_result_call
69 base_central_system._get_specific_response = mock_response
70
71 return base_central_system