def test_prereq_to_multiple_prereq(self): ''' Tests editing prerequisite on a module to multiple prereq. ''' if not self.prereq_to_multiple_prereq_tested: model.add_prerequisite(self.test_module_code, self.test_prereq_code, self.test_prereq_index) prereq_units_to_change_to = [[self.test_prereq_code], [ self.test_prereq2_code, self.test_prereq3_code ]] outcome = model.edit_prerequisite(self.test_module_code, prereq_units_to_change_to) assert_true(outcome[0]) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_equal(self.test_prereq_index, prereq_info[0][0]) assert_equal(self.test_prereq_code, prereq_info[0][1]) assert_equal(self.test_prereq2_index, prereq_info[1][0]) assert_equal(self.test_prereq2_code, prereq_info[1][1]) assert_equal(self.test_prereq3_index, prereq_info[2][0]) assert_equal(self.test_prereq3_code, prereq_info[2][1]) model.delete_all_prerequisite(self.test_module_code) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(len(prereq_info) == 0) return
def test_edit_prereq_already_in_preclusion(self): ''' Tests editing prerequisite on a module to prereqs which are also preclusions of that module. Note: this test case should fail to edit. ''' if not self.edit_prereq_non_existent_tested: model.add_preclusion(self.test_module_code, self.test_prereq_code) prereq_units_to_change_to = [[self.test_prereq_code]] outcome = model.edit_prerequisite(self.test_module_code, prereq_units_to_change_to) assert_false(outcome[0]) error_list = outcome[1] assert_equal(len(error_list), 1) assert_equal(error_list[0], [ self.test_prereq_code, self.ERROR_MSG_MODULE_PREREQ_ALREADY_PRECLUSION ]) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_true(len(prereq_info) == 0) model.delete_all_preclusion(self.test_module_code) preclude_info = model.get_preclusion(self.test_module_code) assert_true(len(preclude_info) == 0)
def test_prereq_delete_all(self): ''' Tests deleting all prerequisites of specific module. ''' if not self.prereq_delete_all_tested: model.add_module(self.test_prereq_code, self.test_module_name, self.test_module_desc, self.test_module_mc, self.test_module_status) model.add_module(self.test_prereq2_code, self.test_module_name, self.test_module_desc, self.test_module_mc, self.test_module_status) model.add_prerequisite(self.test_module_code, self.test_prereq_code, self.test_prereq_index) model.add_prerequisite(self.test_module_code, self.test_prereq2_code, self.test_prereq2_index) outcome = model.delete_all_prerequisite(self.test_module_code) assert_true(outcome) model.delete_module(self.test_prereq_code) model.delete_module(self.test_prereq2_code) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(len(prereq_info) == 0) return
def test_no_prereq_to_one_prereq(self): ''' Tests editing prerequisite on a module originally with no prereq to 1 prereq. ''' if not self.no_prereq_to_one_prereq_tested: prereq_units_to_change_to = [[self.test_prereq_code]] outcome = model.edit_prerequisite(self.test_module_code, prereq_units_to_change_to) assert_true(outcome[0]) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_equal(self.test_prereq_index, prereq_info[0][0]) assert_equal(self.test_prereq_code, prereq_info[0][1]) model.delete_all_prerequisite(self.test_module_code) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(len(prereq_info) == 0) return
def test_edit_prereq_multiple_errors(self): ''' Tests editing prerequisite on a module to prereqs which causes multiple errors. Note: this test case should fail to edit. ''' if not self.edit_prereq_multiple_errors_tested: model.add_prerequisite(self.test_module_code, self.test_prereq_code, self.test_prereq_index) prereq_units_to_change_to = [[self.test_module_code], [self.test_invalid_module_code]] outcome = model.edit_prerequisite(self.test_module_code, prereq_units_to_change_to) assert_false(outcome[0]) error_list = outcome[1] assert_equal(len(error_list), 2) assert_equal(error_list[0], [ self.test_module_code, self.ERROR_MSG_MODULE_CANNOT_BE_ITSELF ]) assert_equal(error_list[1], [ self.test_invalid_module_code, self.ERROR_MSG_MODULE_DOESNT_EXIST ]) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_equal(self.test_prereq_index, prereq_info[0][0]) assert_equal(self.test_prereq_code, prereq_info[0][1]) model.delete_all_prerequisite(self.test_module_code) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(len(prereq_info) == 0)
def test_prereq_CRD(self): ''' Tests creating, reading and deleting of prerequisites. ''' if not self.prereq_CRD_tested: model.add_module(self.test_prereq_code, self.test_module_name, self.test_module_desc, self.test_module_mc, self.test_module_status) model.add_prerequisite(self.test_module_code, self.test_prereq_code, self.test_prereq_index) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_equal(self.test_prereq_index, prereq_info[0][0]) assert_equal(self.test_prereq_code, prereq_info[0][1]) model.delete_prerequisite(self.test_module_code, self.test_prereq_code) model.delete_module(self.test_prereq_code) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(len(prereq_info) == 0) return
def test_no_prereq_to_no_prereq(self): ''' Tests editing prerequisite on a module originally with no prereq to no prereq. ''' if not self.no_prereq_to_no_prereq_tested: prereq_units_to_change_to = [] outcome = model.edit_prerequisite(self.test_module_code, prereq_units_to_change_to) assert_true(outcome[0]) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_true(len(prereq_info) == 0) return
def test_edit_prereq_non_existent_modules(self): ''' Tests editing prerequisite on a module to prereqs which does not exist, note: this test case should fail to edit. ''' if not self.edit_prereq_non_existent_tested: model.add_prerequisite(self.test_module_code, self.test_prereq_code, self.test_prereq_index) prereq_units_to_change_to = [[self.test_prereq2_code], [self.test_invalid_module_code]] outcome = model.edit_prerequisite(self.test_module_code, prereq_units_to_change_to) assert_false(outcome[0]) error_list = outcome[1] assert_equal(len(error_list), 1) assert_equal(error_list[0], [ self.test_invalid_module_code, self.ERROR_MSG_MODULE_DOESNT_EXIST ]) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_equal(self.test_prereq_index, prereq_info[0][0]) assert_equal(self.test_prereq_code, prereq_info[0][1]) model.delete_all_prerequisite(self.test_module_code) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(len(prereq_info) == 0) # Test another form model.add_prerequisite(self.test_module_code, self.test_prereq_code, self.test_prereq_index) prereq_units_to_change_to = [[ self.test_invalid_module_code, self.test_prereq2_code ]] outcome = model.edit_prerequisite(self.test_module_code, prereq_units_to_change_to) assert_false(outcome[0]) error_list = outcome[1] assert_equal(len(error_list), 1) assert_equal(error_list[0], [ self.test_invalid_module_code, self.ERROR_MSG_MODULE_DOESNT_EXIST ]) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(prereq_info is not None) assert_equal(self.test_prereq_index, prereq_info[0][0]) assert_equal(self.test_prereq_code, prereq_info[0][1]) model.delete_all_prerequisite(self.test_module_code) prereq_info = model.get_prerequisite(self.test_module_code) assert_true(len(prereq_info) == 0) return