Skip to content
Open
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
3 changes: 2 additions & 1 deletion ddgs/engines/bing_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def build_payload(
self,
query: str,
region: str, # noqa: ARG002
safesearch: str, # noqa: ARG002
safesearch: str,
timelimit: str | None,
page: int = 1,
**kwargs: str,
Expand All @@ -32,6 +32,7 @@ def build_payload(
count = max(int(kwargs.get("max_results", 10)), 35)
payload = {
"q": query,
"adlt": {"on": "strict", "moderate": "moderate", "off": "off"}[safesearch.lower()],
"async": "1",
"first": str((page - 1) * count + 1),
"count": str(count),
Expand Down
9 changes: 9 additions & 0 deletions tests/bing_images_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ddgs.engines.bing_images import BingImages


def test_bing_images_payload_applies_safesearch() -> None:
engine = BingImages()

assert engine.build_payload("cats", "us-en", "on", None)["adlt"] == "strict"
assert engine.build_payload("cats", "us-en", "moderate", None)["adlt"] == "moderate"
assert engine.build_payload("cats", "us-en", "off", None)["adlt"] == "off"