I'm trying to create an integration test for a Update View with update form. The issue I'm facing is that the form is marked as invalid with the all too common:
Select a valid choice. That choice is not one of the available choices
The model contains 2 related objects (foreign keys) for which this error happens. Note that the view and from work perfectly fine when running in the integrated test web server. This issue occurs when trying to create a TestCase using the client class.
I'm creating all the required instances in the setUp method of the TestCase and in the actual test use client to POST new data.
response = self.client.post(
reverse('edit_form', kwargs={'pk': self.instance.id}),
data={'id': self.instance.id,
'comment':self.instance.comment.id,
'sequence': self.instance.sequence.id,
#more fields omitted
})
This only shows the relevant fields. As one can see the actual ids used for the related objects really to exist as entries in the DB. Maybe relevant is that sequence is a hidden field. But both of them have this same validation error.
What is causing this issue with form validation in the test case?
Aucun commentaire:
Enregistrer un commentaire