Avoid self-link suggestions for redirect targets
This commit is contained in:
parent
d1efae7745
commit
e022872767
2 changed files with 94 additions and 4 deletions
|
|
@ -55,6 +55,61 @@ class ArticlePageSkipTests(unittest.TestCase):
|
|||
)
|
||||
self.assertIn("Useful candidate", body)
|
||||
|
||||
def test_redirect_target_is_left_out_of_candidates(self) -> None:
|
||||
hits = [
|
||||
hit("Documentary film"),
|
||||
hit("Useful candidate"),
|
||||
]
|
||||
|
||||
with (
|
||||
patch("web_view.api.get_wiki_info", return_value="Documentary film"),
|
||||
patch("web_view.search_count", return_value=2),
|
||||
patch("web_view.search_count_with_link", return_value=0),
|
||||
patch("web_view.search_no_link", return_value=(2, hits)),
|
||||
):
|
||||
response = self.client.get("/link/DVD_documentary")
|
||||
|
||||
body = response.get_data(as_text=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotIn('data-title="Documentary film"', body)
|
||||
self.assertIn("Useful candidate", body)
|
||||
|
||||
def test_redirect_target_case_variant_is_left_out_of_candidates(self) -> None:
|
||||
hits = [hit("documentary film")]
|
||||
|
||||
with (
|
||||
patch("web_view.api.get_wiki_info", return_value="Documentary film"),
|
||||
patch("web_view.search_count", return_value=1),
|
||||
patch("web_view.search_count_with_link", return_value=0),
|
||||
patch("web_view.search_no_link", return_value=(1, hits)),
|
||||
):
|
||||
response = self.client.get("/link/DVD_documentary")
|
||||
|
||||
body = response.get_data(as_text=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("No more candidates found for this article.", body)
|
||||
|
||||
|
||||
class ValidHitTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
web_view.app.config["TESTING"] = True
|
||||
self.client = web_view.app.test_client()
|
||||
|
||||
def test_redirect_target_is_not_valid_hit(self) -> None:
|
||||
with patch("web_view.get_diff") as get_diff:
|
||||
response = self.client.get(
|
||||
"/api/1/valid_hit",
|
||||
query_string={
|
||||
"link_to": "DVD documentary",
|
||||
"link_from": "Documentary film",
|
||||
"redirect_to": "Documentary film",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.get_json(), {"valid": False})
|
||||
get_diff.assert_not_called()
|
||||
|
||||
|
||||
class ProtectedCandidateTests(unittest.TestCase):
|
||||
def test_edit_protected_hits_are_filtered_out(self) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue