wagtail / wagtail-factories

Factory boy classes for wagtail
http://wagtail-factories.readthedocs.io/en/latest/
MIT License
102 stars 41 forks source link

Use of traits with StreamBlockFactory #60

Open jams2 opened 2 years ago

jams2 commented 2 years ago

Given a factory definition of

class LinkStreamBlockFactory(wagtail_factories.StreamBlockFactory):
    internal = factory.SubFactory(PageStructBlockFactory)
    document = factory.SubFactory(DocumentStructBlockFactory)
    external = factory.SubFactory(ExternalLinkStructBlockFactory)

    class Meta:
        model = blocks.LinkStreamBlock

    class Params:
        is_internal = factory.Trait(**{"0": "internal"})

it is not possible to use the is_internal trait, like LinkStreamBlockFactory(is_internal=True), as the is_internal keyword breaks StreamBlockFactory's parameter parsing. This particular use case is somewhat pointless (you could just call LinkStreamBlockFactory(**{"0": "internal"})), but there may be valid use cases for traits (maybe as defining a shorthand for a particular combination of nested options). I would like to hear opinions on this - would fixing this be useful?