Hi,
I want to test the GET method for an inline formset.
The view in which the inline formset is created is as follows:
================================
    @login_required
    def patron_edit_phone(request, *args, **kwargs):
        patron = request.user
        PhoneNumberFormSet = inlineformset_factory(Patron,
PhoneNumber, extra=1, exclude="kind",can_order=True)
        if request.method == "POST":
            formset = PhoneNumberFormSet(request.POST, request.FILES,
instance=patron)
            if formset.is_valid():
                formset.save()
                messages.success(request, _(u"Votre information de
numéro de téléphone a bien été mise à jour"))
        else:
            formset = PhoneNumberFormSet(instance=patron)

        return direct_to_template(request, 'accounts/
patron_phone_edit.html', extra_context={'formset': formset})
================================


I have succeeded to test the POST method. Here is the code.
================================
    def test_patron_phone_edit(self):
            self.client.login(username='alex...@e.com',
password='alex')
            response = self.client.post(reverse('patron_edit_phone'),
{
                'phones-TOTAL_FORMS': u'1',
                'phones-INITIAL_FORMS': u'',
                'phones-MAX_NUM_FORMS': u'',

                'phones-0-id' : '1',
                'phones-0-patron' : '1',
                'phones-0-number' : "11111111",
                'phones-0-DELETE' : u''
        })
        self.assertEquals(response.status_code, 200)
================================


For the GET method, I have tried the following code:
================================
    def test_patron_phone_get_form(self):
            self.client.login(usernamer='alex...@e.com',
password='alex')
            response = self.client.get(reverse('patron_edit_phone'))
            self.assertEquals(response.status_code, 200)
================================
But this doesn't work. Instead of getting a status_code=200, I get a
status_code=302. Why?
And when I print response.content, I get "None".
Perhaps I need to specify the total forms for the GET method?

Any help is highly appreciated!Thanks!

If more information is needed, tell me.

-- 
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