Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/utils.py
- This file was added.
# Copyright (C) 2020 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from swh.search.interface import PagedResult | |||||
from typing import Dict, Iterable, List | |||||
def assert_results_match(actual_origins: Iterable[Dict], expected_origins: List[Dict]): | |||||
actual_urls = set(r["url"] for r in actual_origins) | |||||
assert actual_urls == set(o["url"] for o in expected_origins) | |||||
def assert_page_match( | |||||
actual_page: PagedResult, | |||||
expected_origins: List[Dict], | |||||
expected_page_token: bool = False, | |||||
): | |||||
if expected_page_token: | |||||
assert actual_page.next_page_token is not None | |||||
else: | |||||
assert actual_page.next_page_token is None | |||||
assert_results_match(actual_page.results, expected_origins) |