File: conftest.py

package info (click to toggle)
python-actron-neo-api 0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 340 kB
  • sloc: python: 2,439; makefile: 3
file content (171 lines) | stat: -rw-r--r-- 5,639 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""Shared fixtures for ActronNeoAPI tests."""

from typing import Any, Dict
from unittest.mock import AsyncMock, MagicMock

import pytest


# Sample API Response Fixtures
@pytest.fixture
def sample_system_neo() -> Dict[str, Any]:
    """Sample AC system response for Neo platform."""
    return {
        "serial": "abc123",
        "type": "standard",
        "_links": {
            "ac-status": {"href": "/api/v0/client/ac-systems/abc123/status"},
            "commands": {"href": "/api/v0/client/ac-systems/abc123/commands"},
        },
    }


@pytest.fixture
def sample_system_que_nxgen() -> Dict[str, Any]:
    """Sample AC system response with NX Gen type (Que platform)."""
    return {
        "serial": "xyz789",
        "type": "NX-Gen",
        "_links": {
            "ac-status": {"href": "/api/v0/client/ac-systems/xyz789/status"},
            "commands": {"href": "/api/v0/client/ac-systems/xyz789/commands"},
        },
    }


@pytest.fixture
def sample_systems_response_neo(sample_system_neo) -> Dict[str, Any]:
    """Sample get_ac_systems response for Neo platform."""
    return {"_embedded": {"ac-system": [sample_system_neo]}}


@pytest.fixture
def sample_systems_response_que(sample_system_que_nxgen) -> Dict[str, Any]:
    """Sample get_ac_systems response with NX Gen system."""
    return {"_embedded": {"ac-system": [sample_system_que_nxgen]}}


@pytest.fixture
def sample_status_full() -> Dict[str, Any]:
    """Sample full status response with all data."""
    return {
        "isOnline": True,
        "lastKnownState": {
            "AirconSystem": {
                "MasterWCModel": "WC2",
                "MasterSerial": "ABC123",
                "MasterWCFirmwareVersion": "1.2.3",
            },
            "UserAirconSettings": {
                "isOn": True,
                "Mode": "COOL",
                "FanMode": "AUTO",
                "AwayMode": False,
                "TemperatureSetpoint_Cool_oC": 24.0,
                "TemperatureSetpoint_Heat_oC": 20.0,
                "EnabledZones": [True, False, True, False, False, False, False, False],
                "QuietModeEnabled": False,
                "TurboMode": {"Enabled": False, "Supported": True},
            },
            "MasterInfo": {
                "LiveTemp_oC": 22.5,
                "LiveHumidity_pc": 55.0,
                "LiveOutdoorTemp_oC": 28.0,
            },
            "LiveAircon": {
                "SystemOn": True,
                "CompressorMode": "COOL",
                "CompressorCapacity": 75,
                "FanRPM": 450,
                "Defrost": False,
                "CompressorChasingTemperature": 24.0,
                "CompressorLiveTemperature": 22.5,
                "OutdoorUnit": {
                    "ModelNumber": "OU123",
                    "SerialNumber": "OU456",
                    "CompSpeed": 65.5,
                    "CompPower": 2500,
                    "CompRunningPWM": 70,
                    "CompressorOn": True,
                },
            },
            "Alerts": {"CleanFilter": False, "Defrosting": False},
            "RemoteZoneInfo": [
                {
                    "CanOperate": True,
                    "CommonZone": False,
                    "LiveHumidity_pc": 55.0,
                    "LiveTemp_oC": 22.5,
                    "ZonePosition": 100.0,
                    "NV_Title": "Living Room",
                    "NV_Exists": True,
                    "TemperatureSetpoint_Cool_oC": 24.0,
                    "TemperatureSetpoint_Heat_oC": 20.0,
                    "Sensors": {},
                },
            ],
            "NV_Limits": {
                "UserSetpoint_oC": {
                    "setCool_Min": 16.0,
                    "setCool_Max": 32.0,
                    "setHeat_Min": 10.0,
                    "setHeat_Max": 30.0,
                }
            },
        },
    }


@pytest.fixture
def sample_command_response() -> Dict[str, Any]:
    """Sample command response."""
    return {"success": True, "message": "Command executed"}


# Mock OAuth2 Fixtures
@pytest.fixture
def mock_oauth():
    """Mock OAuth2 authentication handler."""
    oauth = MagicMock()
    oauth.access_token = "test_access_token"
    oauth.refresh_token = "test_refresh_token"
    oauth.token_type = "Bearer"
    oauth.is_token_valid = True
    oauth.is_token_expiring_soon = False
    oauth.authenticated_platform = "https://nimbus.actronair.com.au"
    oauth.authorization_header = {"Authorization": "Bearer test_access_token"}
    oauth.ensure_token_valid = AsyncMock(return_value="test_access_token")
    oauth.refresh_access_token = AsyncMock(return_value=("test_access_token", 1234567890.0))
    return oauth


# Mock API Response Fixtures
@pytest.fixture
def mock_aiohttp_response():
    """Factory for creating mock aiohttp responses."""

    def _create_response(status=200, json_data=None, text=""):
        mock_resp = AsyncMock()
        mock_resp.status = status
        mock_resp.json = AsyncMock(return_value=json_data or {})
        mock_resp.text = AsyncMock(return_value=text)
        return mock_resp

    return _create_response


@pytest.fixture
def mock_session(mock_aiohttp_response):
    """Mock aiohttp ClientSession."""
    session = MagicMock()
    session.closed = False
    session.close = AsyncMock()

    # Create async context manager for request()
    mock_ctx = MagicMock()
    mock_ctx.__aenter__ = AsyncMock(return_value=mock_aiohttp_response(status=200, json_data={}))
    mock_ctx.__aexit__ = AsyncMock(return_value=False)

    session.request = MagicMock(return_value=mock_ctx)

    return session