Closed qris closed 4 years ago
Interesting behavior! If you have some pull request with tests I would be happy to merge!
Do you want tests that depend on django-hvad? Or mock the model to check that we can assign all fields supplied in kwargs?
Hi qris, sorry by the late response.
What about trying the new field plugin system? http://django-dynamic-fixture.readthedocs.org/en/latest/data_fixtures.html#custom-field-fixture
Having the same problem, and I don't think I understand how the custom fixtures can be used in this case - I already have them set for Charfields but that doesn't really help...
@pgcd Can you try the new teach
method to teach DDF how to create this instance?
In your PyTest conftest.py
module:
from ddf import teach
teach(NewsItem, title='Another one or some lambda function')
Then in your tests:
from ddf import G
G(NewsItem)
# or
G(NewsItem title='replace the default value')
@paulocheque I'm very very sorry but a long time has passed, and I no longer use either. I'm so so sorry.
@pgcd No problem at all. I am sorry for the delay. Thanks again for the contribution.
This works with django-hvad, provided that you give values for all required fields:
But this doesn't:
Because the
title
attribute is a translated field. I'm not sure whether the problem is in hvad or DDF. I think it occurs here, in DynamicFixture.new():Because
get_fields_from_model
doesn't return translated fields (they're not inmodel_class._meta.fields
either):That may be a mistake by
hvad
, but you can actually assign to those fields:so if DynamicFixture would actually assign all supplied kwargs, then it would work with hvad. Additionally it would not ignore supplied values for fields that it doesn't know about, which can lead to subtle errors.