Hi! When I try to test a post to a form that have a ModelChoiceField form I get always a form error in that field "Select a valid choice". The form is this:
class OperacionForm(forms.Form): ticker = forms.ModelChoiceField(Valor.objects.all()) fecha = forms.DateField(widget=SelectDateWidget(years = range(1950,2010))) cantidad = forms.CharField() precio = forms.CharField() comision = forms.CharField() tipo = forms.ChoiceField(choices=[('Compra','Compra'),('Venta','Venta')]) And the test is this: def testOperacionValida(self): self.client.login(username='pepe', password='test') usuario = User.objects.get(username='pepe') response = self.client.post('/carteras/', { 'cartera_nombre':'micartera', 'submit':'Crear' }) carteras = Cartera.objects.filter(nombre='micartera') & Cartera.objects.filter(usuarioID=usuario) count_before = Operacion.objects.filter(carteraID=carteras[0]).count() response = self.client.get('/carteras/nueva_operacion/%d' % carteras[0].id) response = self.client.post('/carteras/nueva_operacion/', { 'ticker':Valor.objects.all()[0], 'cantidad':'100', 'precio':'5', 'fecha':'06/07/2008', 'comision':'9', 'tipo':'Compra', 'submit':'Crear' }) count_after = Operacion.objects.filter(carteraID=carteras[0]).count() self.assertEqual(count_after, count_before + 1) The test fails with this message: <ul class="errorlist"><li>ticker<ul class="errorlist"><li>Select a valid choice. That choice is not one of the available choices.</li></ul></li></ul> F ====================================================================== FAIL: testOperacionValida (bolsacarteras.Carteras.tests.CrearOperacion) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/fcano/djcode/bolsacarteras/../bolsacarteras/Carteras/tests.py", line 92, in testOperacionValida self.assertEqual(count_after, count_before + 1) AssertionError: 0 != 1 ---------------------------------------------------------------------- I print the form error before the assertion to see what is happening with the form and I see the error. The problem is with the ticker that I try to introduce like this: 'ticker':Valor.objects.all()[0], I print Valor.objects.all()[0] and I see that the fixture is imported correctly. How I can introduce this value in the test? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---