Spaces:
Running
Running
Fix image search test case when API key is missing
Browse files
src/slidedeckai/helpers/image_search.py
CHANGED
|
@@ -20,7 +20,8 @@ load_dotenv()
|
|
| 20 |
if not os.getenv('PEXEL_API_KEY'):
|
| 21 |
warnings.warn(
|
| 22 |
'PEXEL_API_KEY environment variable is not set. '
|
| 23 |
-
'Image search functionality will not work without it.'
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
PEXELS_URL = 'https://api.pexels.com/v1/search'
|
|
|
|
| 20 |
if not os.getenv('PEXEL_API_KEY'):
|
| 21 |
warnings.warn(
|
| 22 |
'PEXEL_API_KEY environment variable is not set. '
|
| 23 |
+
'Image search functionality will not work without it.',
|
| 24 |
+
stacklevel=2
|
| 25 |
)
|
| 26 |
|
| 27 |
PEXELS_URL = 'https://api.pexels.com/v1/search'
|
tests/unit/test_image_search.py
CHANGED
|
@@ -112,6 +112,10 @@ def test_get_photo_url_from_api_response_selects_large_and_original(monkeypatch)
|
|
| 112 |
{'url': 'https://pexels.com/photo/3', 'src': {'large': 'https://images/3_large.jpg'}},
|
| 113 |
]
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
# Force selection of index 1 (second photo) which only has 'original'
|
| 116 |
monkeypatch.setattr(image_search.random, 'choice', lambda seq: 1)
|
| 117 |
|
|
|
|
| 112 |
{'url': 'https://pexels.com/photo/3', 'src': {'large': 'https://images/3_large.jpg'}},
|
| 113 |
]
|
| 114 |
|
| 115 |
+
# Ensure the Pexels API key is present so the helper will attempt to select
|
| 116 |
+
# and return photo URLs rather than early-returning (None, None).
|
| 117 |
+
monkeypatch.setenv('PEXEL_API_KEY', 'akey')
|
| 118 |
+
|
| 119 |
# Force selection of index 1 (second photo) which only has 'original'
|
| 120 |
monkeypatch.setattr(image_search.random, 'choice', lambda seq: 1)
|
| 121 |
|