[Fixed]-Testing formsets in Django

1👍

This is an example formset getting user’s skills

class SkillForm(forms.Form):
    level_id = forms.ChoiceField(choices=LEVEL_CHOICES, required = True)
    txt_skills = forms.CharField(max_length=250, required = True)

SkillFormset = formset_factory(SkillForm,extra=1, max_num=10)

and this the sample POST data for test cases.

self.post_data.update({
        'skillform-0-level_id': '2',
        'skillform-0-txt_skills': 'Python',
        'skillform-1-level_id': '3',
        'skillform-1-txt_skills': 'Java',
        'skillform-TOTAL_FORMS': '2',
        'skillform-INITIAL_FORMS': '1',
        'skillform-MAX_NUM_FORMS': '10'
        })

Leave a comment