def test_invalid_academic_details_submission(self): datas = [{'branch':'CSE', 'college':'*(*(*(*(', 'start_year':'2011', 'end_year':'2015'}, {'branch':'CSE', 'college':'JNTU, Hyderabad', 'start_year':'2011', 'end_year':'2015'}] for data in datas: form = AcadSettingsForm(data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors.has_key('college'))
def test_valid_academic_details_saving(self): datas = [{'branch':'CSE', 'college':'SVPCET', 'start_year':'2011', 'end_year':'2015'}, {'branch':'CSE', 'college':'Sri Venkatesa Perumal College of Engineering and Technology', 'start_year':'2001', 'end_year':'2005'}, {'branch':'CSE', 'college':'MGIT.', 'start_year':'2011', 'end_year':'2015'}, {'branch':'CSE', 'college':'Mohan-Babu College-Chittor.', 'start_year':'1930', 'end_year':'2015'}] for data in datas: form = AcadSettingsForm(data) self.assertTrue(form.is_valid()) self.assertFalse(form.errors) for key, val in data.items(): self.assertEquals(data[key], form.cleaned_data.get(key))
def view_get_acad_settings(request, acad_settings_template): userprofile = loggedin_userprofile(request) (branch, college, start_year, end_year, aggregate) = userprofile.acad_details acad_form = AcadSettingsForm({'branch':branch, 'college':college.name, 'start_year':start_year, 'end_year':end_year, 'aggregate':aggregate}) return response(request, acad_settings_template, {'acad_form':acad_form})
def view_save_acad_settings(request, acad_settings_template): if request.method == 'GET': return view_get_acad_settings(request, acad_settings_template) userprofile = loggedin_userprofile(request) acad_form = AcadSettingsForm(post_data(request)) if acad_form.is_valid(): branch = acad_form.cleaned_data.get('branch') college = acad_form.cleaned_data.get('college') start_year = acad_form.cleaned_data.get('start_year') end_year = acad_form.cleaned_data.get('end_year') aggregate = acad_form.cleaned_data.get('aggregate') userprofile.join_college(college_name=college, branch=branch, start_year=start_year, end_year=end_year, aggregate=aggregate) from users.messages import ACCOUNT_SETTINGS_SAVED messages.success(request, ACCOUNT_SETTINGS_SAVED) return response(request, acad_settings_template, {'acad_form':acad_form})
def view_account_settings(request, settings_template): userprofile = loggedin_userprofile(request) personal_form = PersonalSettingsForm({'name':userprofile.name, 'slug':userprofile.slug}) (branch, college, start_year, end_year, aggregate) = userprofile.acad_details acad_form = AcadSettingsForm({'branch':branch, 'college':college.name if college else '', 'start_year':start_year if start_year else DEFAULT_COLLEGE_START_YEAR, 'end_year':end_year if start_year else DEFAULT_COLLEGE_END_YEAR, 'aggregate':aggregate if aggregate else ''}) if userprofile.is_student: return response(request, settings_template, {'personal_form':personal_form, 'acad_form':acad_form}) else: (workplace, designation, years_of_exp) = userprofile.work_details workinfo_form = WorkInfoSettingsForm({'workplace':workplace.name if workplace else '', 'designation':designation, 'years_of_exp':years_of_exp}) return response(request, settings_template, {'personal_form':personal_form, 'acad_form':acad_form, 'workinfo_form':workinfo_form})
def test_direct_empty_form_submission(self): data = {'branch':'CSE', 'college':'', 'start_year':'2011', 'end_year':'2015'} form = AcadSettingsForm(data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors.has_key('college'))