From 519bcecfc20286ed331606f0c26113dd3a2275b1 Mon Sep 17 00:00:00 2001 From: Kevin Fronczak Date: Sat, 5 Mar 2022 18:59:56 -0500 Subject: [PATCH] Use urljoin to create thumbnail string --- blinkpy/camera.py | 5 +++-- tests/test_cameras.py | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/blinkpy/camera.py b/blinkpy/camera.py index 893332b2..9e7f598b 100644 --- a/blinkpy/camera.py +++ b/blinkpy/camera.py @@ -2,9 +2,10 @@ from shutil import copyfileobj import logging +from json import dumps +from requests.compat import urljoin from blinkpy import api from blinkpy.helpers.constants import TIMEOUT_MEDIA -from json import dumps _LOGGER = logging.getLogger(__name__) @@ -168,7 +169,7 @@ def update_images(self, config, force_cache=False): _LOGGER.warning("Could not find thumbnail for camera %s", self.name) if thumb_addr is not None: - new_thumbnail = f"{self.sync.urls.base_url}{thumb_addr}.jpg" + new_thumbnail = urljoin(self.sync.urls.base_url, f"{thumb_addr}.jpg") try: self.motion_detected = self.sync.motion[self.name] diff --git a/tests/test_cameras.py b/tests/test_cameras.py index e482a72a..73d9839f 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -87,6 +87,14 @@ def test_camera_update(self, mock_resp): self.assertEqual(self.camera.image_from_cache, "test") self.assertEqual(self.camera.video_from_cache, "foobar") + # Check that thumbnail without slash processed properly + mock_resp.side_effect = [None] + self.camera.update_images({"thumbnail": "thumb_no_slash"}) + self.assertEqual( + self.camera.thumbnail, + "https://rest-test.immedia-semi.com/thumb_no_slash.jpg", + ) + def test_no_thumbnails(self, mock_resp): """Tests that thumbnail is 'None' if none found.""" mock_resp.return_value = "foobar"