Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix popularity page #6067

Merged
merged 1 commit into from
Apr 23, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,8 @@ async def is_channel_dirty(self, request):
)
async def get_popular_torrents_channel(self, request):
sanitized = self.sanitize_parameters(request.query)
sanitized["metadata_type"] = REGULAR_TORRENT
sanitized["popular"] = True
if "metadata_type" in sanitized:
err_msg = "specifying `metadata_type` parameter for popular torrents endpoint is not allowed"
return RESTResponse({"error": err_msg}, status=HTTP_BAD_REQUEST)

with db_session:
contents = self.session.mds.get_entries(**sanitized)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ async def test_get_popular_torrents_mdtype(enable_chant, enable_api, add_fake_to
It should be not possible to specify metadata_type argument for popular torrents endpoint
"""
session.dlmgr.get_download().get_state().get_progress = lambda: 0.5
await do_request(session, 'channels/popular_torrents?metadata_type=300', expected_code=400)
json_dict1 = await do_request(session, 'channels/popular_torrents')
json_dict2 = await do_request(session, 'channels/popular_torrents?metadata_type=300')
json_dict3 = await do_request(session, 'channels/popular_torrents?metadata_type=400')

# Currently popularity page force-set metadata_type to 300 (REGULAR_TORRENT) for all requests
assert json_dict1 == json_dict2 == json_dict3


@pytest.mark.asyncio
Expand Down
5 changes: 2 additions & 3 deletions src/tribler-core/tribler_core/modules/metadata_store/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,8 @@ def get_entries_query(
pony_query = self.search_keyword(txt_filter, lim=1000) if txt_filter else left_join(g for g in cls)

if popular:
if metadata_type:
raise TypeError('Specifying `metadata_type` with `popular` is not allowed')
metadata_type = REGULAR_TORRENT
if metadata_type != REGULAR_TORRENT:
raise TypeError('With `popular=True`, only `metadata_type=REGULAR_TORRENT` is allowed')

t = time() - POPULAR_TORRENTS_FRESHNESS_PERIOD
health_list = list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,13 @@ def test_popular_torrens_with_metadata_type(metadata_store):
Test that `popular` argument cannot be combiner with `metadata_type` argument
"""

metadata_store.get_entries(popular=True)

with pytest.raises(TypeError):
metadata_store.get_entries(popular=True, metadata_type=REGULAR_TORRENT)
metadata_store.get_entries(popular=True)

metadata_store.get_entries(popular=True, metadata_type=REGULAR_TORRENT)

with pytest.raises(TypeError):
metadata_store.get_entries(popular=True, metadata_type=CHANNEL_TORRENT)

with pytest.raises(TypeError):
metadata_store.get_entries(popular=True, metadata_type=[REGULAR_TORRENT, CHANNEL_TORRENT])