def test_update_module(self): ''' Tests updating of module info ''' # Update one field model.update_module(self.test_module_code, "Dummy module 2", self.test_module_desc, self.test_module_mc) module_info = model.get_module(self.test_module_code) assert_equal(self.test_module_code, module_info[0]) assert_equal("Dummy module 2", module_info[1]) assert_equal(self.test_module_desc, module_info[2]) assert_equal(self.test_module_mc, module_info[3]) assert_equal(self.test_module_status, module_info[4].rstrip()) # Update multiple fields model.update_module(self.test_module_code, "Dummy module 2", "Dummy description 2", 2) module_info = model.get_module(self.test_module_code) assert_equal(self.test_module_code, module_info[0]) assert_equal("Dummy module 2", module_info[1]) assert_equal("Dummy description 2", module_info[2]) assert_equal(2, module_info[3]) assert_equal(self.test_module_status, module_info[4].rstrip()) # Update fails because MC cannot be a string of alphabets outcome = model.update_module(self.test_module_code, "Dummy module 2", "Dummy description 2", "abc") assert_false(outcome)
def test_delete_module_with_mounting(self): ''' Tests deleting of modules with tentative mounting. ''' outcome = model.delete_module(self.test_module_code) assert_false(outcome) module_info = model.get_module(self.test_module_code) assert_true(module_info is not None) return
def POST(self, *test_data): ''' Handles the submission of the 'Edit General Module Info' page ''' if test_data: # for testing purposes input_data = test_data[0] else: input_data = model.validate_input(web.input(), ["code"], show_404=False) module_code = None try: module_code = input_data.code module_name = input_data.name module_desc = input_data.desc module_mc = input_data.mc #validate inputs if not model.check_name(module_name): return model.outcome_invalid() except AttributeError: return Outcome().POST("edit_module", False, module_code) # Validate that MC is a number and is between 0 and 12 if not model.check_mcs(module_mc): return Outcome().POST("edit_module", False, module_code) old_module_info = model.get_module(module_code) old_module_name = old_module_info[1] old_module_desc = old_module_info[2] old_module_mc = old_module_info[3] outcome = True module_info = model.get_module(module_code) if module_info is None: outcome = False elif (module_name != old_module_name or module_desc != old_module_desc or int(module_mc) != int(old_module_mc)): model.store_original_module_info(module_code, old_module_name, old_module_desc, old_module_mc) outcome = model.update_module(module_code, module_name, module_desc, module_mc) if not test_data: return Outcome().POST("edit_module", outcome, module_code)
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 test_all_mod_in_fixed_mounting_are_active(self): ''' Tests if all modules in fixed mounting have their statuses updated to "Active" ''' current_fixed_data = model.get_all_fixed_mounted_modules() for data in current_fixed_data: module_code = data[0] module_status = model.get_module(module_code)[4] assert_equal(module_status.strip(), "Active")
def test_module_CRD(self): ''' Tests creating, reading and deleting of modules. ''' if not self.module_CRD_tested: model.add_module(self.test_module_code, self.test_module_name, self.test_module_desc, self.test_module_mc, self.test_module_status) module_info = model.get_module(self.test_module_code) assert_true(module_info is not None) assert_equal(self.test_module_code, module_info[0]) assert_equal(self.test_module_name, module_info[1]) assert_equal(self.test_module_desc, module_info[2]) assert_equal(self.test_module_mc, module_info[3]) assert_equal(self.test_module_status, module_info[4].rstrip()) model.delete_module(self.test_module_code) module_info = model.get_module(self.test_module_code) assert_true(module_info is None) return
def GET(self): ''' Handles the loading of the 'Edit General Module Info' page ''' input_data = model.validate_input(web.input(), ["code"]) module_code = input_data.code module_info = model.get_module(module_code) if module_info is None: return RENDER.notfound("Module " + module_code + " does not exist in the system.") preclusions = model.get_preclusion_as_string(module_code) prerequisites = model.get_prerequisite_as_string(module_code) return RENDER.moduleEdit(module_info, preclusions, prerequisites)
def GET(self): ''' Retrieve and render all the info of a module mounting ''' if not session.validate_session(): raise web.seeother('/login') input_data = model.validate_input(web.input(), ["code", "aysem"]) module_code = input_data.code ay_sem = input_data.aysem # Get module's name, description, MC and status module_info = model.get_module(module_code) # Get mounting status, quota and number of students taking self.load_mounting_info(module_code, ay_sem) student_count = model.get_number_of_students_taking_module_in_ay_sem( module_code, ay_sem) # Check if the selected AY-Sem is in the current AY # (To determine whether to display the 'Edit Specific Info' button) is_future_ay = not self.is_current_ay # Check if module is starred is_starred = model.is_module_starred(module_code, web.cookies().get('user')) # Get the year of study and focus area distriubtions of students taking the module # (To be rendered as charts) self.load_focus_areas() self.load_student_enrollments(module_code, ay_sem) all_ay_sems = model.get_all_ay_sems() all_future_ay_sems = model.get_all_future_ay_sems() return RENDER.individualModuleInfo( module_info, all_ay_sems, all_future_ay_sems, is_future_ay, ay_sem, self.mounting_status, self.quota, student_count, is_starred, self.focus_areas, self.focus_area_acronyms, self.student_year_counts, self.focus_area_counts)
def GET(self): ''' Retrieve and render all the info of a module ''' if not session.validate_session(): raise web.seeother('/login') input_data = model.validate_input(web.input(), ["code"]) module_code = input_data.code # Get module's name, description, MC and status module_info = model.get_module(module_code) # Get mounting status, quota and number of students taking self.load_fixed_mounting_plan(module_code) self.load_tenta_mounting_plan(module_code) number_of_student_planning = model.get_number_students_planning( module_code) # Get module's prereqs and preclusions prereq_string = model.get_prerequisite_as_string(module_code) preclude_string = model.get_preclusion_as_string(module_code) # Check if module is starred is_starred = model.is_module_starred(module_code, web.cookies().get('user')) all_ay_sems = model.get_all_ay_sems() all_future_ay_sems = model.get_all_future_ay_sems() target_ay_sem = None #get html of overlapping modules template return RENDER.viewModule(module_info, all_ay_sems, all_future_ay_sems, target_ay_sem, self.fixed_mounting_plan, self.tenta_mounting_plan, number_of_student_planning, is_starred, prereq_string, preclude_string)
def test_details_restore(self): ''' Test if a module's whose details are modified can be restored and if the module will disappear from the table of modules with modified details ''' # Name is modified and will be restored test_module_code = 'BB3005' test_module_name = 'Dummy Module 5' test_module_orig_name = 'Original Module Name' module_info = model.get_module(test_module_code) module_name = module_info[1] assert_equal(module_name, test_module_name) modified_modules = self.modified_modules_handler.get_modules_with_modified_details() is_in_modified_modules = False is_name_modified = None is_desc_modified = None is_mc_modified = None for module in modified_modules: code = module[0][0] if code == test_module_code: is_in_modified_modules = True is_name_modified = module[1][0] is_desc_modified = module[1][1] is_mc_modified = module[1][2] break assert_true(is_in_modified_modules) assert_true(is_name_modified) assert_false(is_desc_modified) assert_false(is_mc_modified) test_post_data = self.TestRestoreModuleData("moduleDetails", test_module_code, None, None, None, None) self.module_restore_handler.POST(test_post_data) modified_modules = self.modified_modules_handler.get_modules_with_modified_details() is_in_modified_modules = False for module in modified_modules: code = module[0][0] if code == test_module_code: is_in_modified_modules = True break assert_false(is_in_modified_modules) module_info = model.get_module(test_module_code) module_name = module_info[1] assert_equal(module_name, test_module_orig_name) # Name, description and MC are modified and will be restored test_module_code = 'BB3006' test_module_name = 'Dummy Module 6' test_module_desc = "This module's name, description and MC will be restored" test_module_mc = 6 test_module_orig_name = 'Original Module Name' test_module_orig_desc = 'Original Module Description' test_module_orig_mc = 0 module_info = model.get_module(test_module_code) module_name = module_info[1] module_desc = module_info[2] module_mc = module_info[3] assert_equal(module_name, test_module_name) assert_equal(module_desc, test_module_desc) assert_equal(module_mc, test_module_mc) modified_modules = self.modified_modules_handler.get_modules_with_modified_details() is_in_modified_modules = False is_name_modified = None is_desc_modified = None is_mc_modified = None for module in modified_modules: code = module[0][0] if code == test_module_code: is_in_modified_modules = True is_name_modified = module[1][0] is_desc_modified = module[1][1] is_mc_modified = module[1][2] break assert_true(is_in_modified_modules) assert_true(is_name_modified) assert_true(is_desc_modified) assert_true(is_mc_modified) test_post_data = self.TestRestoreModuleData("moduleDetails", test_module_code, None, None, None, None) self.module_restore_handler.POST(test_post_data) modified_modules = self.modified_modules_handler.get_modules_with_modified_details() is_in_modified_modules = False for module in modified_modules: code = module[0] if code == test_module_code: is_in_modified_modules = True break assert_false(is_in_modified_modules) module_info = model.get_module(test_module_code) module_name = module_info[1] module_desc = module_info[2] module_mc = module_info[3] assert_equal(module_name, test_module_orig_name) assert_equal(module_desc, test_module_orig_desc) assert_equal(module_mc, test_module_orig_mc)