Hi If you're mocking away the storage class to speed up your tests, instead try this in-memory storage class which implements the complete API: https://github.com/waveaccounting/dj-inmemorystorage . Then you don't need any mocks.
As to adding the shortcut - if the only thing it will help with is your test length, why not write a couple of wrapper functions in your tests? I'm not sure we'd want to add this capability to Django since it would complicate the type signature and would enforce change on all the third party storage classes that exist. Thanks, Adam On Thu, 18 Feb 2021 at 07:37, guettli <guettli.goo...@thomas-guettler.de> wrote: > To save strings/bytes you need to use ContentFile up to now: > > path = default_storage.save('path/to/file', ContentFile(b'new content')) > > Docs: https://docs.djangoproject.com/en/3.1/topics/files/#storage-objects > > Things would be bit easier, if save() would support strings/bytes directly. > > This way a developer needs to type and import less code. > > The implementation would be simple: Storage.save() could check with > "isinstance()" > > if the value needs to be wrapped in ContentFile. > > Would you accept a patch to Storage.save()? > > Background: I am writing a unittest which mocked away the storage calls to > save() will put the data into the mock. > > Then I check if the data is the way I want it. > > Now it gets complicated again: I need to access the data which is > inside ContentFile grrr. > > This would be much easier if you could add strings/bytes to > the save() directly. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/fabd4661-93b9-45f4-a47e-3ffc31abc50cn%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/fabd4661-93b9-45f4-a47e-3ffc31abc50cn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Adam -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM0pkmWOZ8CTwhqrX3kR2dCApNd%2B0437ZktdN6GBC7R9jw%40mail.gmail.com.