Compare commits

..

No commits in common. "5499320723ad10933da398848c123accf36e4d38" and "75a00734da41494a8cda8d9e7b607974574c0913" have entirely different histories.

2 changed files with 31 additions and 65 deletions

View File

@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
"""Pytest fixtures."""
import random
import shutil
import pytest
from os import path, makedirs
from uuid import uuid4
TEST_ROOT_PATH: str = path.dirname(path.abspath(__file__))
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_LANG: str = 'zh-Hans'
TEST_UID: str = '123456789'
TEST_RANDOM_DID: str = '6720871318229644562'
TEST_UUID: str = '8b06ba169c304b788a37bdc3f1210bb1'
TEST_CLOUD_SERVER: str = 'cn'
DOMAIN_OAUTH2: str = 'oauth2_info'
@ -107,14 +107,12 @@ def test_uid() -> str:
@pytest.fixture(scope='session')
def test_random_did() -> str:
# Gen random did
return str(random.getrandbits(64))
return TEST_RANDOM_DID
@pytest.fixture(scope='session')
def test_uuid() -> str:
# Gen uuid
return uuid4().hex
return TEST_UUID
@pytest.fixture(scope='session')

View File

@ -11,28 +11,20 @@ import pytest
@pytest.mark.asyncio
@pytest.mark.dependency()
async def test_miot_oauth_async(
test_cache_path: str,
test_cloud_server: str,
test_oauth2_redirect_url: str,
test_domain_oauth2: str,
test_uuid: str
test_cache_path, test_cloud_server, test_oauth2_redirect_url,
test_domain_oauth2, test_uuid
) -> dict:
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTOauthClient
from miot.miot_storage import MIoTStorage
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(
client_id=OAUTH2_CLIENT_ID,
redirect_url=test_oauth2_redirect_url,
cloud_server=test_cloud_server,
uuid=uuid)
uuid=test_uuid)
miot_storage = MIoTStorage(test_cache_path)
oauth_info = None
load_info = await miot_storage.load_async(
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)
assert rc
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)
assert isinstance(access_token, str)
@ -79,10 +67,9 @@ async def test_miot_oauth_async(
@pytest.mark.asyncio
@pytest.mark.dependency(on=['test_miot_oauth_async'])
async def test_miot_oauth_refresh_token(
test_cache_path: str,
test_cloud_server: str,
test_oauth2_redirect_url: str,
test_domain_oauth2: str
test_cache_path: str, test_cloud_server: str,
test_oauth2_redirect_url: str, test_domain_oauth2: str,
test_uuid: str
):
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTOauthClient
@ -90,9 +77,6 @@ async def test_miot_oauth_refresh_token(
print('') # separate from previous output
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(
domain=test_domain_oauth2, name=test_cloud_server, type_=dict)
assert isinstance(oauth_info, dict)
@ -106,7 +90,7 @@ async def test_miot_oauth_refresh_token(
client_id=OAUTH2_CLIENT_ID,
redirect_url=test_oauth2_redirect_url,
cloud_server=test_cloud_server,
uuid=uuid)
uuid=test_uuid)
refresh_token = oauth_info.get('refresh_token', None)
assert refresh_token
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.dependency()
async def test_miot_cloud_get_nickname_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str
test_cache_path, test_cloud_server, test_domain_oauth2
):
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTHttpClient
@ -155,10 +137,10 @@ async def test_miot_cloud_get_nickname_async(
@pytest.mark.asyncio
@pytest.mark.dependency()
async def test_miot_cloud_get_uid_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path,
test_cloud_server,
test_domain_oauth2,
test_domain_user_info
):
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTHttpClient
@ -186,10 +168,8 @@ async def test_miot_cloud_get_uid_async(
@pytest.mark.asyncio
@pytest.mark.dependency()
async def test_miot_cloud_get_homeinfos_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path, test_cloud_server,
test_domain_oauth2, test_domain_user_info
):
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTHttpClient
@ -231,10 +211,8 @@ async def test_miot_cloud_get_homeinfos_async(
@pytest.mark.asyncio
@pytest.mark.dependency()
async def test_miot_cloud_get_devices_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path, test_cloud_server,
test_domain_oauth2, test_domain_user_info
):
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTHttpClient
@ -282,10 +260,8 @@ async def test_miot_cloud_get_devices_async(
@pytest.mark.asyncio
@pytest.mark.dependency()
async def test_miot_cloud_get_devices_with_dids_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path, test_cloud_server,
test_domain_oauth2, test_domain_user_info
):
from miot.const import OAUTH2_CLIENT_ID
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.dependency()
async def test_miot_cloud_get_prop_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path, test_cloud_server,
test_domain_oauth2, test_domain_user_info
):
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTHttpClient
@ -355,10 +329,8 @@ async def test_miot_cloud_get_prop_async(
@pytest.mark.asyncio
@pytest.mark.dependency()
async def test_miot_cloud_get_props_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path, test_cloud_server,
test_domain_oauth2, test_domain_user_info
):
from miot.const import OAUTH2_CLIENT_ID
from miot.miot_cloud import MIoTHttpClient
@ -392,10 +364,8 @@ async def test_miot_cloud_get_props_async(
@pytest.mark.asyncio
@pytest.mark.dependency()
async def test_miot_cloud_set_prop_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path, test_cloud_server,
test_domain_oauth2, test_domain_user_info
):
"""
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.dependency()
async def test_miot_cloud_action_async(
test_cache_path: str,
test_cloud_server: str,
test_domain_oauth2: str,
test_domain_user_info: str
test_cache_path, test_cloud_server,
test_domain_oauth2, test_domain_user_info
):
"""
WARNING: This test case will control the actual device and is not enabled