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

data_fixture='random' doesn't work #31

Closed qris closed 4 years ago

qris commented 11 years ago

The docs say you can do:

G(MyModel, data_fixture='random')

But this doesn't work:

Traceback (most recent call last):
File "/home/installuser/projects/inaspsite/django/website/perireg/tests/accept_reject_application_for_resource_tests.py", line 213, in test_reapprove_updated_registration_form_loads_with_all_fields_changed
    new_inst = new(Institution, data_fixture='random')
File "/home/installuser/projects/inaspsite/django/website/.ve/local/lib/python2.7/site-packages/django_dynamic_fixture/__init__.py", line 79, in new
    return d.new(model, shelve=shelve, persist_dependencies=persist_dependencies, **kwargs)
File "/home/installuser/projects/inaspsite/django/website/.ve/local/lib/python2.7/site-packages/django_dynamic_fixture/ddf.py", line 441, in new
    self.set_data_for_a_field(model_class, instance, field, persist_dependencies=persist_dependencies, **configuration)
File "/home/installuser/projects/inaspsite/django/website/.ve/local/lib/python2.7/site-packages/django_dynamic_fixture/ddf.py", line 348, in set_data_for_a_field
    data = self._process_field_with_default_fixture(field, model_class, persist_dependencies)
File "/home/installuser/projects/inaspsite/django/website/.ve/local/lib/python2.7/site-packages/django_dynamic_fixture/ddf.py", line 335, in _process_field_with_default_fixture
    data = self.data_fixture.generate_data(field)
AttributeError: 'str' object has no attribute 'generate_data'

I suspect I should be creating an instance of RandomDataFixture() instead?

paulocheque commented 11 years ago

Thanks for reporting! This must be a bug or documentation issue =)

@data_fixture: override DDF_DEFAULT_DATA_FIXTURE configuration. Default is SequentialDataFixture().

While there is not 'factory' implemented I recommend you to use the RandomDataFixture() like you predicted.

simenheg commented 9 years ago

This issue is still present in the documentation, under Overriding global data fixture. Doing G(MyModel, data_fixture='sequential') is also suggested, which results in the same error.

paulocheque commented 4 years ago

Fixed: https://github.com/paulocheque/django-dynamic-fixture/pull/110

Thanks again for the contribution.