Subj.
Right now (Factory Boy ver. 2.4.1.) with this code:
class ImageFactory(factory.django.DjangoModelFactory):
class Meta:
model = Image
image = factory.django.ImageField(width=1024, height=768)
image
will be None
at save time, so if the Image
model has save
overridden and its operates with the image
, it will fail. And thats exactly my case.
So - how to make image generated before save
call?
I've found a workaround:
from django.core.files.base import ContentFile
class ImageFactory(factory.django.DjangoModelFactory):
class Meta:
model = Image
image = factory.LazyAttribute(
lambda _: ContentFile(
factory.django.ImageField()._make_data(
{'width': 1024, 'height': 768}
), 'example.jpg'
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With