Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/test_search.py
Show First 20 Lines • Show All 403 Lines • ▼ Show 20 Lines | def test_origin_last_revision_date_update_search(self): | ||||
date_type="last_revision_date" | date_type="last_revision_date" | ||||
) | ) | ||||
def test_origin_last_release_date_update_search(self): | def test_origin_last_release_date_update_search(self): | ||||
self._test_origin_last_revision_release_date_update_search( | self._test_origin_last_revision_release_date_update_search( | ||||
date_type="last_revision_date" | date_type="last_revision_date" | ||||
) | ) | ||||
def test_origin_keywords_search(self): | |||||
ORIGINS = [ | |||||
{ | |||||
"url": "http://foobar.1.com", | |||||
"intrinsic_metadata": { | |||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | |||||
"description": "Django is a backend framework for applications", | |||||
"keywords": "django,backend,server,web,framework", | |||||
}, | |||||
}, | |||||
{ | |||||
"url": "http://foobar.2.com", | |||||
"intrinsic_metadata": { | |||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | |||||
"description": "Native Android applications are fast", | |||||
"keywords": "android,mobile,ui", | |||||
}, | |||||
}, | |||||
{ | |||||
"url": "http://foobar.3.com", | |||||
"intrinsic_metadata": { | |||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0", | |||||
"description": "React framework helps you build web applications", | |||||
"keywords": "react,web,ui", | |||||
}, | |||||
}, | |||||
] | |||||
self.search.origin_update(ORIGINS) | |||||
self.search.flush() | |||||
def _check_results(keywords, origin_indices, sorting=False): | |||||
page = self.search.origin_search(url_pattern="foobar", keywords=keywords) | |||||
results = [r["url"] for r in page.results] | |||||
if sorting: | |||||
assert sorted(results) == sorted( | |||||
[ORIGINS[index]["url"] for index in origin_indices] | |||||
) | |||||
else: | |||||
assert results == [ORIGINS[index]["url"] for index in origin_indices] | |||||
_check_results(["build"], [2]) | |||||
_check_results(["web"], [2, 0]) | |||||
_check_results(["ui"], [1, 2]) | |||||
# baseline: "applications" is common in all origins | |||||
_check_results(["applications"], [1, 0, 2], True) | |||||
# ORIGINS[0] has 'framework' in both description and keyword so boosted | |||||
_check_results(["framework", "applications"], [0, 2, 1]) | |||||
# 'ui' is present in keywords of both origins so they're boosted | |||||
_check_results(["applications", "ui"], [1, 2, 0]) | |||||
# difference from baseline : | |||||
# ORIGIN[2] has 'ui' in: keyword + description | |||||
# ORIGIN[0] has 'ui' in: keyword | |||||
# ORIGIN[1] has 'ui' in: None | |||||
# so they get boosted accordingly | |||||
_check_results(["web", "applications"], [2, 0, 1]) | |||||
KShivendu: These comments are outdated. I'll update them.
But you may check if these test cases are… | |||||
def test_origin_sort_by_search(self): | def test_origin_sort_by_search(self): | ||||
now = datetime.now(tz=timezone.utc).isoformat() | now = datetime.now(tz=timezone.utc).isoformat() | ||||
now_minus_5_hours = ( | now_minus_5_hours = ( | ||||
datetime.now(tz=timezone.utc) - timedelta(hours=5) | datetime.now(tz=timezone.utc) - timedelta(hours=5) | ||||
).isoformat() | ).isoformat() | ||||
now_plus_5_hours = ( | now_plus_5_hours = ( | ||||
datetime.now(tz=timezone.utc) + timedelta(hours=5) | datetime.now(tz=timezone.utc) + timedelta(hours=5) | ||||
▲ Show 20 Lines • Show All 599 Lines • Show Last 20 Lines |
These comments are outdated. I'll update them.
But you may check if these test cases are sufficient.