From 8d105a594b11dcc0fd60978ca7750dbf0bc85c3a Mon Sep 17 00:00:00 2001 From: Kidochukwu Jesse Jude <165483736+Jesse-jude@users.noreply.github.com> Date: Sun, 8 Jun 2025 12:42:21 +0000 Subject: [PATCH] Test Case To Check Whether the search_images() function correctly parses image urls --- tests/test_google_search.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_google_search.py diff --git a/tests/test_google_search.py b/tests/test_google_search.py new file mode 100644 index 0000000..1c9a052 --- /dev/null +++ b/tests/test_google_search.py @@ -0,0 +1,25 @@ +from google_images_search import search_images + +def test_search_images(monkeypatch): + # Mock response + class MockResponse: + def json(self): + return { + 'items': [ + {'link': 'https://example.com/image1.jpg'}, + {'link': 'https://example.com/image2.jpg'} + ] + } + + def mock_get(*args, **kwargs): + return MockResponse() + + # Replace requests.get with the mock + monkeypatch.setattr("requests.get", mock_get) + + results = search_images("cat", "fake_key", "fake_cse_id") + + assert results == [ + 'https://example.com/image1.jpg', + 'https://example.com/image2.jpg' + ]