mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-17 23:50:42 +08:00
feat: use random value replace uuid, random_did
This commit is contained in:
parent
75a00734da
commit
9b15482a15
@ -10,8 +10,6 @@ TEST_CACHE_PATH: str = path.join(TEST_ROOT_PATH, 'test_cache')
|
|||||||
TEST_OAUTH2_REDIRECT_URL: str = 'http://homeassistant.local:8123'
|
TEST_OAUTH2_REDIRECT_URL: str = 'http://homeassistant.local:8123'
|
||||||
TEST_LANG: str = 'zh-Hans'
|
TEST_LANG: str = 'zh-Hans'
|
||||||
TEST_UID: str = '123456789'
|
TEST_UID: str = '123456789'
|
||||||
TEST_RANDOM_DID: str = '6720871318229644562'
|
|
||||||
TEST_UUID: str = '8b06ba169c304b788a37bdc3f1210bb1'
|
|
||||||
TEST_CLOUD_SERVER: str = 'cn'
|
TEST_CLOUD_SERVER: str = 'cn'
|
||||||
|
|
||||||
DOMAIN_OAUTH2: str = 'oauth2_info'
|
DOMAIN_OAUTH2: str = 'oauth2_info'
|
||||||
@ -107,12 +105,14 @@ def test_uid() -> str:
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def test_random_did() -> str:
|
def test_random_did() -> str:
|
||||||
return TEST_RANDOM_DID
|
# Gen random did
|
||||||
|
return str(random.getrandbits(64))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def test_uuid() -> str:
|
def test_uuid() -> str:
|
||||||
return TEST_UUID
|
# Gen uuid
|
||||||
|
return uuid4().hex
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
|
|||||||
@ -11,20 +11,28 @@ import pytest
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_oauth_async(
|
async def test_miot_oauth_async(
|
||||||
test_cache_path, test_cloud_server, test_oauth2_redirect_url,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_uuid
|
test_cloud_server: str,
|
||||||
|
test_oauth2_redirect_url: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_uuid: str
|
||||||
) -> dict:
|
) -> dict:
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTOauthClient
|
from miot.miot_cloud import MIoTOauthClient
|
||||||
from miot.miot_storage import MIoTStorage
|
from miot.miot_storage import MIoTStorage
|
||||||
print('') # separate from previous output
|
print('') # separate from previous output
|
||||||
|
|
||||||
|
miot_storage = MIoTStorage(test_cache_path)
|
||||||
|
local_uuid = await miot_storage.load_async(
|
||||||
|
domain=test_domain_oauth2, name=f'{test_cloud_server}_uuid', type_=str)
|
||||||
|
uuid = str(local_uuid or test_uuid)
|
||||||
|
print(f'uuid: {uuid}')
|
||||||
miot_oauth = MIoTOauthClient(
|
miot_oauth = MIoTOauthClient(
|
||||||
client_id=OAUTH2_CLIENT_ID,
|
client_id=OAUTH2_CLIENT_ID,
|
||||||
redirect_url=test_oauth2_redirect_url,
|
redirect_url=test_oauth2_redirect_url,
|
||||||
cloud_server=test_cloud_server,
|
cloud_server=test_cloud_server,
|
||||||
uuid=test_uuid)
|
uuid=uuid)
|
||||||
miot_storage = MIoTStorage(test_cache_path)
|
|
||||||
oauth_info = None
|
oauth_info = None
|
||||||
load_info = await miot_storage.load_async(
|
load_info = await miot_storage.load_async(
|
||||||
domain=test_domain_oauth2, name=test_cloud_server, type_=dict)
|
domain=test_domain_oauth2, name=test_cloud_server, type_=dict)
|
||||||
@ -54,6 +62,10 @@ async def test_miot_oauth_async(
|
|||||||
test_domain_oauth2, test_cloud_server, oauth_info)
|
test_domain_oauth2, test_cloud_server, oauth_info)
|
||||||
assert rc
|
assert rc
|
||||||
print('save oauth info')
|
print('save oauth info')
|
||||||
|
rc = await miot_storage.save_async(
|
||||||
|
test_domain_oauth2, f'{test_cloud_server}_uuid', uuid)
|
||||||
|
assert rc
|
||||||
|
print('save uuid')
|
||||||
|
|
||||||
access_token = oauth_info.get('access_token', None)
|
access_token = oauth_info.get('access_token', None)
|
||||||
assert isinstance(access_token, str)
|
assert isinstance(access_token, str)
|
||||||
@ -67,9 +79,10 @@ async def test_miot_oauth_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency(on=['test_miot_oauth_async'])
|
@pytest.mark.dependency(on=['test_miot_oauth_async'])
|
||||||
async def test_miot_oauth_refresh_token(
|
async def test_miot_oauth_refresh_token(
|
||||||
test_cache_path: str, test_cloud_server: str,
|
test_cache_path: str,
|
||||||
test_oauth2_redirect_url: str, test_domain_oauth2: str,
|
test_cloud_server: str,
|
||||||
test_uuid: str
|
test_oauth2_redirect_url: str,
|
||||||
|
test_domain_oauth2: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTOauthClient
|
from miot.miot_cloud import MIoTOauthClient
|
||||||
@ -77,6 +90,9 @@ async def test_miot_oauth_refresh_token(
|
|||||||
print('') # separate from previous output
|
print('') # separate from previous output
|
||||||
|
|
||||||
miot_storage = MIoTStorage(test_cache_path)
|
miot_storage = MIoTStorage(test_cache_path)
|
||||||
|
uuid = await miot_storage.load_async(
|
||||||
|
domain=test_domain_oauth2, name=f'{test_cloud_server}_uuid', type_=str)
|
||||||
|
assert isinstance(uuid, str)
|
||||||
oauth_info = await miot_storage.load_async(
|
oauth_info = await miot_storage.load_async(
|
||||||
domain=test_domain_oauth2, name=test_cloud_server, type_=dict)
|
domain=test_domain_oauth2, name=test_cloud_server, type_=dict)
|
||||||
assert isinstance(oauth_info, dict)
|
assert isinstance(oauth_info, dict)
|
||||||
@ -90,7 +106,7 @@ async def test_miot_oauth_refresh_token(
|
|||||||
client_id=OAUTH2_CLIENT_ID,
|
client_id=OAUTH2_CLIENT_ID,
|
||||||
redirect_url=test_oauth2_redirect_url,
|
redirect_url=test_oauth2_redirect_url,
|
||||||
cloud_server=test_cloud_server,
|
cloud_server=test_cloud_server,
|
||||||
uuid=test_uuid)
|
uuid=uuid)
|
||||||
refresh_token = oauth_info.get('refresh_token', None)
|
refresh_token = oauth_info.get('refresh_token', None)
|
||||||
assert refresh_token
|
assert refresh_token
|
||||||
update_info = await miot_oauth.refresh_access_token_async(
|
update_info = await miot_oauth.refresh_access_token_async(
|
||||||
@ -112,7 +128,9 @@ async def test_miot_oauth_refresh_token(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_get_nickname_async(
|
async def test_miot_cloud_get_nickname_async(
|
||||||
test_cache_path, test_cloud_server, test_domain_oauth2
|
test_cache_path: str,
|
||||||
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTHttpClient
|
from miot.miot_cloud import MIoTHttpClient
|
||||||
@ -137,10 +155,10 @@ async def test_miot_cloud_get_nickname_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_get_uid_async(
|
async def test_miot_cloud_get_uid_async(
|
||||||
test_cache_path,
|
test_cache_path: str,
|
||||||
test_cloud_server,
|
test_cloud_server: str,
|
||||||
test_domain_oauth2,
|
test_domain_oauth2: str,
|
||||||
test_domain_user_info
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTHttpClient
|
from miot.miot_cloud import MIoTHttpClient
|
||||||
@ -168,8 +186,10 @@ async def test_miot_cloud_get_uid_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_get_homeinfos_async(
|
async def test_miot_cloud_get_homeinfos_async(
|
||||||
test_cache_path, test_cloud_server,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_domain_user_info
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTHttpClient
|
from miot.miot_cloud import MIoTHttpClient
|
||||||
@ -211,8 +231,10 @@ async def test_miot_cloud_get_homeinfos_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_get_devices_async(
|
async def test_miot_cloud_get_devices_async(
|
||||||
test_cache_path, test_cloud_server,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_domain_user_info
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTHttpClient
|
from miot.miot_cloud import MIoTHttpClient
|
||||||
@ -260,8 +282,10 @@ async def test_miot_cloud_get_devices_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_get_devices_with_dids_async(
|
async def test_miot_cloud_get_devices_with_dids_async(
|
||||||
test_cache_path, test_cloud_server,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_domain_user_info
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTHttpClient
|
from miot.miot_cloud import MIoTHttpClient
|
||||||
@ -295,8 +319,10 @@ async def test_miot_cloud_get_devices_with_dids_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_get_prop_async(
|
async def test_miot_cloud_get_prop_async(
|
||||||
test_cache_path, test_cloud_server,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_domain_user_info
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTHttpClient
|
from miot.miot_cloud import MIoTHttpClient
|
||||||
@ -329,8 +355,10 @@ async def test_miot_cloud_get_prop_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_get_props_async(
|
async def test_miot_cloud_get_props_async(
|
||||||
test_cache_path, test_cloud_server,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_domain_user_info
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
from miot.const import OAUTH2_CLIENT_ID
|
from miot.const import OAUTH2_CLIENT_ID
|
||||||
from miot.miot_cloud import MIoTHttpClient
|
from miot.miot_cloud import MIoTHttpClient
|
||||||
@ -364,8 +392,10 @@ async def test_miot_cloud_get_props_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_set_prop_async(
|
async def test_miot_cloud_set_prop_async(
|
||||||
test_cache_path, test_cloud_server,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_domain_user_info
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
WARNING: This test case will control the actual device and is not enabled
|
WARNING: This test case will control the actual device and is not enabled
|
||||||
@ -412,8 +442,10 @@ async def test_miot_cloud_set_prop_async(
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.dependency()
|
@pytest.mark.dependency()
|
||||||
async def test_miot_cloud_action_async(
|
async def test_miot_cloud_action_async(
|
||||||
test_cache_path, test_cloud_server,
|
test_cache_path: str,
|
||||||
test_domain_oauth2, test_domain_user_info
|
test_cloud_server: str,
|
||||||
|
test_domain_oauth2: str,
|
||||||
|
test_domain_user_info: str
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
WARNING: This test case will control the actual device and is not enabled
|
WARNING: This test case will control the actual device and is not enabled
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user