Django factory boy, image fields not created?
I tried to follow the standard recipe for image fields for django factory boy:
class ConfigurationSingletonFactory(DjangoModelFactory):
class Meta:
model = Configuration
django_get_or_create = ("id",)
id = 1
custom_theme = ImageField(color="blue", width=200, height=200)
class GeneralConfiguration(SingletonModel):
custom_theme = PrivateMediaImageField("Custom background", upload_to="themes", blank=True)
However whenever I try to test it:
def test_config(self):
conf = GeneralConfigurationSingletonFactory(
custom_theme__name="image.png"
)
print(conf.custom_theme.width)
self.assertEqual(conf.custom_theme.width, 200)
The following error pops up:
ValueError: The 'custom_theme' attribute has no file associated with it.
What am I misunderstanding, I thought I did exactly what https://factoryboy.readthedocs.io/en/stable/orms.html#factory.django.ImageField says?