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_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 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'))