From adc6718d17b9406e89a8011e5f95d5216a55edeb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Mar 2020 03:51:50 +0000 Subject: [PATCH] Fix validation code verification passing login_method as a string instead of a var --- august/api_common.py | 2 +- setup.py | 2 +- tests/test_api_async.py | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/august/api_common.py b/august/api_common.py index c187d5b..5799f45 100644 --- a/august/api_common.py +++ b/august/api_common.py @@ -171,7 +171,7 @@ def _build_validate_verification_code_request( "method": "post", "url": API_VALIDATE_VERIFICATION_CODE_URLS[login_method], "access_token": access_token, - "json": {"login_method": username, "code": str(verification_code)}, + "json": {login_method: username, "code": str(verification_code)}, } def _build_get_doorbells_request(self, access_token): diff --git a/setup.py b/setup.py index 40bea82..27cab15 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="py-august", - version="0.24.0", + version="0.25.0", packages=["august"], url="https://github.com/snjoetw/py-august", license="MIT", diff --git a/tests/test_api_async.py b/tests/test_api_async.py index 7c4e34f..3a15986 100644 --- a/tests/test_api_async.py +++ b/tests/test_api_async.py @@ -3,12 +3,13 @@ from aiohttp import ClientError, ClientResponse, ClientSession from aiohttp.helpers import TimerNoop -from aioresponses import aioresponses +from aioresponses import aioresponses, CallbackResult import aiounittest from asynctest import mock import august.activity from august.api_async import ApiAsync, _raise_response_exceptions from august.api_common import ( + API_VALIDATE_VERIFICATION_CODE_URLS, API_GET_DOORBELL_URL, API_GET_DOORBELLS_URL, API_GET_HOUSE_ACTIVITIES_URL, @@ -698,6 +699,24 @@ async def test_async_get_house_activities(self, mock): self.assertIsInstance(activities[8], august.activity.LockOperationActivity) self.assertIsInstance(activities[9], august.activity.LockOperationActivity) + @aioresponses() + async def test_async_validate_verification_code(self, mock): + last_args = {} + + def response_callback(url, **kwargs): + last_args.update(kwargs) + return CallbackResult(status=200, body="{}") + + mock.post( + API_VALIDATE_VERIFICATION_CODE_URLS["email"], callback=response_callback + ) + + api = ApiAsync(ClientSession()) + await api.async_validate_verification_code( + ACCESS_TOKEN, "email", "emailaddress", 123456 + ) + assert last_args["json"] == {"code": "123456", "email": "emailaddress"} + def test__raise_response_exceptions(self): loop = mock.Mock() request_info = mock.Mock()