def test_unmounted_from_both_sems(self): ''' Tests that a module that is unmounted from both sems will have the tentative-mounting values '0' and '0' ''' model.delete_tenta_mounting('BB1001', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1001', self.next_ay+' Sem 2') self.load_tenta_full_mounting_plan() full_mounting_plan = self.tentative_mounting_handler.full_mounting_plan test_module_code = "BB1001" test_module_sem_1 = -2 test_module_sem_2 = -2 has_test_module = False for subplan in full_mounting_plan: if subplan[0] == test_module_code: has_test_module = True test_module_sem_1 = subplan[2] test_module_sem_2 = subplan[3] break assert_true(has_test_module) assert_equal(test_module_sem_1, 0) assert_equal(test_module_sem_2, 0) model.add_tenta_mounting('BB1001', self.next_ay+' Sem 1', 10) model.add_tenta_mounting('BB1001', self.next_ay+' Sem 2', 20) self.load_tenta_full_mounting_plan()
def test_unmounted_from_sem_2(self): ''' Tests that a module that is unmounted from sem 2 will have the tentative-mounting value of '0' for sem 2 ''' test_module_code = "BB1003" model.delete_tenta_mounting(test_module_code, self.next_ay + ' Sem 2') self.module_overview_handler.load_fixed_mounting_plan(test_module_code) self.module_overview_handler.load_tenta_mounting_plan(test_module_code) tenta_mounting_plan = self.module_overview_handler.tenta_mounting_plan assert_true(len(tenta_mounting_plan) > 0) tenta_sem_2_mounting_value = tenta_mounting_plan[1][1] tenta_sem_2_quota = tenta_mounting_plan[1][2] assert_equal(tenta_sem_2_mounting_value, 0) assert_equal(tenta_sem_2_quota, '-') self.mounting_view_handler.load_mounting_info( test_module_code, self.current_ay + ' Sem 2') assert_equal(self.mounting_view_handler.mounting_status, 1) assert_equal(self.mounting_view_handler.quota, 40) self.mounting_view_handler.load_mounting_info(test_module_code, self.next_ay + ' Sem 2') assert_equal(self.mounting_view_handler.mounting_status, 0) assert_equal(self.mounting_view_handler.quota, '-') model.add_tenta_mounting(test_module_code, self.next_ay + ' Sem 2', 40)
def test_tenta_mounting_CRD(self): ''' Tests creating, reading and deleting of tentative mountings. ''' if not self.tenta_mounting_CRD_tested: model.add_tenta_mounting(self.test_module_code, self.test_module_tenta_mounting_s1, self.test_module_quota1) model.add_tenta_mounting(self.test_module_code, self.test_module_tenta_mounting_s2, self.test_module_quota2) mounting_data = model.get_tenta_mounting_and_quota( self.test_module_code) assert_equal(self.test_module_mounted_count, len(mounting_data)) mounting_s1 = mounting_data[0][0] mounting_s2 = mounting_data[1][0] quota_s1 = mounting_data[0][1] quota_s2 = mounting_data[1][1] assert_equal(self.test_module_tenta_mounting_s1, mounting_s1) assert_equal(self.test_module_tenta_mounting_s2, mounting_s2) assert_equal(self.test_module_quota1, quota_s1) assert_equal(self.test_module_quota2, quota_s2) model.delete_tenta_mounting(self.test_module_code, self.test_module_tenta_mounting_s1) model.delete_tenta_mounting(self.test_module_code, self.test_module_tenta_mounting_s2) mounting_data = model.get_tenta_mounting_and_quota( self.test_module_code) assert_true(len(mounting_data) == 0) return
def tearDown(self): ''' Clean up the database after all test cases are ran ''' model.delete_prerequisite(self.test_module_code, self.test_prereq_code) model.delete_tenta_mounting(self.test_module_code, self.test_module_tenta_mounting_s1) model.delete_module(self.test_module_code)
def test_edit_multiple_modules_mountings(self): ''' Test that Edit All function can edit multiple modules' mounting(s) ''' test_data = {} # Dummy Module 1: Mount in Sem 2 test_mod_1_code = self.DUMMY_MODULE_CODE_1 test_mod_1_mounting = True #mounted test_mod_1_quota = 200 #quota added test_data[test_mod_1_code+'_isEdited'] = "True" test_data[test_mod_1_code+'_Sem2Mounting'] = test_mod_1_mounting #modified to true test_data[test_mod_1_code+'_Sem2Quota'] = test_mod_1_quota # Dummy Module 3: Unmount from both sems test_mod_2_code = self.DUMMY_MODULE_CODE_3 test_mod_2_mounting_1 = False #unmounted test_mod_2_quota_1 = False #quota will be false because unmounted test_mod_2_mounting_2 = False #unmounted test_mod_2_quota_2 = False #quota will be false because unmounted test_data[test_mod_2_code+'_isEdited'] = "True" # Because mounting is false (unchecked), no mounting value will be returned by the UI test_data[test_mod_2_code+'_Sem1Quota'] = test_mod_2_quota_1 # Because mounting is false (unchecked), no mounting value will be returned by the UI test_data[test_mod_2_code+'_Sem2Quota'] = test_mod_2_quota_2 self.edit_all_handler.POST(test_data) mounting = model.get_mounting_of_target_tenta_ay_sem(test_mod_1_code, self.next_ay+" Sem 2") quota = model.get_quota_of_target_tenta_ay_sem(test_mod_1_code, self.next_ay+" Sem 2") assert_equal(mounting, test_mod_1_mounting) assert_equal(quota, test_mod_1_quota) mounting = model.get_mounting_of_target_tenta_ay_sem(test_mod_2_code, self.next_ay+" Sem 1") quota = model.get_quota_of_target_tenta_ay_sem(test_mod_2_code, self.next_ay+" Sem 1") assert_equal(mounting, test_mod_2_mounting_1) assert_equal(quota, test_mod_2_quota_1) mounting = model.get_mounting_of_target_tenta_ay_sem(test_mod_2_code, self.next_ay+" Sem 2") quota = model.get_quota_of_target_tenta_ay_sem(test_mod_2_code, self.next_ay+" Sem 2") assert_equal(mounting, test_mod_2_mounting_2) assert_equal(quota, test_mod_2_quota_2) model.delete_tenta_mounting(test_mod_1_code, self.next_ay+" Sem 2") model.add_tenta_mounting(test_mod_2_code, self.next_ay+" Sem 1", self.DUMMY_QUOTA_3) model.add_tenta_mounting(test_mod_2_code, self.next_ay+" Sem 2", self.DUMMY_QUOTA_0)
def test_edit_single_module_mounting(self): ''' Test that Edit All function can edit a single module's mounting ''' test_module_code = self.DUMMY_MODULE_CODE_1 test_mounting = False #unmounted test_quota = False #quota will be false because unmounted # Unmount from Sem 1 test_data = {} test_data[test_module_code+'_isEdited'] = "True" # Because mounting is false (unchecked), no mounting value will be returned by the UI test_data[test_module_code+'_Sem1Quota'] = test_quota self.edit_all_handler.POST(test_data) mounting = model.get_mounting_of_target_tenta_ay_sem(test_module_code, self.next_ay+" Sem 1") quota = model.get_quota_of_target_tenta_ay_sem(test_module_code, self.next_ay+" Sem 1") assert_equal(mounting, test_mounting) assert_equal(quota, test_quota) model.add_tenta_mounting(test_module_code, self.next_ay+" Sem 1", self.DUMMY_QUOTA_1) # Mount in Sem 2 test_module_code = self.DUMMY_MODULE_CODE_2 test_mounting = True test_quota = 200 test_data = {} test_data[test_module_code+'_isEdited'] = "True" test_data[test_module_code+'_Sem2Mounting'] = True #modified to true test_data[test_module_code+'_Sem2Quota'] = test_quota #modified self.edit_all_handler.POST(test_data) mounting = model.get_mounting_of_target_tenta_ay_sem(test_module_code, self.next_ay+" Sem 2") quota = model.get_quota_of_target_tenta_ay_sem(test_module_code, self.next_ay+" Sem 2") assert_equal(mounting, test_mounting) assert_equal(quota, test_quota) model.delete_tenta_mounting(test_module_code, self.next_ay+" Sem 2")
def tearDown(self): ''' Clean up the database after all test cases are ran ''' model.delete_fixed_mounting('BB1001', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1001', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB1002', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1003', self.current_ay+' Sem 2') model.delete_tenta_mounting('BB1001', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1001', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB1002', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1003', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB9999', 'AY 36/37 Sem 1') model.delete_module('BB1001') model.delete_module('BB1002') model.delete_module('BB1003') model.delete_module('BB1004') model.delete_module('BB9999')
def POST(self): ''' Handles the submission of the 'Edit Specific Module Info' page ''' input_data = model.validate_input(web.input(), ["code", "aysem"], is_future=True, show_404=False) module_code = None ay_sem = None try: module_code = input_data.code ay_sem = input_data.aysem mounting_status = input_data.mountingStatus except AttributeError: return Outcome().POST("edit_mounting", False, module_code, ay_sem) try: quota = input_data.quota if quota == "": quota = None except AttributeError: quota = None outcome = None # If quota is being set by the user, it should not fall below 0. # Otherwise, if the user is not interested in leaving a value for # the quota, leaving it blank (none) is acceptable. if quota is not None: try: quota = int(quota) if quota < 0 or quota > 999: outcome = False except ValueError: # quota is not None or int outcome = False if outcome is not False: module_info = model.get_module(module_code) if module_info is None: outcome = False elif ay_sem not in self.list_of_future_ay_sems: outcome = False else: if mounting_status == "Mounted": outcome = None old_mounting_status = model.get_mounting_of_target_tenta_ay_sem(module_code, ay_sem) if old_mounting_status is True: outcome = model.update_quota(module_code, ay_sem, quota) else: outcome = model.add_tenta_mounting(module_code, ay_sem, quota) elif mounting_status == "Not Mounted": outcome = model.delete_tenta_mounting(module_code, ay_sem) else: outcome = False return Outcome().POST("edit_mounting", outcome, module_code, ay_sem)
def POST(self, *test_data): ''' Handles the restoration of module info ''' if test_data: # for testing purposes input_data = test_data[0] else: input_data = model.validate_input(web.input(), ["code", "restore_type"]) module_code = input_data.code restore_type = input_data.restoreType if restore_type.lower() == "quota": model.validate_input(input_data, ["aysem"]) ay_sem = input_data.aysem quota = input_data.quota if quota == "": quota = None outcome = model.update_quota(module_code, ay_sem, quota) if not test_data: return Outcome().POST("restore_module", outcome, module_code) elif restore_type.lower() == "mounting": model.validate_input(input_data, ["aysem"]) target_ay_sem = input_data.aysem mounting_change = int(input_data.mountingChange) outcome = None if mounting_change == 1: # Is mounted, so should revert to unmounted outcome = model.delete_tenta_mounting(module_code, target_ay_sem) elif mounting_change == 0: # Is unmounted, so should revert to mounted current_ay_sem = input_data.currentAySem quota = model.get_quota_of_target_fixed_ay_sem( module_code, current_ay_sem) outcome = model.add_tenta_mounting(module_code, target_ay_sem, quota) if not test_data: return Outcome().POST("restore_module", outcome, module_code) elif restore_type.lower() == "moduledetails": original_module_details = model.get_original_module_info( module_code) model.remove_original_module_info(module_code) outcome = model.update_module(module_code, original_module_details[1], original_module_details[2], original_module_details[3]) if not test_data: return Outcome().POST("restore_module", outcome, module_code)
def test_unmounted_from_both_sems(self): ''' Tests that a module that is unmounted from both sems will have the tentative-mounting values '0' and '0' ''' test_module_code = "BB1001" model.delete_tenta_mounting(test_module_code, self.next_ay + ' Sem 1') model.delete_tenta_mounting(test_module_code, self.next_ay + ' Sem 2') self.module_overview_handler.load_fixed_mounting_plan(test_module_code) self.module_overview_handler.load_tenta_mounting_plan(test_module_code) tenta_mounting_plan = self.module_overview_handler.tenta_mounting_plan assert_true(len(tenta_mounting_plan) > 0) tenta_sem_1_mounting_value = tenta_mounting_plan[0][1] tenta_sem_1_quota = tenta_mounting_plan[0][2] tenta_sem_2_mounting_value = tenta_mounting_plan[1][1] tenta_sem_2_quota = tenta_mounting_plan[1][2] assert_equal(tenta_sem_1_mounting_value, 0) assert_equal(tenta_sem_1_quota, '-') assert_equal(tenta_sem_2_mounting_value, 0) assert_equal(tenta_sem_2_quota, '-') self.mounting_view_handler.load_mounting_info( test_module_code, self.current_ay + ' Sem 1') assert_equal(self.mounting_view_handler.mounting_status, 1) assert_equal(self.mounting_view_handler.quota, 10) self.mounting_view_handler.load_mounting_info( test_module_code, self.current_ay + ' Sem 2') assert_equal(self.mounting_view_handler.mounting_status, 1) assert_equal(self.mounting_view_handler.quota, 20) self.mounting_view_handler.load_mounting_info(test_module_code, self.next_ay + ' Sem 1') assert_equal(self.mounting_view_handler.mounting_status, 0) assert_equal(self.mounting_view_handler.quota, '-') self.mounting_view_handler.load_mounting_info(test_module_code, self.next_ay + ' Sem 2') assert_equal(self.mounting_view_handler.mounting_status, 0) assert_equal(self.mounting_view_handler.quota, '-') model.add_tenta_mounting(test_module_code, self.next_ay + ' Sem 1', 10) model.add_tenta_mounting(test_module_code, self.next_ay + ' Sem 2', 20)
def POST(self, *test_data): ''' Handles the editing operations for all mountings and quotas ''' if test_data: input_data = test_data[0] else: input_data = web.input() all_modules = model.get_all_modules() target_ay = model.get_next_ay(model.get_current_ay()) for module in all_modules: module_code = module[0] try: is_module_edited = input_data[module_code+"_isEdited"] except KeyError: is_module_edited = "False" if is_module_edited == "True": try: sem1_mounting = input_data[module_code+"_Sem1Mounting"] sem1_mounting = True except KeyError: sem1_mounting = False try: sem2_mounting = input_data[module_code+"_Sem2Mounting"] sem2_mounting = True except KeyError: sem2_mounting = False try: sem1_quota = input_data[module_code+"_Sem1Quota"] if sem1_quota == "": # quota = '?' sem1_quota = None except KeyError: # quota = '-' sem1_quota = None if sem1_quota is not None: try: sem1_quota = int(sem1_quota) if sem1_quota < 0 or sem1_quota > 999: if test_data: return False else: return Outcome().POST("edit_all_mountings_and_quotas", False, None) except ValueError: # quota is not an integer if test_data: return False else: return Outcome().POST("edit_all_mountings_and_quotas", False, None) try: sem2_quota = input_data[module_code+"_Sem2Quota"] if sem2_quota == "": # quota = '?' sem2_quota = None except KeyError: # quota = '-' sem2_quota = None if sem2_quota is not None: try: sem2_quota = int(sem2_quota) if sem2_quota < 0 or sem2_quota > 999: if test_data: return False else: return Outcome().POST("edit_all_mountings_and_quotas", False, None) except ValueError: # quota is not an integer if test_data: return False else: return Outcome().POST("edit_all_mountings_and_quotas", False, None) target_aysem = target_ay+" Sem 1" outcome = None if sem1_mounting is True: old_mounting = model.get_mounting_of_target_tenta_ay_sem(module_code, target_aysem) if old_mounting is True: outcome = model.update_quota(module_code, target_aysem, sem1_quota) else: outcome = model.add_tenta_mounting(module_code, target_aysem, sem1_quota) else: outcome = model.delete_tenta_mounting(module_code, target_aysem) if outcome is False: return Outcome().POST("edit_all_mountings_and_quotas", False, None) target_aysem = target_ay+" Sem 2" outcome = None if sem2_mounting is True: old_mounting = model.get_mounting_of_target_tenta_ay_sem(module_code, target_aysem) if old_mounting is True: outcome = model.update_quota(module_code, target_aysem, sem2_quota) else: outcome = model.add_tenta_mounting(module_code, target_aysem, sem2_quota) else: outcome = model.delete_tenta_mounting(module_code, target_aysem) if outcome is False: return Outcome().POST("edit_all_mountings_and_quotas", False, None) if not test_data: return Outcome().POST("edit_all_mountings_and_quotas", True, None)
def tearDown(self): ''' Clean up the database after all test cases are ran ''' model.delete_student_plan('D1000000A', 'PT1001', self.current_ay+' Sem 1') model.delete_student_plan('D1000000A', 'PT1002', self.current_ay+' Sem 2') model.delete_student_plan('D2000000A', 'PT1001', self.current_ay+' Sem 1') model.delete_student_plan('D2000000A', 'PT1002', self.current_ay+' Sem 2') model.delete_student_plan('D1000000A', 'PT1003', self.next_ay+' Sem 1') model.delete_student_plan('D3000000A', 'PT1001', self.current_ay+' Sem 1') model.delete_student_plan('D3000000A', 'PT1004', self.next_ay+' Sem 2') model.delete_student_plan('D5000000A', 'PT1001', self.current_ay+' Sem 1') model.delete_student_plan('D5000001A', 'PT1001', self.current_ay+' Sem 1') model.delete_student_plan('D5000002A', 'PT1001', self.current_ay+' Sem 2') model.delete_student_plan('D5000000A', 'PT1005', self.next_ay+' Sem 1') model.delete_student_plan('D5000001A', 'PT1005', self.next_ay+' Sem 1') model.delete_student_plan('D5000002A', 'PT1005', self.next_ay+' Sem 1') model.delete_student_plan('D5000003A', 'PT1005', self.next_ay+' Sem 1') model.delete_student_plan('D5000004A', 'PT1005', self.next_ay+' Sem 1') model.delete_tenta_mounting('PT1001', self.next_ay+' Sem 1') model.delete_tenta_mounting('PT1002', self.next_ay+' Sem 2') model.delete_tenta_mounting('PT1003', self.next_ay+' Sem 1') model.delete_tenta_mounting('PT1003', self.next_ay+' Sem 2') model.delete_tenta_mounting('PT1004', self.next_ay+' Sem 2') model.delete_tenta_mounting('PT1005', self.next_ay+' Sem 1') model.delete_fixed_mounting('PT1001', self.current_ay+' Sem 1') model.delete_fixed_mounting('PT1001', self.current_ay+' Sem 2') model.delete_fixed_mounting('PT1002', self.current_ay+' Sem 2') model.delete_module('PT1001') model.delete_module('PT1002') model.delete_module('PT1003') model.delete_module('PT1004') model.delete_module('PT1005')
def tearDown(self): ''' Clean up the database after all test cases are ran ''' model.NUMBER_OF_AY_SEMS_IN_SYSTEM = 2 model.delete_fixed_mounting('BB1001', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1001', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB1002', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1002', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB1003', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1003', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB1004', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1004', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB1005', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1005', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB1006', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB1006', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB2001', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB2001', self.current_ay+' Sem 2') model.delete_fixed_mounting('BB2002', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB2003', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB2004', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB3001', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB3002', self.current_ay+' Sem 1') model.delete_fixed_mounting('BB3004', self.current_ay+' Sem 2') model.delete_tenta_mounting('BB1001', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1001', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB1002', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1002', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB1003', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1003', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB1004', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1004', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB1005', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1005', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB1006', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB1006', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB2001', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB2002', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB2002', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB2003', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB2004', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB2004', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB3001', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB3002', self.next_ay+' Sem 1') model.delete_tenta_mounting('BB3003', self.next_ay+' Sem 2') model.delete_tenta_mounting('BB3004', self.next_ay+' Sem 2') model.delete_module('BB1001') model.delete_module('BB1002') model.delete_module('BB1003') model.delete_module('BB1004') model.delete_module('BB1005') model.delete_module('BB1006') model.delete_module('BB2001') model.delete_module('BB2002') model.delete_module('BB2003') model.delete_module('BB2004') model.delete_module('BB3001') model.delete_module('BB3002') model.delete_module('BB3003') model.delete_module('BB3004') model.delete_module('BB3005') model.delete_module('BB3006')