def test_that_sections_are_reordered_after_save(self): section_form = SectionForm(instance=self.section3, data=self.form_data, initial={'questionnaire': self.questionnaire.id}) section_form.save() self.assertEqual(1, self.section3.order) self.assertEqual(2, Section.objects.get(id=self.section1.id).order) self.assertEqual(3, Section.objects.get(id=self.section2.id).order)
def test_valid_with_initial(self): initial = {'questionnaire': self.questionnaire.id, 'region': self.region, 'user': self.user} section_form = SectionForm(data=self.form_data, initial=initial) self.assertTrue(section_form.is_valid()) section = section_form.save() self.assertEqual(section.region, self.region) self.assertTrue(section.is_core)
def test_that_a_new_section_created_get_max_order_plus_one(self): questionnaire = QuestionnaireFactory() section1 = SectionFactory(order=1, questionnaire=questionnaire) section2 = SectionFactory(order=2, questionnaire=questionnaire) section3 = SectionFactory(order=3, questionnaire=questionnaire) section4 = SectionFactory(order=4, questionnaire=questionnaire) section5 = SectionFactory(order=1, title='Not in the same questionnaire') form_data = self.form_data form_data['order'] = 3 form_data['questionnaire'] = questionnaire.id initial = {'questionnaire': questionnaire.id} section_form = SectionForm(data=form_data, initial=initial) saved_section = section_form.save() self.assertEqual(3, saved_section.order) self.assertEqual(1, Section.objects.get(id=section1.id).order) self.assertEqual(2, Section.objects.get(id=section2.id).order) self.assertEqual(4, Section.objects.get(id=section3.id).order) self.assertEqual(5, Section.objects.get(id=section4.id).order)