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

BadDataError: IntegrityError #56

Closed learner010 closed 9 years ago

learner010 commented 9 years ago

I have a data fixture which extends SequentialDataFixture. The fixture is given below:

class ASequentialDataFixture(SequentialDataFixture):
   def genericipaddressfield_config(self, field, key):
        return "{}.{}.{}".format(randint(000,999), randint(000,999), randint(000,999))

I have following test code.

        tokens = [G(Token, data_fixture = ASequentialDataFixture()).token for count in range(100)]

Which generates following error.

Traceback (most recent call last):
  File "/home/suren/job/ussd/core/tests/test_models.py", line 33, in test_generates_unique_tokens
    tokens = [G(Token, data_fixture = ASequentialDataFixture()).token for count in range(100)]

...

BadDataError: ('panel.models.user.User', IntegrityError(1062, "Duplicate entry 'a1@dynamicfixture.com' for key 'email'"))
paulocheque commented 9 years ago

That is a problem to use random values. The purpose of the "SequentialDataFixture" is to avoid errors like that.

I think you can try something like that:

   def genericipaddressfield_config(self, field, key):
        return self.ipaddressfield_config(field, key)

But in the new version of DDF I will add native support for it.

paulocheque commented 9 years ago

I added support for the GenericIPAddressField field in the master branch (https://github.com/paulocheque/django-dynamic-fixture/commit/c0254e388e6daafdd9b95f1cc27892eb6f2f09d4). It will be include in the new version of DDF. Thanks for reporting!!

Ref #54