88
99from pyvesync import VeSync
1010from pyvesync .utils .errors import VeSyncRateLimitError , VeSyncServerError
11+
1112from pyvesync .const import API_BASE_URL_US
1213from pyvesync .utils .errors import (
1314 VeSyncAPIStatusCodeError
1415 )
16+ import call_json
1517from defaults import TestDefaults
1618from aiohttp_mocker import AiohttpMockSession
1719
20+
1821DEFAULT_ENDPOINT = '/endpoint'
1922DEFAULT_POST_DATA = {'key' : 'value' }
20-
21-
22- def response_dict (code , msg ):
23- """Return a response dictionary."""
24- return {'code' : code , 'msg' : msg }
25-
26-
2723PARAM_ARGS = "endpoint, method, resp_bytes, resp_status"
2824
2925# Successful API calls should return the response in bytes and a 200 status code
30- SUCCESS_RESP = response_dict (0 , 'Success' )
26+ SUCCESS_RESP = call_json . response_body (0 , 'Success' )
3127
3228
3329# Rate limit errors should raise an exception in `async_call_api`
3430RATE_LIMIT_CODE = - 11003000
35- RATE_LIMIT_RESP = response_dict (RATE_LIMIT_CODE , "Rate limit exceeded" )
31+ RATE_LIMIT_RESP = call_json . response_body (RATE_LIMIT_CODE , "Rate limit exceeded" )
3632
3733
3834# Server errors should raise an exception in `async_call_api`
3935SERVER_ERROR = - 11102000
40- SERVER_ERROR_RESP = response_dict (SERVER_ERROR , "Server error" )
36+ SERVER_ERROR_RESP = call_json . response_body (SERVER_ERROR , "Server error" )
4137
4238
4339# Status code errors should raise an exception in `async_call_api`
@@ -53,7 +49,7 @@ def response_dict(code, msg):
5349# Device errors should return the response and a 200 status code
5450# with no exception thrown by `async_call_api`
5551DEVICE_ERROR_CODE = - 11901000
56- DEVICE_ERROR_RESP = response_dict (DEVICE_ERROR_CODE , "Device error" )
52+ DEVICE_ERROR_RESP = call_json . response_body (DEVICE_ERROR_CODE , "Device error" )
5753
5854
5955class TestApiFunc :
@@ -75,10 +71,6 @@ def setup(self, caplog):
7571 self .caplog = caplog
7672 self .caplog .set_level (logging .DEBUG )
7773 self .loop = asyncio .new_event_loop ()
78- # self.mock_api = self.mock_api_call.start()
79- # self.mock_api.return_value.ok = True
80- # self.mock = aioresponses()
81- # self.mock.start()
8274 self .mock = MagicMock ()
8375 self .manager = VeSync ('EMAIL' , 'PASSWORD' )
8476 self .manager .verbose = True
@@ -116,7 +108,7 @@ def test_api_success(self, mock):
116108 @patch ("pyvesync.vesync.ClientSession" )
117109 def test_api_rate_limit (self , mock ):
118110 """Test rate limit error - raises `VeSyncRateLimitError` from `VeSync.async_call_api`."""
119- rate_limit_resp = response_dict (RATE_LIMIT_CODE , "Rate limit exceeded" )
111+ rate_limit_resp = call_json . response_body (RATE_LIMIT_CODE , "Rate limit exceeded" )
120112 mock .return_value .request .return_value = AiohttpMockSession (
121113 method = "post" ,
122114 url = API_BASE_URL_US + DEFAULT_ENDPOINT ,
0 commit comments