Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
blocks/description: apply DESC_MAX_SIZE size constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-dupre committed Jul 21, 2021
1 parent 9f3db25 commit a78ae14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions idunn/blocks/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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
9 changes: 6 additions & 3 deletions tests/test_rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a78ae14

Please sign in to comment.