def test_get_candidate_by_id(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save1 = dbc.Candidate() to_save1.cnp = 123456789 to_save1.first_name = "student1 in town" to_save1.surname = " name1 " to_save1.email = "*****@*****.**" to_save1.info_grade = 6.7 to_save1.math_grade = 8.9 to_save1.high_school_avg_grade = 9.5 to_save1.admission_grade = 7.8 to_save1.first_option = 2 to_save1.second_option = 1 to_save2 = dbc.Candidate() to_save2.cnp = 987654321 to_save2.first_name = " student2 in town" to_save2.surname = " name2" to_save2.email = "*****@*****.**" to_save2.info_grade = 6.7 to_save2.math_grade = 8.9 to_save2.high_school_avg_grade = 9.5 to_save2.admission_grade = 7.8 to_save2.first_option = 2 to_save2.second_option = 1 dbc.save_candidate(to_save1) dbc.save_candidate(to_save2) found = dbc.get_candidate_by_id(123456789) self.assertEqual(to_save1.to_xml(), found.to_xml())
def test_get_all_candidates(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() sp1 = dbc.Specialization() sp1.capacity = 92 sp1.name = "specialization 1" sp1.identifier = 1 sp2 = dbc.Specialization() sp2.capacity = 92 sp2.name = "specialization 2" sp2.identifier = 2 dbc.save_specialization(sp1) dbc.save_specialization(sp2) to_save1 = dbc.Candidate() to_save1.cnp = 123456789 to_save1.first_name = "student1 in town" to_save1.surname = " name1 " to_save1.email = "*****@*****.**" to_save1.info_grade = 6.7 to_save1.math_grade = 8.9 to_save1.high_school_avg_grade = 9.5 to_save1.admission_grade = 7.8 to_save1.first_option = 2 to_save1.second_option = 1 to_save2 = dbc.Candidate() to_save2.cnp = 987654321 to_save2.first_name = " student2 in town" to_save2.surname = " name2" to_save2.email = "*****@*****.**" to_save2.info_grade = 6.7 to_save2.math_grade = 8.9 to_save2.high_school_avg_grade = 9.5 to_save2.admission_grade = 7.8 to_save2.first_option = 2 to_save2.second_option = 1 dbc.save_candidate(to_save1) dbc.save_candidate(to_save2) found = dbc.get_all_candidates() self.assertEqual(2, len(found)) found = dbc.get_all_candidates(1) self.assertEqual(2, len(found))
def test_save_candidate_incorrect_data(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Candidate() to_save.surname = 1234 result = dbc.save_candidate(to_save) self.assertEqual('OK', result)
def test_save_candidate_misiing_data(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Candidate() result = dbc.save_candidate(to_save) found = dbc.get_candidate_by_id(0) self.assertEqual('OK', result) self.assertEqual(to_save.to_xml(), found.to_xml()) found.print()
def test_update_specialization_not_found(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() original = dbc.Candidate() original.cnp = 123456789 original.first_name = "student1 in town" original.surname = " name1 " original.email = "*****@*****.**" original.info_grade = 6.7 original.math_grade = 8.9 original.high_school_avg_grade = 9.5 original.admission_grade = 7.8 original.first_option = 2 original.second_option = 1 dbc.save_candidate(original) updated = dbc.Candidate() updated.cnp = 987654321 updated.first_name = "this is my name" updated.surname = " my surname " updated.email = " i got a new mail" updated.info_grade = 6.7 updated.math_grade = 8.9 updated.high_school_avg_grade = 9.5 updated.admission_grade = 7.8 updated.first_option = 2 updated.second_option = 1 result = dbc.update_candidate(updated) found = dbc.get_candidate_by_id(123456789) self.assertEqual(original.to_xml(), found.to_xml()) self.assertEqual('Entry not found', result)
def test_save_new_candidate(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Candidate() to_save.cnp = 987654321 to_save.first_name = "new student in town" to_save.surname = " mhm " to_save.email = "*****@*****.**" to_save.info_grade = 6.7 to_save.math_grade = 8.9 to_save.high_school_avg_grade = 9.5 to_save.admission_grade = 7.8 to_save.first_option = 2 to_save.second_option = 1 result = dbc.save_candidate(to_save) saved = dbc.get_candidate_by_id(987654321) self.assertEqual(to_save.to_xml(), saved.to_xml()) self.assertEqual('OK', result)
def add_candidate(): form = AddCandidateForm() actions = menu_actions.menu if form.validate_on_submit(): new_candidate = DbC.Candidate() new_candidate.cnp = form.cnp.data new_candidate.first_name = form.first_name.data new_candidate.surname = form.surname.data new_candidate.email = form.email.data new_candidate.info_grade = form.info_grade.data new_candidate.math_grade = form.math_grade.data new_candidate.high_school_avg_grade = form.high_school_avg_grade.data new_candidate.admission_grade = form.admission_grade.data new_candidate.first_option = form.first_option.data new_candidate.second_option = form.second_option.data DbC.save_candidate(new_candidate) flash('Candidate with CNP {} submitted.'.format(form.cnp.data)) return redirect('/index') return render_template('candidate_form.html', title='Add Candidate', form=form, actions=actions)
def test_save_duplicate_candidate(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Candidate() to_save.cnp = 987654321 to_save.first_name = "new student in town" to_save.surname = " mhm " to_save.email = "*****@*****.**" to_save.info_grade = 6.7 to_save.math_grade = 8.9 to_save.high_school_avg_grade = 9.5 to_save.admission_grade = 7.8 to_save.first_option = 2 to_save.second_option = 1 dbc.save_candidate(to_save) result = dbc.save_candidate(to_save) saved = dbc.get_all_candidates() self.assertEqual(1, len(saved)) self.assertEqual('ALREADY_EXISTING', result)