-
Notifications
You must be signed in to change notification settings - Fork 41
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
Feature request: A TestCase that automatically finds and tests PageFactory subclasses #45
Comments
We use an extended base class for that - no magic, so we end up with class ArticlePageTests(PageTestCase):
factory_class = ArticleFactory
def test_basics(self):
self.assertCanRenderPage()
self.assertCanRenderAdminPageEditor()
self.assertCanRenderPagePreview() where kind of thing. Which is then pretty easy to extend with a mixin, if you like: class ArticlePageTests(BasicPageTestsMixin):
def test_basics(self):
self.assertCanRenderPage()
self.assertCanRenderAdminPageEditor()
self.assertCanRenderPagePreview()
class ArticlePageTests(BasicPageTestsMixin, PageTestCase):
factory_class = ArticleFactory
class BlogPageTests(BasicPageTestsMixin, PageTestCase):
factory_class = BlogPageFactory
class ProductPageTests(BasicPageTestsMixin, PageTestCase):
factory_class = ProductPageFactory we've actually got it doing parent stuff too for some page types, eg: class ProductPageTests(BasicPageTestsMixin, PageTestCase):
factory_class = ProductPageFactory
def get_parent(self):
if hasattr(self, product_group_page):
return self.product_group_page
self.shop_page = ShopPageFactory.create(parent=self.site.homepage)
self.product_group_page = ProductGroupPage.create(parent=self.shop_page)
return self.product_group_page type of thing. and then in the Having something like this in a library would be nice - maybe we'll extract it to one some time. |
@danthedeckie We often find ourselves doing something quite similar to that, only where you have custom assertions, we just have separate tests. e.g.:
Certainly not difficult to do. But, with both solutions, you still need to import this and use it in the right places. Whereas, if we had some way to identify the factories of interest, we could do this once, and we'd be covered forever.
|
Imagine a test case that magically find all of the
PageFactory
subclasses within a project, and for each class found, test that:I think this could easily be achieved by keeping a 'reference'
dict
that gets populated via a metaclass when subclasses are defined (a bit like what Wagtail does withwagtail.core.models.PAGE_MODEL_CLASSES
)We could ignore any factories that do not specify a
model
value in theirMeta
class. And maybe even introduce a new/optionalMeta
option that could be used to explicitly opt-out of testing for a specific factory class.The text was updated successfully, but these errors were encountered: