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

Added a factory for Redirect model #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JakubMastalerz
Copy link

@JakubMastalerz JakubMastalerz commented Jan 5, 2024

Resolves #82

This PR adds a factory for Wagtail's Redirect model.

@JakubMastalerz JakubMastalerz changed the title Added a factory for Redirect objects Draft: Added a factory for Redirect model Jan 5, 2024
src/wagtail_factories/factories.py Show resolved Hide resolved
src/wagtail_factories/factories.py Outdated Show resolved Hide resolved
@JakubMastalerz JakubMastalerz marked this pull request as ready for review May 10, 2024 17:41
@JakubMastalerz JakubMastalerz changed the title Draft: Added a factory for Redirect model Added a factory for Redirect model May 13, 2024
Copy link
Contributor

@jams2 jams2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great so far @JakubMastalerz. It would be nice to see documentation too if you have time.

@see https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/redirects/models.py#L191
"""
obj = model_class(*args, **kwargs)
obj.clean()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: I don't think we should be calling clean here, as it may clobber the values provided by a user. There are scenarios in which you may want to provide invalid data to a model instance — for example, if you want to test the clean method itself. I think our approach should be to make a best effort to generate example data that is both valid, and matches the typical usage of the object — but give the user the ability to create objects with data however they want, if they need to.

I would love to see a custom faker provider developed for old_path. We could use uri_path as a starting point (just using slugs is a little deficient). old_path also accepts query parameters, for which we could use pydict as a source. An API using traits to enable flags like has_query_params would be the icing on the cake.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more context on whether or not we should call clean:

"""
redirect = wagtail_factories.RedirectFactory()

assert type(redirect) is Redirect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: isinstance is a more conventional way to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add RedirectFactory
4 participants