This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from Qwant/fix-bancheck-status-code
Bancheck: fix status code for banned client
- Loading branch information
Showing
2 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
from fastapi.testclient import TestClient | ||
|
||
from app import app | ||
from idunn.utils.ban_check import get_ban_check_http | ||
from tests.utils import override_settings | ||
|
||
|
||
@pytest.fixture | ||
def enable_bancheck(httpx_mock): | ||
with override_settings( | ||
{ | ||
"BANCHECK_ENABLED": True, | ||
"QWANT_API_BASE_URL": "http://qwant-api.test", | ||
} | ||
), patch("idunn.utils.ban_check.ban_check_http", new_callable=get_ban_check_http): | ||
httpx_mock.get(url__regex=r"http://qwant-api.test/v3/captcha/isban.*").respond( | ||
json={"status": "success", "data": True} | ||
) | ||
yield | ||
|
||
|
||
def test_ia_client_banned(enable_bancheck): | ||
client = TestClient(app) | ||
response = client.get( | ||
"/v1/instant_answer", | ||
params={"q": "paris", "lang": "fr"}, | ||
headers={"x-client-hash": "banned"}, | ||
) | ||
assert response.status_code == 429 |