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 TestCase that automatically test PageFactory subclasses #61

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ababic
Copy link

@ababic ababic commented Sep 20, 2022

Dependant on #62
Resolves #45

PageAutoTestCase is an importable test case that provides an instantly high level of coverage for custom page types in a standard (non-headless) Wagtail project.

All developers need to do is:

  • Import PageAutoTestCase into a module where their test runner will pick it up
  • For each page type they want to test, define a PageFactory capable of creating fully functional instances

The edit-ability, serve-ability (for multiple routes), and preview-ability (for all preview modes) should then be tested for each type.

Developers can add autotest=False to the Meta class to exclude factories from these tests. For example,
where a factory is created as a 'base' for a series of subclasses, and isn't intended to be used directly.

What if my page types aren't a good fit?

If none of them are, simply don't import PageAutoTestCase into your project, and the tests should not run as part of your test suite.

If only a few page types are incompatible with PageAutoTestCase, you may wish to add autotest=False to the Meta class for those factories to exclude them.

Can I customise PageAutoTestCase?

PageAutoTestCase isn't designed to be subclassed. However, if you wanted to define something similar,, you could subclass PageFeaturesTestCase, which would give you access to the following assertions:

  • assertCanEditPageWithoutErrors(page: Page)
  • assertCanRenderPageWithoutErrors(page: Page, route_path: str = "/")
  • assertCanPreviewPageWithoutErrors(page: Page, preview_mode: str = "")

@ababic ababic marked this pull request as draft September 20, 2022 09:03
@ababic ababic force-pushed the feature/autotest branch 6 times, most recently from 76166d5 to 79bab44 Compare September 20, 2022 10:55
@ababic ababic force-pushed the feature/autotest branch 2 times, most recently from b204803 to 64e4049 Compare October 5, 2022 10:10
@ababic ababic changed the title Add TestCase that automatically finds and tests PageFactory subclasses Add TestCase that automatically test PageFactory subclasses Oct 5, 2022
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.

Feature request: A TestCase that automatically finds and tests PageFactory subclasses
1 participant