Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use urljoin to create thumbnail string #550

Merged
merged 1 commit into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions blinkpy/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down