Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add factories for Wagtail's view restriction classes #90

Open
jams2 opened this issue Mar 12, 2024 · 0 comments
Open

Add factories for Wagtail's view restriction classes #90

jams2 opened this issue Mar 12, 2024 · 0 comments

Comments

@jams2
Copy link
Contributor

jams2 commented Mar 12, 2024

Here's a barebones example - we may need to add factories for some more related models.

import factory
import factory.fuzzy
import wagtail_factories
from wagtail import models as wagtail_models


class BaseViewRestrictionFactory(factory.django.DjangoModelFactory):
    """
    Factory for Wagtail's BaseViewRestriction model.
    """

    restriction_type = factory.fuzzy.FuzzyChoice(
        wagtail_models.BaseViewRestriction.RESTRICTION_CHOICES
    )
    password = factory.Faker("text", max_nb_chars=20)

    class Meta:
        model = wagtail_models.BaseViewRestriction
        abstract = True


class PageViewRestrictionFactory(BaseViewRestrictionFactory):
    """
    Factory for Wagtail's PageViewRestriction model.
    """

    page = factory.SubFactory(wagtail_factories.PageFactory)

    class Meta:
        model = wagtail_models.PageViewRestriction


class PasswordPageRestrictionFactory(PageViewRestrictionFactory):
    """
    Factory for creating password restrictions for Wagtail pages.
    """

    restriction_type = wagtail_models.BaseViewRestriction.PASSWORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant