forked from retoor/devplacepy
Zo doen wijdat in oost
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from tests.conftest import run_async
|
||||
|
||||
import pytest
|
||||
|
||||
from devplacepy.services.community.search import SearchPhase, direct_url, rank
|
||||
from tests.unit.services.community.fakes import FakeFetcher
|
||||
|
||||
|
||||
def test_direct_addresses_skip_search():
|
||||
assert direct_url("https://x.test/forum") == "https://x.test/forum"
|
||||
assert direct_url("x.test") == "https://x.test"
|
||||
assert direct_url("devplace") is None
|
||||
|
||||
|
||||
def test_rank_prefers_domain_match_and_drops_social_noise():
|
||||
results = [
|
||||
{"title": "DevPlace on LinkedIn", "url": "https://www.linkedin.com/company/devplace", "description": ""},
|
||||
{"title": "Other", "url": "https://other.test/page", "description": "mentions devplace"},
|
||||
{"title": "DevPlace", "url": "https://devplace.example/", "description": ""},
|
||||
]
|
||||
ranked = rank("devplace", results)
|
||||
assert [candidate.host for candidate in ranked] == ["devplace.example", "other.test"]
|
||||
|
||||
|
||||
def test_search_uses_rsearch_and_caps_candidates():
|
||||
results = [{"title": f"t{n}", "url": f"https://site{n}.test/", "description": ""} for n in range(9)]
|
||||
key = "https://rsearch.app.molodetz.nl/search?content=false&count=15&query=forum"
|
||||
fetcher = FakeFetcher({key: {"success": True, "results": results}})
|
||||
found = run_async(SearchPhase(fetcher).run("forum"))
|
||||
assert len(found) == 5
|
||||
|
||||
|
||||
def test_search_failure_raises():
|
||||
key = "https://rsearch.app.molodetz.nl/search?content=false&count=15&query=forum"
|
||||
fetcher = FakeFetcher({key: (500, "boom")})
|
||||
with pytest.raises(RuntimeError):
|
||||
run_async(SearchPhase(fetcher).run("forum"))
|
||||
Reference in New Issue
Block a user