Skip to content

Commit

Permalink
Add test for broken link actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MizukiTemma committed Oct 2, 2024
1 parent 079fad8 commit a306330
Show file tree
Hide file tree
Showing 7 changed files with 560 additions and 9 deletions.
152 changes: 152 additions & 0 deletions integreat_cms/cms/fixtures/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,54 @@
"redirect_to": "https://integreat.app/augsburg/de/test-links/"
}
},
{
"model": "linkcheck.url",
"pk": 18,
"fields": {
"url": "https://tuerantuer.de/",
"last_checked": "2023-08-23T10:19:32Z",
"anchor_status": null,
"ssl_status": null,
"status": true,
"status_code": 302,
"redirect_status_code": 200,
"message": "200 OK",
"error_message": "",
"redirect_to": ""
}
},
{
"model": "linkcheck.url",
"pk": 19,
"fields": {
"url": "https://integreat.app/fake-region/de/willkommen/",
"last_checked": "2023-08-23T10:19:32Z",
"anchor_status": null,
"ssl_status": null,
"status": false,
"status_code": null,
"redirect_status_code": null,
"message": "",
"error_message": "Diese Region existiert nicht oder ist nicht aktiv.",
"redirect_to": ""
}
},
{
"model": "linkcheck.url",
"pk": 20,
"fields": {
"url": "https://tuerantuer.dx/",
"last_checked": "2023-08-23T10:19:32Z",
"anchor_status": null,
"ssl_status": null,
"status": false,
"status_code": null,
"redirect_status_code": null,
"message": "Name Resolution Error: Failed to resolve 'tuerantuer.dx' ([Errno -2] Name or service not known)",
"error_message": "Name Resolution Error: Failed to resolve 'tuerantuer.dx' ([Errno -2] Name or service not known)",
"redirect_to": ""
}
},
{
"model": "linkcheck.link",
"pk": 1,
Expand Down Expand Up @@ -2627,6 +2675,66 @@
"ignore": false
}
},
{
"model": "linkcheck.link",
"pk": 35,
"fields": {
"content_type": ["cms", "pagetranslation"],
"object_id": 99,
"field": "content",
"url": 7,
"text": "Internal valid link",
"ignore": false
}
},
{
"model": "linkcheck.link",
"pk": 36,
"fields": {
"content_type": ["cms", "pagetranslation"],
"object_id": 99,
"field": "content",
"url": 19,
"text": "Internal invalid link",
"ignore": false
}
},
{
"model": "linkcheck.link",
"pk": 37,
"fields": {
"content_type": ["cms", "pagetranslation"],
"object_id": 99,
"field": "content",
"url": 18,
"text": "External valid link",
"ignore": false
}
},
{
"model": "linkcheck.link",
"pk": 38,
"fields": {
"content_type": ["cms", "pagetranslation"],
"object_id": 99,
"field": "content",
"url": 20,
"text": "External invalid link",
"ignore": false
}
},
{
"model": "linkcheck.link",
"pk": 39,
"fields": {
"content_type": ["cms", "pagetranslation"],
"object_id": 99,
"field": "content",
"url": 4,
"text": "Unchecked ink",
"ignore": false
}
},
{
"model": "cms.page",
"pk": 1,
Expand Down Expand Up @@ -3271,6 +3379,29 @@
"embedded_offers": []
}
},
{
"model": "cms.page",
"pk": 29,
"fields": {
"created_date": "2023-08-18T10:31:48.247Z",
"lft": 1,
"rgt": 2,
"tree_id": 10,
"depth": 1,
"parent": null,
"region": 2,
"explicitly_archived": false,
"icon": null,
"mirrored_page": null,
"mirrored_page_first": true,
"organization": null,
"api_token": "",
"hix_ignore": false,
"authors": [],
"editors": [],
"embedded_offers": []
}
},
{ "model": "cms.regionfeedback", "pk": 1, "fields": { "feedback_ptr": 1 } },
{ "model": "cms.regionfeedback", "pk": 4, "fields": { "feedback_ptr": 4 } },
{ "model": "cms.regionfeedback", "pk": 7, "fields": { "feedback_ptr": 7 } },
Expand Down Expand Up @@ -5336,6 +5467,27 @@
"hix_feedback": null
}
},
{
"model": "cms.pagetranslation",
"pk": 99,
"fields": {
"title": "Test links",
"slug": "test_links",
"status": "PUBLIC",
"content": "<div><p><a href=\"https://integreat.app/augsburg/de/willkommen/\">Internal valid</a></p><p><a href=\"https://integreat.app/fake-region/de/willkommen/\">Internal invalid</a></p><p> </p><p><a class=\"link-external\" href=\"https://tuerantuer.de/\">External valid</a></p><p><a class=\"link-external\" href=\"https://tuerantuer.dx/\">External invalid</a></p><p> </p><p><a href=\"https://integreat.app\">Unchecked link</a></p></div>",
"language": 1,
"currently_in_translation": false,
"machine_translated": false,
"version": 1,
"minor_edit": false,
"last_updated": "2022-12-30T11:11:11.111Z",
"creator": ["root"],
"automatic_translation": false,
"page": 29,
"hix_score": null,
"hix_feedback": null
}
},
{
"model": "cms.imprintpagetranslation",
"pk": 1,
Expand Down
3 changes: 3 additions & 0 deletions integreat_cms/cms/views/linkcheck/link_replace_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from django.contrib import messages
from django.shortcuts import redirect, render
from django.utils.decorators import method_decorator
from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView

from ...decorators import permission_required
from ...forms import LinkReplaceForm

if TYPE_CHECKING:
Expand All @@ -15,6 +17,7 @@
from django.http import HttpRequest, HttpResponse


@method_decorator(permission_required("cms.view_broken_links"), name="dispatch")
class LinkReplaceView(TemplateView):
"""
View for link replace form
Expand Down
3 changes: 0 additions & 3 deletions integreat_cms/cms/views/linkcheck/linkcheck_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import TYPE_CHECKING
from urllib.parse import urlencode

from cacheops import invalidate_model
from django.conf import settings
from django.contrib import messages
from django.http import Http404
Expand Down Expand Up @@ -218,8 +217,6 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
# Add short delay to allow rechecking to be finished when page reloads
time.sleep(1)

invalidate_model(Link)
invalidate_model(Url)
url_for_current_region = reverse("linkcheck", kwargs=kwargs)
# Keep pagination settings
return redirect(f"{url_for_current_region}{self.get_pagination_params()}")
Loading

0 comments on commit a306330

Please sign in to comment.