|
| 1 | +"""Common test fixtures and mocks for the pooldose test suite.""" |
| 2 | + |
| 3 | +from unittest.mock import AsyncMock, MagicMock |
| 4 | + |
| 5 | +import pytest |
| 6 | +from pooldose.request_status import RequestStatus |
| 7 | +from pooldose.values.instant_values import InstantValues |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture |
| 11 | +def mock_request_handler(): |
| 12 | + """Create a mock request handler.""" |
| 13 | + handler = AsyncMock() |
| 14 | + handler.api_version = "v1/" |
| 15 | + handler.connect.return_value = RequestStatus.SUCCESS |
| 16 | + handler.set_value.return_value = True |
| 17 | + return handler |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def mock_device_info(): |
| 22 | + """Create mock device information with all fields.""" |
| 23 | + return { |
| 24 | + "NAME": "Test Device", |
| 25 | + "SERIAL_NUMBER": "TEST123", |
| 26 | + "DEVICE_ID": "TEST123_DEVICE", |
| 27 | + "MODEL": "PDPR1H1HAW100", |
| 28 | + "MODEL_ID": "PDPR1H1HAW100", |
| 29 | + "OWNERID": "Owner1", |
| 30 | + "GROUPNAME": "GroupA", |
| 31 | + "FW_VERSION": "1.0.0", |
| 32 | + "SW_VERSION": "SW1.0", |
| 33 | + "API_VERSION": "v1/", |
| 34 | + "FW_CODE": "FW539187", |
| 35 | + "MAC": "00:11:22:33:44:55", |
| 36 | + "IP": "192.168.1.100", |
| 37 | + "WIFI_SSID": "TestSSID", |
| 38 | + "WIFI_KEY": "TestWifiKey", |
| 39 | + "AP_SSID": "TestAPSSID", |
| 40 | + "AP_KEY": "TestAPKey" |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture |
| 45 | +def mock_device_data(): |
| 46 | + """Create mock device data for InstantValues.""" |
| 47 | + return { |
| 48 | + "PDPR1H1HAW100_FW539187_w_1eommf39k": { |
| 49 | + "current": 25.5, |
| 50 | + "magnitude": ["°C"] |
| 51 | + }, |
| 52 | + "PDPR1H1HAW100_FW539187_w_1eomog123": { |
| 53 | + "current": 7.2, |
| 54 | + "magnitude": ["ph"] |
| 55 | + }, |
| 56 | + "PDPR1H1HAW100_FW539187_w_1eomph456": { |
| 57 | + "current": 7.0, |
| 58 | + "magnitude": ["ph"], |
| 59 | + "absMin": 6.0, |
| 60 | + "absMax": 8.0, |
| 61 | + "resolution": 0.1 |
| 62 | + }, |
| 63 | + "PDPR1H1HAW100_FW539187_w_1switch123": { |
| 64 | + "current": "O" |
| 65 | + }, |
| 66 | + "PDPR1H1HAW100_FW539187_w_1select456": { |
| 67 | + "current": "0" |
| 68 | + }, |
| 69 | + "PDPR1H1HAW100_FW539187_w_1label789": { |
| 70 | + "current": "|PDPR1H1HAW100_FW539187_LABEL_w_1eklg44ro_ALCALYNE|", |
| 71 | + "magnitude": ["undefined"] |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | +@pytest.fixture |
| 77 | +def mock_mapping(): |
| 78 | + """Create mock mapping configuration.""" |
| 79 | + return { |
| 80 | + "temperature": { |
| 81 | + "type": "sensor", |
| 82 | + "key": "w_1eommf39k" |
| 83 | + }, |
| 84 | + "ph": { |
| 85 | + "type": "sensor", |
| 86 | + "key": "w_1eomog123" |
| 87 | + }, |
| 88 | + "target_ph": { |
| 89 | + "type": "number", |
| 90 | + "key": "w_1eomph456" |
| 91 | + }, |
| 92 | + "pump_switch": { |
| 93 | + "type": "switch", |
| 94 | + "key": "w_1switch123" |
| 95 | + }, |
| 96 | + "water_unit": { |
| 97 | + "type": "select", |
| 98 | + "key": "w_1select456", |
| 99 | + "options": { |
| 100 | + "0": "PDPR1H1HAW100_FW539187_COMBO_w_1eklinki6_M_", |
| 101 | + "1": "PDPR1H1HAW100_FW539187_COMBO_w_1eklinki6_LITER" |
| 102 | + }, |
| 103 | + "conversion": { |
| 104 | + "PDPR1H1HAW100_FW539187_COMBO_w_1eklinki6_M_": "m³", |
| 105 | + "PDPR1H1HAW100_FW539187_COMBO_w_1eklinki6_LITER": "L" |
| 106 | + } |
| 107 | + }, |
| 108 | + "ph_type_dosing": { |
| 109 | + "type": "sensor", |
| 110 | + "key": "w_1label789", |
| 111 | + "conversion": { |
| 112 | + "|PDPR1H1HAW100_FW539187_LABEL_w_1eklg44ro_ALCALYNE|": "alcalyne" |
| 113 | + } |
| 114 | + }, |
| 115 | + "alarm_ph": { |
| 116 | + "type": "binary_sensor", |
| 117 | + "key": "w_1switch123" |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + |
| 122 | +@pytest.fixture |
| 123 | +def mock_raw_data(): |
| 124 | + """Create mock raw device data for client tests.""" |
| 125 | + return { |
| 126 | + "devicedata": { |
| 127 | + "TEST123_DEVICE": { |
| 128 | + "PDPR1H1HAW100_FW539187_w_1eommf39k": { |
| 129 | + "current": 25.5, |
| 130 | + "magnitude": ["°C"] |
| 131 | + }, |
| 132 | + "PDPR1H1HAW100_FW539187_w_1eomog123": { |
| 133 | + "current": 7.2, |
| 134 | + "magnitude": ["ph"] |
| 135 | + }, |
| 136 | + "PDPR1H1HAW100_FW539187_w_1eomph456": { |
| 137 | + "current": 7.0, |
| 138 | + "magnitude": ["ph"], |
| 139 | + "absMin": 6.0, |
| 140 | + "absMax": 8.0, |
| 141 | + "resolution": 0.1 |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + |
| 148 | +@pytest.fixture |
| 149 | +def mock_debug_config(): |
| 150 | + """Create mock debug config response.""" |
| 151 | + return { |
| 152 | + "GATEWAY": { |
| 153 | + "DID": "TEST123", |
| 154 | + "NAME": "Test Device", |
| 155 | + "FW_REL": "1.0.0" |
| 156 | + }, |
| 157 | + "DEVICES": [{ |
| 158 | + "DID": "TEST123_DEVICE", |
| 159 | + "NAME": "PDPR1H1HAW100", |
| 160 | + "PRODUCT_CODE": "PDPR1H1HAW100", |
| 161 | + "FW_REL": "1.0.0", |
| 162 | + "FW_CODE": "FW539187" |
| 163 | + }] |
| 164 | + } |
| 165 | + |
| 166 | + |
| 167 | +@pytest.fixture |
| 168 | +def mock_mapping_info(mock_mapping): # pylint: disable=redefined-outer-name |
| 169 | + """Create mock mapping info object.""" |
| 170 | + mapping_info = MagicMock() |
| 171 | + mapping_info.mapping = mock_mapping |
| 172 | + return mapping_info |
| 173 | + |
| 174 | + |
| 175 | +@pytest.fixture |
| 176 | +def instant_values_fixture( # pylint: disable=redefined-outer-name |
| 177 | + mock_device_data, mock_mapping, mock_request_handler |
| 178 | +): |
| 179 | + """Create InstantValues instance for testing.""" |
| 180 | + return InstantValues( |
| 181 | + device_data=mock_device_data, |
| 182 | + mapping=mock_mapping, |
| 183 | + prefix="PDPR1H1HAW100_FW539187_", |
| 184 | + device_id="TEST123_DEVICE", |
| 185 | + request_handler=mock_request_handler |
| 186 | + ) |
| 187 | + |
| 188 | + |
| 189 | +@pytest.fixture |
| 190 | +def mock_structured_data(): |
| 191 | + """Create mock structured data for testing.""" |
| 192 | + return { |
| 193 | + "sensor": { |
| 194 | + "temperature": {"value": 25.5, "unit": "°C"}, |
| 195 | + "ph": {"value": 7.2, "unit": None} |
| 196 | + }, |
| 197 | + "number": { |
| 198 | + "target_ph": {"value": 7.0, "unit": None, "min": 6.0, "max": 8.0, "step": 0.1} |
| 199 | + }, |
| 200 | + "switch": { |
| 201 | + "pump_switch": {"value": True} |
| 202 | + }, |
| 203 | + "binary_sensor": { |
| 204 | + "alarm_ph": {"value": False} |
| 205 | + }, |
| 206 | + "select": { |
| 207 | + "water_unit": {"value": "m³"} |
| 208 | + } |
| 209 | + } |
0 commit comments