Skip to content

Commit

Permalink
optimize test test_async_get_led_setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Bong authored and Markus Bong committed Aug 28, 2020
1 parent 452d901 commit 7a24a69
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions tests/test_deviceapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@

import pytest
from asynctest import CoroutineMock
from httpx import AsyncClient, Client, Response
from google.protobuf.json_format import MessageToDict
from httpx import AsyncClient, Response

from devolo_plc_api.device_api.deviceapi import DeviceApi
from devolo_plc_api.device_api.devolo_idl_proto_deviceapi_ledsettings_pb2 import LedSettingsGet


class TestDeviceApi:

@pytest.mark.asyncio
async def test_async_get_led_setting(self, request):
ip = request.cls.ip
session = AsyncClient()
path = request.cls.device_info['_dvl-deviceapi._tcp.local.']['Path']
version = request.cls.device_info['_dvl-deviceapi._tcp.local.']['Version']
features = "led"
password = "password"

with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=CoroutineMock(return_value=Response)), \
patch("httpx.Response.aread", new=CoroutineMock(return_value=b"")):
device_api = DeviceApi(ip, session, path, version, features, password)
device_api = DeviceApi(request.cls.ip,
AsyncClient(),
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Path'],
request.cls.device_info['_dvl-deviceapi._tcp.local.']['Version'],
"led",
"password")
led_setting = await device_api.async_get_led_setting()

assert led_setting['state'] == "LED_ON"
assert led_setting == MessageToDict(LedSettingsGet(),
including_default_value_fields=True,
preserving_proto_field_name=True)

0 comments on commit 7a24a69

Please sign in to comment.