vendredi 31 juillet 2015

How to specify list size using FactoryBoy

Let's assume i have this model:

class FooContainerModel(object):
    def __init__(self, foos):
        self.foos = foos

I want to be able to decide how many foos will be created at creation time, eg.

model = FooContainerFactory(count=15)

Tried factories like

class FooContainerFactory(factory.Factory):
    class Meta:
        model = FooContainerModel

    foos = factory.List([Foo() for _ in xrange(20)]) # fixed amount
    foos = factory.lazy_attribute(lambda o: [Foo() for _ in xrange(20)]) # same

Of course I can manually create list of Foo() with desired length and instantiate FooContainerModel, but it's not what I want. Any solutions?

Aucun commentaire:

Enregistrer un commentaire