示例#1
0
    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))
示例#2
0
    def test_get_all_results(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.Specialization()
        to_save.capacity = 92
        to_save.name = "new specialization"
        to_save.identifier = 0

        result = dbc.save_specialization(to_save)

        to_save1 = dbc.AdmissionResult()
        to_save1.candidate_cnp = 987654321
        to_save1.allocation = dbc.AdmissionStatus.FEE
        to_save1.specialization_id = 0
        to_save1.final_score = 8.6

        to_save2 = dbc.AdmissionResult()
        to_save2.candidate_cnp = 1234567
        to_save2.allocation = dbc.AdmissionStatus.FREE
        to_save2.specialization_id = 0
        to_save2.final_score = 9.0

        dbc.save_admission_result_for_candidate(to_save1)
        dbc.save_admission_result_for_candidate(to_save2)

        found = dbc.get_admission_results()

        self.assertEqual(2, len(found))

        found = dbc.get_admission_results(1)

        self.assertEqual(2, len(found))
示例#3
0
    def test_get_all_specializations(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save1 = dbc.Specialization()
        to_save1.capacity = 11
        to_save1.name = "new specialization 1"
        to_save1.identifier = 1

        to_save2 = dbc.Specialization()
        to_save2.capacity = 22
        to_save2.name = "new specialization 2"
        to_save2.identifier = 2

        dbc.save_specialization(to_save1)
        dbc.save_specialization(to_save2)

        found = dbc.get_all_specializations()

        self.assertEqual(2, len(found))
示例#4
0
    def test_update_specialization_not_found(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        original = dbc.Specialization()
        original.capacity = 11
        original.name = "new specialization 1"
        original.identifier = 1

        dbc.save_specialization(original)

        updated = dbc.Specialization()
        updated.capacity = 21
        updated.name = "updated specialization 1"
        updated.identifier = 2

        result = dbc.update_specialization(updated)

        found = dbc.get_specialization_by_id(1)

        self.assertEqual(original.to_xml(), found.to_xml())
        self.assertEqual('Entry not found', result)
示例#5
0
    def test_save_new_specialization(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.Specialization()
        to_save.capacity = 92
        to_save.name = "new specialization"
        to_save.identifier = 1

        result = dbc.save_specialization(to_save)
        saved = dbc.get_specialization_by_id(1)

        self.assertEqual(to_save.to_xml(), saved.to_xml())
        self.assertEqual('OK', result)
示例#6
0
    def test_save_specialization_no_id(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.Specialization()
        to_save.name = 'No id'
        to_save.capacity = 92

        result = dbc.save_specialization(to_save)
        found = dbc.get_specialization_by_id(-1)

        self.assertEqual('OK', result)
        self.assertEqual(to_save.to_xml(), found.to_xml())
        found.print()
示例#7
0
    def test_delete_specialization_by_id(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save1 = dbc.Specialization()
        to_save1.capacity = 11
        to_save1.name = "new specialization 1"
        to_save1.identifier = 1

        to_save2 = dbc.Specialization()
        to_save2.capacity = 22
        to_save2.name = "new specialization 2"
        to_save2.identifier = 2

        dbc.save_specialization(to_save1)
        dbc.save_specialization(to_save2)

        dbc.delete_specialization_by_id(2)

        found1 = dbc.get_specialization_by_id(1)
        found2 = dbc.get_specialization_by_id(2)

        self.assertEqual(to_save1.to_xml(), found1.to_xml())
        self.assertEqual(None, found2)
示例#8
0
    def test_save_specialization_incorrect_data(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.Specialization()
        to_save.identifier = 1
        to_save.name = 4567
        to_save.capacity = 'Incorrect capacity'

        result = dbc.save_specialization(to_save)
        found = dbc.get_specialization_by_id(1)

        self.assertEqual('OK', result)
        self.assertEqual(to_save.to_xml(), found.to_xml())
        found.print()
示例#9
0
    def test_save_duplicate_specialization(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.Specialization()
        to_save.capacity = 92
        to_save.name = "new specialization"
        to_save.identifier = 1

        dbc.save_specialization(to_save)

        result = dbc.save_specialization(to_save)
        saved = dbc.get_all_specializations()

        self.assertEqual(1, len(saved))
        self.assertEqual('ALREADY_EXISTING', result)