Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/test_search.py
# Copyright (C) 2019-2021 The Software Heritage developers | # Copyright (C) 2019-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from collections import Counter | |||||
from datetime import datetime, timedelta, timezone | from datetime import datetime, timedelta, timezone | ||||
from itertools import permutations | from itertools import permutations | ||||
from hypothesis import given, settings, strategies | from hypothesis import given, settings, strategies | ||||
import pytest | import pytest | ||||
from swh.core.api.classes import stream_results | from swh.core.api.classes import stream_results | ||||
▲ Show 20 Lines • Show All 1,147 Lines • ▼ Show 20 Lines | def test_filter_keyword_in_filter(self): | ||||
result_page = self.search.origin_search(url_pattern="language in ['foo bar']") | result_page = self.search.origin_search(url_pattern="language in ['foo bar']") | ||||
assert result_page.next_page_token is None | assert result_page.next_page_token is None | ||||
assert result_page.results == [origin1] | assert result_page.results == [origin1] | ||||
result_page = self.search.origin_search(url_pattern="baaz") | result_page = self.search.origin_search(url_pattern="baaz") | ||||
assert result_page.next_page_token is None | assert result_page.next_page_token is None | ||||
assert result_page.results == [] | assert result_page.results == [] | ||||
def test_visit_types_count(self): | |||||
assert self.search.visit_types_count() == Counter() | |||||
origins = [ | |||||
{"url": "http://foobar.baz", "visit_types": ["git"], "blocklisted": True} | |||||
] | |||||
for idx, visit_type in enumerate(["git", "hg", "svn"]): | |||||
for i in range(idx + 1): | |||||
origins.append( | |||||
{ | |||||
ardumont: maybe also add some blocklisted entry here as well to check it's indeed not counted (assertion… | |||||
Done Inline Actionsgood idea, will update test anlambert: good idea, will update test | |||||
"url": f"http://{visit_type}.foobar.baz.{i}", | |||||
"visit_types": [visit_type], | |||||
} | |||||
) | |||||
self.search.origin_update(origins) | |||||
self.search.flush() | |||||
assert self.search.visit_types_count() == Counter(git=1, hg=2, svn=3) |
maybe also add some blocklisted entry here as well to check it's indeed not counted (assertion should stay the same iiuc).