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