def test_valid_form(self): data = init_data() form = SociologicalSurveyForm(data) self.assertTrue(form.is_valid()) data.update({'student_profession': None}) data.update({ 'student_professional_activity': professional_activity.NO_PROFESSION }) form = SociologicalSurveyForm(data) self.assertTrue(form.is_valid(), str(form.errors))
def update(request, application_id=None): """ Sociological survey of an applicant. :param request :param application_id """ applicant = mdl.applicant.find_by_user(request.user) if application_id: application = mdl.application.find_by_id(application_id) else: application = mdl.application.init_application(request.user) next_tab = navigation.SOCIOLOGICAL_SURVEY_TAB sociological_survey = sociological_survey_mdl.find_by_applicant(applicant) if request.method == "POST": sociological_form = SociologicalSurveyForm(request.POST) if sociological_form.is_valid(): sociological_form.save(applicant=applicant) sociological_survey = sociological_survey_mdl.find_by_applicant( applicant) following_tab = navigation.get_following_tab( request, 'sociological', application) if following_tab: return following_tab else: sociological_form = SociologicalSurveyForm( instance=sociological_survey) elif sociological_survey: sociological_form = SociologicalSurveyForm( instance=sociological_survey) else: sociological_form = SociologicalSurveyForm() data = { 'tab_active': next_tab, 'application': application, 'applications': mdl.application.find_by_user(request.user), 'sociological_form': sociological_form, 'professions': mdl.profession.find_by_adoc(False), 'sociological_survey': sociological_survey } data.update( demande_validation.get_validation_status(application, applicant)) return render(request, "admission_home.html", data)
def test_with_profession_with_adhoc(self): sociological_survey = SociologicalSurvey( applicant=self.applicant, student_profession=self.profession_adhoc, father_profession=self.profession_adhoc, mother_profession=self.profession_adhoc, conjoint_profession=self.profession_adhoc, paternal_grandfather_profession=self.profession_adhoc, maternal_grandfather_profession=self.profession_adhoc ) form = SociologicalSurveyForm(instance=sociological_survey) self.assertTrue(form.initial.get('student_profession_not_found')) self.assertEqual(form.initial.get('student_profession_other_name'), self.profession_adhoc.name) self.assertTrue(form.initial.get('father_profession_not_found')) self.assertEqual(form.initial.get('father_profession_other_name'), self.profession_adhoc.name) self.assertTrue(form.initial.get('mother_profession_not_found')) self.assertEqual(form.initial.get('mother_profession_other_name'), self.profession_adhoc.name) self.assertTrue(form.initial.get('conjoint_profession_not_found')) self.assertEqual(form.initial.get('conjoint_profession_other_name'), self.profession_adhoc.name) self.assertTrue(form.initial.get('paternal_grandfather_profession_not_found')) self.assertEqual(form.initial.get('paternal_grandfather_profession_other_name'), self.profession_adhoc.name) self.assertTrue(form.initial.get('maternal_grandfather_profession_not_found')) self.assertEqual(form.initial.get('maternal_grandfather_profession_other_name'), self.profession_adhoc.name)
def test_with_profession_not_adhoc(self): sociological_survey = SociologicalSurvey( applicant=self.applicant, student_profession=self.profession, father_profession=self.profession, mother_profession=self.profession, conjoint_profession=self.profession, paternal_grandfather_profession=self.profession, maternal_grandfather_profession=self.profession ) form = SociologicalSurveyForm(instance=sociological_survey) self.assertFalse(form.initial.get('student_profession_not_found')) self.assertIsNone(form.initial.get('student_profession_other_name')) self.assertFalse(form.initial.get('father_profession_not_found')) self.assertIsNone(form.initial.get('father_profession_other_name')) self.assertFalse(form.initial.get('mother_profession_not_found')) self.assertIsNone(form.initial.get('mother_profession_other_name')) self.assertFalse(form.initial.get('conjoint_profession_not_found')) self.assertIsNone(form.initial.get('conjoint_profession_other_name')) self.assertFalse(form.initial.get('paternal_grandfather_profession_not_found')) self.assertIsNone(form.initial.get('paternal_grandfather_profession_other_name')) self.assertFalse(form.initial.get('maternal_grandfather_profession_not_found')) self.assertIsNone(form.initial.get('maternal_grandfather_profession_other_name'))
def init_form(data=None): return SociologicalSurveyForm(data=data)