Почему поля изображений не создаются в Django Factory Boy?Python

Программы на Python
Anonymous
Почему поля изображений не создаются в Django Factory Boy?

Сообщение Anonymous »

Я пытался следовать стандартному рецепту для полей изображений в 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)
Я попытался протестировать это с помощью следующего фрагмента кода:

Код: Выделить всё

def test_config(self):
conf = GeneralConfigurationSingletonFactory(
custom_theme__name="image.png"
)
print(conf.custom_theme.width)
self.assertEqual(conf.custom_theme.width, 200)
При этом возникает следующая ошибка:

Код: Выделить всё

ValueError: The 'custom_theme' attribute has no file associated with it.
Я думал, что сделал именно то, что написано в документации. Что я не понимаю?

Подробнее здесь: https://stackoverflow.com/questions/790 ... actory-boy

Вернуться в «Python»