Skip to content

Commit

Permalink
Added unit tests for pinterst image download
Browse files Browse the repository at this point in the history
  • Loading branch information
rbreu committed May 4, 2024
1 parent fb8515e commit 2af6a75
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Fixed
hangs/weird behaviour)
* Fixed an intermittent crash when invoking New Scene
* Fixed bee files hanging on to disk space of deleted images (issue #99)
* Fixing Drag @ Drop from pinterest feed (by Randommist)



Expand Down
2 changes: 1 addition & 1 deletion beeref/fileio/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from PyQt6 import QtGui

import exif
import plum
from lxml import etree
import plum


logger = logging.getLogger(__name__)
Expand Down
62 changes: 62 additions & 0 deletions tests/fileio/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,65 @@ def test_load_image_loads_from_web_url_errors(view, imgfilename3x3):
img, filename = load_image(QtCore.QUrl(url))
assert img.isNull() is True
assert filename == url


@httpretty.activate
def test_load_image_from_pinterest_finds_image(view, imgdata3x3):
url = 'http://pinterest.com/a1b2c3/'
img_url = 'http://pinterest.com/foo.png'
httpretty.register_uri(
httpretty.GET,
url,
body=f'<html><body><img src="{img_url}"/></body></html>',
)
httpretty.register_uri(
httpretty.GET,
img_url,
body=imgdata3x3,
)
img, filename = load_image(QtCore.QUrl(url))
assert img.isNull() is False
assert filename == img_url


@httpretty.activate
def test_load_image_from_pinterest_when_already_image(view, imgdata3x3):
img_url = 'http://pinterest.com/foo.png'
httpretty.register_uri(
httpretty.GET,
img_url,
body=imgdata3x3,
)
img, filename = load_image(QtCore.QUrl(img_url))
assert img.isNull() is False
assert filename == img_url


@httpretty.activate
def test_load_image_from_pinterest_when_img_url_not_found(view, imgdata3x3):
url = 'http://pinterest.com/a1b2c3/'
img_url = 'http://pinterest.com/foo.png'
httpretty.register_uri(
httpretty.GET,
url,
body='<html><body><p>no image here</p></body></html>',
)
httpretty.register_uri(
httpretty.GET,
img_url,
body=imgdata3x3,
)
img, filename = load_image(QtCore.QUrl(url))
assert img.isNull() is True


@httpretty.activate
def test_load_image_from_pinterest_when_url_errors(view, imgdata3x3):
url = 'http://pinterest.com/a1b2c3/'
httpretty.register_uri(
httpretty.GET,
url,
status=500,
)
img, filename = load_image(QtCore.QUrl(url))
assert img.isNull() is True

0 comments on commit 2af6a75

Please sign in to comment.