paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
391 stars 67 forks source link

Bug using SimpleUploadedFile #76

Closed valdergallo closed 4 years ago

valdergallo commented 8 years ago

Was implemented one new library in django to create tests files called SimpleUploadedFile

The problem happen when you try send one SimpleUploadedFile to create one file instance.

Traceback (most recent call last):
  File "/vagrant/goal_design/tests/test_views.py", line 24, in test_download_documentation
    is_last_version="true")
  File "/home/vagrant/.virtualenvs/env/local/lib/python2.7/site-packages/django_dynamic_fixture/__init__.py", line 106, in get
    return d.get(model, shelve=shelve, **kwargs)
  File "/home/vagrant/.virtualenvs/env/local/lib/python2.7/site-packages/django_dynamic_fixture/ddf.py", line 528, in get
    instance = self.new(model_class, shelve=shelve, named_shelve=named_shelve, **kwargs)
  File "/home/vagrant/.virtualenvs/env/local/lib/python2.7/site-packages/django_dynamic_fixture/ddf.py", line 455, in new
    self.set_data_for_a_field(model_class, instance, field, persist_dependencies=persist_dependencies, **configuration)
  File "/home/vagrant/.virtualenvs/env/local/lib/python2.7/site-packages/django_dynamic_fixture/ddf.py", line 372, in set_data_for_a_field
    if django_file.file.mode != 'rb':
AttributeError: '_io.BytesIO' object has no attribute 'mode'

And in my tests, Im using

from django.core.files.uploadedfile import SimpleUploadedFile

BASE_FILE = SimpleUploadedFile('test_upload.txt', 'these are the file contents')
G(DjangoFIleModel, file=BASE_FILE)
paulocheque commented 8 years ago

Thanks for reporting!

Could you give feedback with the new version 1.9.0? I just try to avoid this error, but we can face another kind of issue right now.

paulocheque commented 4 years ago

Any news on this @valdergallo ? I will close the issue for now, please re-open if you think it is not solved. ;)