diff --git a/wrolpi/common.py b/wrolpi/common.py index c6ea4af2..321478f5 100644 --- a/wrolpi/common.py +++ b/wrolpi/common.py @@ -2885,11 +2885,11 @@ async def search_other_estimates(session: Session, tag_names: List[str], search_ repo_count=repo_count, ) - # TODO handle multiple tags + # Matches `search_channels`: Channels with any of the Tags. channel_count = session.query(func.count(Channel.id)) \ .join(Collection, Collection.id == Channel.collection_id) \ .join(Tag, Tag.id == Collection.tag_id) \ - .filter(Tag.name == tag_names[0]) \ + .filter(Tag.name.in_(tag_names)) \ .scalar() others = dict( diff --git a/wrolpi/test/test_root_api.py b/wrolpi/test/test_root_api.py index 055e7364..a8163666 100644 --- a/wrolpi/test/test_root_api.py +++ b/wrolpi/test/test_root_api.py @@ -1016,6 +1016,18 @@ async def test_search_other_estimates(async_client, test_session, channel_factor assert response.status_code == HTTPStatus.OK assert response.json['others']['channel_count'] == 1, 'Only one Channel is tagged.' + # The estimate counts the Channels the search lists: those with any of the Tags. + tag2 = await tag_factory() + channel_factory(tag_name=tag2.name) + test_session.commit() + body = dict(tag_names=[tag.name, tag2.name]) + request, response = await async_client.post('/api/search_other_estimates', json=body) + assert response.status_code == HTTPStatus.OK + estimate = response.json['others']['channel_count'] + request, response = await async_client.post('/api/videos/channels/search', json=body) + assert response.status_code == HTTPStatus.OK + assert estimate == len(response.json['channels']) == 2 + @pytest.mark.asyncio async def test_mutating_request_survives_concurrent_writer(async_client, test_session, test_downloader,