From e68bd0457c0a6f8f96c085a98e8fcf8947ebd2fd Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 26 May 2017 13:12:17 -0700 Subject: [PATCH] Fix more deprecation warnings (#7778) * Remove setting up an hbmqtt broker * Don't pass loop to web.Application in tests * Use .query instead of deprecated .GET for aiohttp requests * Fix closing file resource * Do not use asyncio mark * Notify.html5 - PyJWT: Use options to disable verify * Yamaha: Test was still using deprecated ip * Remove pytest-asyncio --- homeassistant/components/api.py | 2 +- homeassistant/components/binary_sensor/mystrom.py | 2 +- homeassistant/components/camera/__init__.py | 2 +- homeassistant/components/device_tracker/gpslogger.py | 2 +- homeassistant/components/device_tracker/locative.py | 2 +- homeassistant/components/history.py | 4 ++-- homeassistant/components/http/auth.py | 4 ++-- homeassistant/components/media_player/__init__.py | 2 +- homeassistant/components/media_player/spotify.py | 2 +- homeassistant/components/notify/html5.py | 2 +- homeassistant/components/sensor/fitbit.py | 2 +- homeassistant/components/sensor/torque.py | 2 +- homeassistant/components/switch/netio.py | 2 +- requirements_test.txt | 1 - requirements_test_all.txt | 1 - tests/common.py | 2 +- tests/components/device_tracker/test_mqtt_json.py | 3 --- tests/components/media_player/test_yamaha.py | 2 +- tests/components/notify/test_command_line.py | 6 +++--- tests/test_config.py | 3 ++- 20 files changed, 22 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index 8beb737ae89..b722fc6ebb4 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -83,7 +83,7 @@ class APIEventStream(HomeAssistantView): stop_obj = object() to_write = asyncio.Queue(loop=hass.loop) - restrict = request.GET.get('restrict') + restrict = request.query.get('restrict') if restrict: restrict = restrict.split(',') + [EVENT_HOMEASSISTANT_STOP] diff --git a/homeassistant/components/binary_sensor/mystrom.py b/homeassistant/components/binary_sensor/mystrom.py index c551a8c4efe..08ab1f4a8b7 100644 --- a/homeassistant/components/binary_sensor/mystrom.py +++ b/homeassistant/components/binary_sensor/mystrom.py @@ -38,7 +38,7 @@ class MyStromView(HomeAssistantView): @asyncio.coroutine def get(self, request): """The GET request received from a myStrom button.""" - res = yield from self._handle(request.app['hass'], request.GET) + res = yield from self._handle(request.app['hass'], request.query) return res @asyncio.coroutine diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index d33dc996afd..7c21b99ddda 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -241,7 +241,7 @@ class CameraView(HomeAssistantView): return web.Response(status=status) authenticated = (request[KEY_AUTHENTICATED] or - request.GET.get('token') in camera.access_tokens) + request.query.get('token') in camera.access_tokens) if not authenticated: return web.Response(status=401) diff --git a/homeassistant/components/device_tracker/gpslogger.py b/homeassistant/components/device_tracker/gpslogger.py index 81961b13f7f..b88245ac9a5 100644 --- a/homeassistant/components/device_tracker/gpslogger.py +++ b/homeassistant/components/device_tracker/gpslogger.py @@ -39,7 +39,7 @@ class GPSLoggerView(HomeAssistantView): @asyncio.coroutine def get(self, request): """Handle for GPSLogger message received as GET.""" - res = yield from self._handle(request.app['hass'], request.GET) + res = yield from self._handle(request.app['hass'], request.query) return res @asyncio.coroutine diff --git a/homeassistant/components/device_tracker/locative.py b/homeassistant/components/device_tracker/locative.py index b41326c4192..ced24edde48 100644 --- a/homeassistant/components/device_tracker/locative.py +++ b/homeassistant/components/device_tracker/locative.py @@ -41,7 +41,7 @@ class LocativeView(HomeAssistantView): @asyncio.coroutine def get(self, request): """Locative message received as GET.""" - res = yield from self._handle(request.app['hass'], request.GET) + res = yield from self._handle(request.app['hass'], request.query) return res @asyncio.coroutine diff --git a/homeassistant/components/history.py b/homeassistant/components/history.py index 5a960ae894b..8faf8f30b1d 100644 --- a/homeassistant/components/history.py +++ b/homeassistant/components/history.py @@ -223,7 +223,7 @@ class HistoryPeriodView(HomeAssistantView): if start_time > now: return self.json([]) - end_time = request.GET.get('end_time') + end_time = request.query.get('end_time') if end_time: end_time = dt_util.as_utc( dt_util.parse_datetime(end_time)) @@ -231,7 +231,7 @@ class HistoryPeriodView(HomeAssistantView): return self.json_message('Invalid end_time', HTTP_BAD_REQUEST) else: end_time = start_time + one_day - entity_id = request.GET.get('filter_entity_id') + entity_id = request.query.get('filter_entity_id') result = yield from request.app['hass'].async_add_job( get_significant_states, request.app['hass'], start_time, end_time, diff --git a/homeassistant/components/http/auth.py b/homeassistant/components/http/auth.py index 2a0413e9dbc..a00da9ee5b6 100644 --- a/homeassistant/components/http/auth.py +++ b/homeassistant/components/http/auth.py @@ -37,8 +37,8 @@ def auth_middleware(app, handler): # A valid auth header has been set authenticated = True - elif (DATA_API_PASSWORD in request.GET and - validate_password(request, request.GET[DATA_API_PASSWORD])): + elif (DATA_API_PASSWORD in request.query and + validate_password(request, request.query[DATA_API_PASSWORD])): authenticated = True elif is_trusted_ip(request): diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 47d018d0849..e17935814cc 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -947,7 +947,7 @@ class MediaPlayerImageView(HomeAssistantView): return web.Response(status=status) authenticated = (request[KEY_AUTHENTICATED] or - request.GET.get('token') == player.access_token) + request.query.get('token') == player.access_token) if not authenticated: return web.Response(status=401) diff --git a/homeassistant/components/media_player/spotify.py b/homeassistant/components/media_player/spotify.py index 8ceb245eb03..9b9a8c5bb2d 100644 --- a/homeassistant/components/media_player/spotify.py +++ b/homeassistant/components/media_player/spotify.py @@ -110,7 +110,7 @@ class SpotifyAuthCallbackView(HomeAssistantView): def get(self, request): """Receive authorization token.""" hass = request.app['hass'] - self.oauth.get_access_token(request.GET['code']) + self.oauth.get_access_token(request.query['code']) hass.async_add_job(setup_platform, hass, self.config, self.add_devices) diff --git a/homeassistant/components/notify/html5.py b/homeassistant/components/notify/html5.py index 52d2deedcd4..f656fc0a302 100644 --- a/homeassistant/components/notify/html5.py +++ b/homeassistant/components/notify/html5.py @@ -246,7 +246,7 @@ class HTML5PushCallbackView(HomeAssistantView): # 2a. If decode is successful, return the payload. # 2b. If decode is unsuccessful, return a 401. - target_check = jwt.decode(token, verify=False) + target_check = jwt.decode(token, options={'verify_signature': False}) if target_check[ATTR_TARGET] in self.registrations: possible_target = self.registrations[target_check[ATTR_TARGET]] key = possible_target[ATTR_SUBSCRIPTION][ATTR_KEYS][ATTR_AUTH] diff --git a/homeassistant/components/sensor/fitbit.py b/homeassistant/components/sensor/fitbit.py index d976da723d6..80e452e7b37 100644 --- a/homeassistant/components/sensor/fitbit.py +++ b/homeassistant/components/sensor/fitbit.py @@ -299,7 +299,7 @@ class FitbitAuthCallbackView(HomeAssistantView): from oauthlib.oauth2.rfc6749.errors import MissingTokenError hass = request.app['hass'] - data = request.GET + data = request.query response_message = """Fitbit has been successfully authorized! You can close this window now!""" diff --git a/homeassistant/components/sensor/torque.py b/homeassistant/components/sensor/torque.py index acc7958ea7f..3ce277f794b 100644 --- a/homeassistant/components/sensor/torque.py +++ b/homeassistant/components/sensor/torque.py @@ -75,7 +75,7 @@ class TorqueReceiveDataView(HomeAssistantView): def get(self, request): """Handle Torque data request.""" hass = request.app['hass'] - data = request.GET + data = request.query if self.email is not None and self.email != data[SENSOR_EMAIL_FIELD]: return diff --git a/homeassistant/components/switch/netio.py b/homeassistant/components/switch/netio.py index 3351f39eeea..2a72703c5df 100644 --- a/homeassistant/components/switch/netio.py +++ b/homeassistant/components/switch/netio.py @@ -95,7 +95,7 @@ class NetioApiView(HomeAssistantView): def get(self, request, host): """Request handler.""" hass = request.app['hass'] - data = request.GET + data = request.query states, consumptions, cumulated_consumptions, start_dates = \ [], [], [], [] diff --git a/requirements_test.txt b/requirements_test.txt index c2c5cf65f1b..a584e97b5c7 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -8,7 +8,6 @@ pydocstyle==1.1.1 coveralls>=1.1 pytest>=2.9.2 pytest-aiohttp>=0.1.3 -pytest-asyncio>=0.5.0 pytest-cov>=2.3.1 pytest-timeout>=1.2.0 pytest-catchlog>=1.2.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index de96de19214..06acb00af15 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -9,7 +9,6 @@ pydocstyle==1.1.1 coveralls>=1.1 pytest>=2.9.2 pytest-aiohttp>=0.1.3 -pytest-asyncio>=0.5.0 pytest-cov>=2.3.1 pytest-timeout>=1.2.0 pytest-catchlog>=1.2.2 diff --git a/tests/common.py b/tests/common.py index 735b1dfce98..dec5bdac4a4 100644 --- a/tests/common.py +++ b/tests/common.py @@ -250,7 +250,7 @@ def mock_http_component_app(hass, api_password=None): """Create an aiohttp.web.Application instance for testing.""" if 'http' not in hass.config.components: mock_http_component(hass, api_password) - app = web.Application(middlewares=[auth_middleware], loop=hass.loop) + app = web.Application(middlewares=[auth_middleware]) app['hass'] = hass app[KEY_USE_X_FORWARDED_FOR] = False app[KEY_BANS_ENABLED] = False diff --git a/tests/components/device_tracker/test_mqtt_json.py b/tests/components/device_tracker/test_mqtt_json.py index fdca113a7ff..1755f424d29 100644 --- a/tests/components/device_tracker/test_mqtt_json.py +++ b/tests/components/device_tracker/test_mqtt_json.py @@ -69,7 +69,6 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase): topic = 'location/zanzito' location = json.dumps(LOCATION_MESSAGE) - self.hass.config.components = set(['mqtt_json', 'zone']) assert setup_component(self.hass, device_tracker.DOMAIN, { device_tracker.DOMAIN: { CONF_PLATFORM: 'mqtt_json', @@ -88,7 +87,6 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase): topic = 'location/zanzito' location = 'home' - self.hass.config.components = set(['mqtt_json']) assert setup_component(self.hass, device_tracker.DOMAIN, { device_tracker.DOMAIN: { CONF_PLATFORM: 'mqtt_json', @@ -110,7 +108,6 @@ class TestComponentsDeviceTrackerJSONMQTT(unittest.TestCase): topic = 'location/zanzito' location = json.dumps(LOCATION_MESSAGE_INCOMPLETE) - self.hass.config.components = set(['mqtt_json']) assert setup_component(self.hass, device_tracker.DOMAIN, { device_tracker.DOMAIN: { CONF_PLATFORM: 'mqtt_json', diff --git a/tests/components/media_player/test_yamaha.py b/tests/components/media_player/test_yamaha.py index 7484b18a904..8cea5f7c63e 100644 --- a/tests/components/media_player/test_yamaha.py +++ b/tests/components/media_player/test_yamaha.py @@ -73,7 +73,7 @@ class TestYamaha(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" super(TestYamaha, self).setUp() - self.rec = FakeYamaha('10.0.0.0') + self.rec = FakeYamaha("http://10.0.0.0:80/YamahaRemoteControl/ctrl") def test_get_playback_support(self): """Test the playback.""" diff --git a/tests/components/notify/test_command_line.py b/tests/components/notify/test_command_line.py index e66f2647d4f..2575e1418f4 100644 --- a/tests/components/notify/test_command_line.py +++ b/tests/components/notify/test_command_line.py @@ -63,9 +63,9 @@ class TestCommandLine(unittest.TestCase): blocking=True) ) - result = open(filename).read() - # the echo command adds a line break - self.assertEqual(result, "{}\n".format(message)) + with open(filename) as fil: + # the echo command adds a line break + self.assertEqual(fil.read(), "{}\n".format(message)) @patch('homeassistant.components.notify.command_line._LOGGER.error') def test_error_for_none_zero_exit_code(self, mock_error): diff --git a/tests/test_config.py b/tests/test_config.py index c555c879300..6d0932cd9a2 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,5 +1,6 @@ """Test config utils.""" # pylint: disable=protected-access +import asyncio import os import unittest import unittest.mock as mock @@ -546,7 +547,7 @@ def test_merge_duplicate_keys(merge_log_err): assert len(config['input_select']) == 1 -@pytest.mark.asyncio +@asyncio.coroutine def test_merge_customize(hass): """Test loading core config onto hass object.""" core_config = {