Skip to content

Commit

Permalink
Add tests for RedirectFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMastalerz committed May 10, 2024
1 parent 431ad50 commit 28e7b21
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import wagtail_factories
from wagtail import blocks
from wagtail.models import Page, Site
from wagtail.contrib.redirects.models import Redirect

from tests.testapp.factories import MyTestPageFactory, MyTestPageGetOrCreateFactory

Expand Down Expand Up @@ -171,3 +172,27 @@ def test_document_add_to_collection():
collection__parent=root_collection, collection__name="new"
)
assert document.collection.name == "new"


@pytest.mark.django_db()
def test_redirect_factory():
"""
Test that a `RedirectFactory` generates a `Redirect` object.
"""
redirect = wagtail_factories.RedirectFactory()

assert type(redirect) is Redirect


@pytest.mark.django_db()
def test_redirect_factory_old_path_normalisation():
"""
Test that `RedirectFactory` uses `Redirect.clean()` to normalise the
`old_path` value.
"""

redirect = wagtail_factories.RedirectFactory(old_path="test-path/")

# Verify that `old_path` has been modified according to
# @https://github.com/wagtail/wagtail/blob/a09bba67cd58f519f3ae5bff32575e7ce9244031/wagtail/contrib/redirects/models.py#L141
assert redirect.old_path == "/test-path"

0 comments on commit 28e7b21

Please sign in to comment.