fix(sdk): BUG-015 validate URL in capture() when using ScreenshotOptions
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m14s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m14s
- Add URL validation after options.to_dict() in Python SDK - Add failing test first (TDD), then fix - All 17 Python SDK tests passing
This commit is contained in:
parent
dfd410f842
commit
195a656a7d
5 changed files with 8 additions and 2 deletions
BIN
sdk/python/src/snapapi/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
sdk/python/src/snapapi/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
sdk/python/src/snapapi/__pycache__/client.cpython-312.pyc
Normal file
BIN
sdk/python/src/snapapi/__pycache__/client.cpython-312.pyc
Normal file
Binary file not shown.
|
|
@ -144,6 +144,8 @@ class SnapAPI:
|
||||||
"""
|
"""
|
||||||
if options:
|
if options:
|
||||||
body = options.to_dict()
|
body = options.to_dict()
|
||||||
|
if not body.get('url'):
|
||||||
|
raise ValueError("url is required")
|
||||||
else:
|
else:
|
||||||
if not url:
|
if not url:
|
||||||
raise ValueError("url is required")
|
raise ValueError("url is required")
|
||||||
|
|
|
||||||
BIN
sdk/python/tests/__pycache__/test_snapapi.cpython-312.pyc
Normal file
BIN
sdk/python/tests/__pycache__/test_snapapi.cpython-312.pyc
Normal file
Binary file not shown.
|
|
@ -165,8 +165,12 @@ class TestSnapAPI(unittest.TestCase):
|
||||||
self.snap.capture(None)
|
self.snap.capture(None)
|
||||||
self.assertEqual(str(cm.exception), "url is required")
|
self.assertEqual(str(cm.exception), "url is required")
|
||||||
|
|
||||||
# Note: When using ScreenshotOptions object, URL validation doesn't happen early
|
def test_capture_raises_value_error_if_options_has_empty_url(self):
|
||||||
# This could be considered a bug in the SDK but we're testing current behavior
|
"""capture(options=ScreenshotOptions(url='')) should raise ValueError."""
|
||||||
|
options = ScreenshotOptions(url="")
|
||||||
|
with self.assertRaises(ValueError) as cm:
|
||||||
|
self.snap.capture(options=options)
|
||||||
|
self.assertEqual(str(cm.exception), "url is required")
|
||||||
|
|
||||||
@patch('snapapi.client.urllib.request.urlopen')
|
@patch('snapapi.client.urllib.request.urlopen')
|
||||||
def test_capture_raises_snap_api_error_on_http_error(self, mock_urlopen):
|
def test_capture_raises_snap_api_error_on_http_error(self, mock_urlopen):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue