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 hypothesis import given, settings, strategies | from hypothesis import given, settings, strategies | ||||
import pytest | |||||
from swh.core.api.classes import stream_results | from swh.core.api.classes import stream_results | ||||
class CommonSearchTest: | class CommonSearchTest: | ||||
def test_origin_url_unique_word_prefix(self): | def test_origin_url_unique_word_prefix(self): | ||||
origin_foobar_baz = {"url": "http://foobar.baz"} | origin_foobar_baz = {"url": "http://foobar.baz"} | ||||
origin_barbaz_qux = {"url": "http://barbaz.qux"} | origin_barbaz_qux = {"url": "http://barbaz.qux"} | ||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | def test_origin_visit_types_update_search(self): | ||||
["hg"], | ["hg"], | ||||
["svn", "git"], | ["svn", "git"], | ||||
["hg", "git"], | ["hg", "git"], | ||||
["hg", "svn"], | ["hg", "svn"], | ||||
["git", "hg", "svn"], | ["git", "hg", "svn"], | ||||
] | ] | ||||
) | ) | ||||
def test_origin_nb_visit_update_search(self): | |||||
origin_url = "http://foobar.baz" | |||||
self.search.origin_update([{"url": origin_url}]) | |||||
self.search.flush() | |||||
def _update_nb_visit(nb_visit): | |||||
self.search.origin_update([{"url": origin_url, "nb_visit": nb_visit}]) | |||||
self.search.flush() | |||||
def _check_nb_visit(nb_visit): | |||||
actual_page = self.search.origin_search( | |||||
url_pattern=origin_url, nb_visit=nb_visit, | |||||
) | |||||
assert actual_page.next_page_token is None | |||||
results = [r["url"] for r in actual_page.results] | |||||
expected_results = [origin_url] | |||||
assert sorted(results) == sorted(expected_results) | |||||
_update_nb_visit(5) | |||||
_check_nb_visit(5) | |||||
_update_nb_visit(3) | |||||
_check_nb_visit(5) # nb_visit shouldn't get updated and remain remain 5 | |||||
with pytest.raises(AssertionError): | |||||
_check_nb_visit(3) | |||||
def test_origin_update_with_no_visit_types(self): | def test_origin_update_with_no_visit_types(self): | ||||
""" | """ | ||||
Update an origin with visit types first then with no visit types, | Update an origin with visit types first then with no visit types, | ||||
check origin can still be searched with visit types afterwards. | check origin can still be searched with visit types afterwards. | ||||
""" | """ | ||||
origin_url = "http://foobar.baz" | origin_url = "http://foobar.baz" | ||||
self.search.origin_update([{"url": origin_url, "visit_types": ["git"]}]) | self.search.origin_update([{"url": origin_url, "visit_types": ["git"]}]) | ||||
self.search.flush() | self.search.flush() | ||||
self.search.origin_update([{"url": origin_url}]) | self.search.origin_update([{"url": origin_url}]) | ||||
self.search.flush() | self.search.flush() | ||||
actual_page = self.search.origin_search(url_pattern="http", visit_types=["git"]) | actual_page = self.search.origin_search(url_pattern="http", visit_types=["git"]) | ||||
assert actual_page.next_page_token is None | assert actual_page.next_page_token is None | ||||
results = [r["url"] for r in actual_page.results] | results = [r["url"] for r in actual_page.results] | ||||
expected_results = [origin_url] | expected_results = [origin_url] | ||||
assert results == expected_results | assert results == expected_results | ||||
def test_origin_intrinsic_metadata_description(self): | def test_origin_intrinsic_metadata_description(self): | ||||
origin1_nothin = {"url": "http://origin1"} | origin1_nothin = {"url": "http://origin1"} | ||||
origin2_foobar = {"url": "http://origin2"} | origin2_foobar = {"url": "http://origin2"} | ||||
origin3_barbaz = {"url": "http://origin3"} | origin3_barbaz = {"url": "http://origin3"} | ||||
self.search.origin_update( | self.search.origin_update( | ||||
[ | [ | ||||
{**origin1_nothin, "intrinsic_metadata": {},}, | {**origin1_nothin, "intrinsic_metadata": {},}, | ||||
{ | { | ||||
vlorentz: It's hard to spot the difference. Could you make the date constants and comment that the… | |||||
**origin2_foobar, | **origin2_foobar, | ||||
"intrinsic_metadata": { | "intrinsic_metadata": { | ||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", | ||||
"description": "foo bar", | "description": "foo bar", | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
**origin3_barbaz, | **origin3_barbaz, | ||||
▲ Show 20 Lines • Show All 395 Lines • Show Last 20 Lines |
It's hard to spot the difference. Could you make the date constants and comment that the difference is the years?