From a78ae14be4819b724c53085b8a240030d1836c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dupr=C3=A9?= Date: Wed, 21 Jul 2021 14:37:42 +0200 Subject: [PATCH] blocks/description: apply `DESC_MAX_SIZE` size constraint --- idunn/blocks/description.py | 8 ++++++-- tests/test_rate_limiter.py | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/idunn/blocks/description.py b/idunn/blocks/description.py index e18ac8ac3..f70dfc42c 100644 --- a/idunn/blocks/description.py +++ b/idunn/blocks/description.py @@ -32,7 +32,7 @@ class DescriptionBlock(BaseBlock): def from_es(cls, place, lang): if wiki_block := WikipediaBlock.from_es(place, lang): return cls( - description=wiki_block.description, + description=limit_size(wiki_block.description), source=DescriptionSources.WIKIPEDIA, url=wiki_block.url, ) @@ -43,6 +43,10 @@ def from_es(cls, place, lang): else: source = DescriptionSources.OSM - return cls(description=description, source=source, url=place.get_description_url(lang)) + return cls( + description=limit_size(description), + source=source, + url=place.get_description_url(lang), + ) return None diff --git a/tests/test_rate_limiter.py b/tests/test_rate_limiter.py index b7b3b7a40..8204d4629 100644 --- a/tests/test_rate_limiter.py +++ b/tests/test_rate_limiter.py @@ -63,9 +63,12 @@ def test_rate_limiter_with_redis(limiter_test_normal, mock_wikipedia_response): Test that Idunn stops external requests when we are above the max rate - We mock 5*2 calls to wikipedia while the max number - of calls is 3*2, so we test that after 3 calls - no more calls are done + Each call to Idunn (with cache disabled) outputs two blocks with Wikipedia + data, each block requires two request (to translate the title and then to + fetch actual content). Which makes 4 calls per POI request to Idunn. + + As `WIKI_API_RL_MAX_CALLS` is set to 12, the blocks won't be displayed + after the 3rd request. """ client = TestClient(app)