dimanche 3 juillet 2016

pass a form in unittest

I want to write test for my code and pass a value to a form how can i do that? I have two form in my code and this value should pass just to one of them. my unittest:

def test_user_has_project(self):
    resp = self.client.post('/register/',NEW_USER)
    self.assertRedirects(resp, '/register/confirm/')
    confirmation_code = self.client.session['confirm_code']
    resp = self.client.post('/register/confirm/',
            {'confirm_code':confirmation_code})

but this code pass confirmation code to both forms. my views:

`if request.method == 'POST':
        form = forms.RegistrationConfirmForm(request.POST)
        if (form.is_valid() and
            form.cleaned_data['confirm_code'] == request.session['confirm_code']):

            # Register the user in the backend
            form = forms.RegistrationForm(request.session['registering_user'])

sorry. I'm a beginner in both coding and asking question! `

Aucun commentaire:

Enregistrer un commentaire