Ya, when I'm writing unit tests for my forms. What I wanted was a way in my
testing logic to generate a dictionary of values to post back to the server
based on the initial values of the forms in the content property of the
response object returned from the test client get() and/or post() methods.
Here is the current response object definition
http://docs.djangoproject.com/en/dev/topics/testing/#testing-responses

<http://docs.djangoproject.com/en/dev/topics/testing/#testing-responses>I
actually just finished my work on extracting them (or at least a first pass)
today:
http://dpaste.com/hold/85281/

The following is basic usage. As you can see, it simplifies the generation
of values for post or get.

    def test_htmlParse(self):

        response = self.client.get('/test/')
        self.failUnlessEqual(response.status_code, 200, 'Failed to retrieve
the form test page. (1)')

        curVals = response.form_values['frmTest']

        response = self.client.post('/test/', curVals)
        self.failUnlessEqual(response.status_code, 200, 'Failed to retrieve
the form test page. (2)')


On Tue, Aug 25, 2009 at 7:44 PM, Peter Bengtsson <pete...@gmail.com> wrote:

>
> Do you mean when you write tests?
> If so, when you get the response you can extract all the variables
> that was created inside the view if you're using locals().
> That way, you can probably get the form instance (created for example
> by form=MyForm(request.POST)) which you can then untangle to get all
> the fields from the form instance.
>
> On Aug 25, 4:31 pm, Joshua Russo <josh.r.ru...@gmail.com> wrote:
> > I'm working on putting together parsing logic so that I can extract the
> form
> > variables from the response content of the test Client. That way I can
> just
> > change a few values and throw it back at the server. This is especially
> > helpful with large dynamic forms that use formsets.
> > My question is, has this already been done? My Google-fu came up with
> nada.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to