def test_valid_form_submission(self): datas = [{'workplace':'Sri Venkatesa Perumal College of Engineering & Technology.', 'designation':'Computer Science Professor', 'years_of_exp':'2'}, {'workplace':'Infosys', 'designation':'Software Architect', 'years_of_exp':'4'}, {'workplace':'IBM Global-Services', 'designation':'IT Guy-Bangalore', 'years_of_exp':'1.5'}] for data in datas: form = WorkInfoSettingsForm(data) self.assertTrue(form.is_valid()) self.assertFalse(form.errors)
def test_invalid_form_submission(self): invalid_workplace_names = ('()(**&*&', '%$%$%$%') datas = [{'workplace':invalid_workplace_names[0], 'designation':'Computer Science Professor', 'years_of_exp':'2'}, {'workplace':invalid_workplace_names[1], 'designation':'Software Architect', 'years_of_exp':'1.5'}] for data in datas: form = WorkInfoSettingsForm(data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors) self.assertTrue(form.errors.has_key('workplace')) self.assertFalse(form.errors.has_key('designation')) self.assertFalse(form.errors.has_key('years_of_exp'))
def view_get_workinfo_settings(request, workinfo_settings_template): userprofile = loggedin_userprofile(request) (workplace, designation, years_of_exp) = userprofile.work_details form = WorkInfoSettingsForm({'workplace':workplace if workplace else '', 'designation':designation, 'years_of_exp':years_of_exp}) return response(request, workinfo_settings_template, {'workinfo_form':form})
def view_save_workinfo_settings(request, workinfo_settings_template): if request.method == 'GET': return view_get_workinfo_settings(request, workinfo_settings_template) userprofile = loggedin_userprofile(request) form = WorkInfoSettingsForm(post_data(request)) if form.is_valid(): workplace = form.cleaned_data.get('workplace') designation = form.cleaned_data.get('designation') years_of_exp = form.cleaned_data.get('years_of_exp') #TODO:Currently a Professor getting a corporate job is not handled if userprofile.is_student: workplace_type = 'Company' userprofile.make_employee() elif userprofile.is_employee: workplace_type = 'Company' else: workplace_type = 'College' userprofile.make_professor() userprofile.join_workplace(workplace, workplace_type, designation, years_of_exp) from users.messages import ACCOUNT_SETTINGS_SAVED messages.success(request, ACCOUNT_SETTINGS_SAVED) return response(request, workinfo_settings_template, {'workinfo_form':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_empty_form_submission(self): data = {'workplace':'', 'designation':'', 'years_of_exp':''} form = WorkInfoSettingsForm(data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors)