mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-20 01:09:36 +08:00
Compare commits
No commits in common. "5499320723ad10933da398848c123accf36e4d38" and "75a00734da41494a8cda8d9e7b607974574c0913" have entirely different histories.
5499320723
...
75a00734da
@ -1,10 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""Pytest fixtures."""
|
"""Pytest fixtures."""
|
||||||
import random
|
|
||||||
import shutil
|
import shutil
|
||||||
import pytest
|
import pytest
|
||||||
from os import path, makedirs
|
from os import path, makedirs
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
TEST_ROOT_PATH: str = path.dirname(path.abspath(__file__))
|
TEST_ROOT_PATH: str = path.dirname(path.abspath(__file__))
|
||||||
TEST_FILES_PATH: str = path.join(TEST_ROOT_PATH, 'miot')
|
TEST_FILES_PATH: str = path.join(TEST_ROOT_PATH, 'miot')
|
||||||
@ -12,6 +10,8 @@ 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,14 +107,12 @@ def test_uid() -> str:
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def test_random_did() -> str:
|
def test_random_did() -> str:
|
||||||
# Gen random did
|
return TEST_RANDOM_DID
|
||||||
return str(random.getrandbits(64))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def test_uuid() -> str:
|
def test_uuid() -> str:
|
||||||
# Gen uuid
|
return TEST_UUID
|
||||||
return uuid4().hex
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
|
|||||||
@ -11,28 +11,20 @@ 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: str,
|
test_cache_path, test_cloud_server, test_oauth2_redirect_url,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_uuid
|
||||||
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=uuid)
|
uuid=test_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)
|
||||||
@ -62,10 +54,6 @@ 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)
|
||||||
@ -79,10 +67,9 @@ 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_cache_path: str, test_cloud_server: str,
|
||||||
test_cloud_server: str,
|
test_oauth2_redirect_url: str, test_domain_oauth2: str,
|
||||||
test_oauth2_redirect_url: str,
|
test_uuid: 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
|
||||||
@ -90,9 +77,6 @@ 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)
|
||||||
@ -106,7 +90,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=uuid)
|
uuid=test_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(
|
||||||
@ -128,9 +112,7 @@ 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: str,
|
test_cache_path, test_cloud_server, test_domain_oauth2
|
||||||
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
|
||||||
@ -155,10 +137,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: str,
|
test_cache_path,
|
||||||
test_cloud_server: str,
|
test_cloud_server,
|
||||||
test_domain_oauth2: str,
|
test_domain_oauth2,
|
||||||
test_domain_user_info: str
|
test_domain_user_info
|
||||||
):
|
):
|
||||||
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
|
||||||
@ -186,10 +168,8 @@ 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: str,
|
test_cache_path, test_cloud_server,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_domain_user_info
|
||||||
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
|
||||||
@ -231,10 +211,8 @@ 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: str,
|
test_cache_path, test_cloud_server,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_domain_user_info
|
||||||
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
|
||||||
@ -282,10 +260,8 @@ 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: str,
|
test_cache_path, test_cloud_server,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_domain_user_info
|
||||||
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
|
||||||
@ -319,10 +295,8 @@ 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: str,
|
test_cache_path, test_cloud_server,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_domain_user_info
|
||||||
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
|
||||||
@ -355,10 +329,8 @@ 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: str,
|
test_cache_path, test_cloud_server,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_domain_user_info
|
||||||
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
|
||||||
@ -392,10 +364,8 @@ 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: str,
|
test_cache_path, test_cloud_server,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_domain_user_info
|
||||||
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
|
||||||
@ -442,10 +412,8 @@ 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: str,
|
test_cache_path, test_cloud_server,
|
||||||
test_cloud_server: str,
|
test_domain_oauth2, test_domain_user_info
|
||||||
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