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_is_valid_when_user_is_regional_and_editing_none_core_section(self): questionnaire = QuestionnaireFactory() user = self.create_user(username='******', group=self.REGIONAL_ADMIN, org="WHO", region='AFR') section1 = SectionFactory(order=1, questionnaire=questionnaire, is_core=False, region=user.user_profile.region) initial = {'questionnaire': questionnaire.id, 'user': user} section_form = SectionForm(data=self.form_data, initial=initial, instance=section1) self.assertTrue(section_form.is_valid())
def test_is_invalid_when_user_is_regional_and_editing_core_section(self): questionnaire = QuestionnaireFactory() user = self.create_user(username='******', group=self.REGIONAL_ADMIN, org="WHO", region='AFR') section1 = SectionFactory(order=1, questionnaire=questionnaire, is_core=True, region=user.user_profile.region) initial = {'questionnaire': questionnaire.id, 'user': user} section_form = SectionForm(data=self.form_data, initial=initial, instance=section1) self.assertFalse(section_form.is_valid()) self.assertIn('You are not permitted to edit this section', section_form.errors['name'])
def test_valid_with_initial(self): section_form = SectionForm( data=self.form_data, initial={'questionnaire': self.questionnaire.id}) self.assertTrue(section_form.is_valid())
def test_valid(self): section_form = SectionForm( initial={'questionnaire': self.questionnaire.id}, data=self.form_data) self.assertTrue(section_form.is_valid())
def test_valid_with_initial(self): section_form = SectionForm(data=self.form_data, initial={'questionnaire': self.questionnaire.id}) self.assertTrue(section_form.is_valid())
def test_valid(self): section_form = SectionForm(initial={'questionnaire': self.questionnaire.id}, data=self.form_data) self.assertTrue(section_form.is_valid())