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_quota(self):
        '''
            Test that Edit All function can edit a single module's quota
        '''
        test_module_code = self.DUMMY_MODULE_CODE_1
        test_mounting = True
        test_quota = 100

        # Modifiy Sem 1 quota
        test_data = {}
        test_data[test_module_code+'_isEdited'] = "True"
        test_data[test_module_code+'_Sem1Mounting'] = test_mounting
        test_data[test_module_code+'_Sem1Quota'] = 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 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.update_quota(test_module_code, self.next_ay+" Sem 1", self.DUMMY_QUOTA_1)

        # Modify Sem 2 quota
        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'] = test_mounting
        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.update_quota(test_module_code, self.next_ay+" Sem 2", self.DUMMY_QUOTA_2)
    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")
示例#4
0
    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 load_mounting_info(self, module_code, ay_sem):
        '''
            Load the mounting status and quota of the target module and AY/Sem
        '''
        fixed_mounting_status = -1
        fixed_quota = None
        is_current_ay = False

        # Get mounting status and quota in current AY
        target_ay = ay_sem[0:8]
        current_ay = model.get_current_ay()
        if target_ay == current_ay:
            is_current_ay = True
            fixed_mounting_status = model.get_mounting_of_target_fixed_ay_sem(
                module_code, ay_sem)
            fixed_quota = model.get_quota_of_target_fixed_ay_sem(
                module_code, ay_sem)
        else:
            target_sem = ay_sem[9:14]
            fixed_mounting_status = model.get_mounting_of_target_fixed_ay_sem(
                module_code, current_ay + " " + target_sem)
            fixed_quota = model.get_quota_of_target_fixed_ay_sem(
                module_code, current_ay + " " + target_sem)

        if fixed_quota is False:
            fixed_quota = '-'

        if is_current_ay:
            if fixed_mounting_status is True:
                self.mounting_status = 1
            else:
                self.mounting_status = -1
            self.quota = fixed_quota

        else:
            # Get mounting status and quota in target (future) AY
            tenta_mounting_status = model.get_mounting_of_target_tenta_ay_sem(
                module_code, ay_sem)
            tenta_quota = model.get_quota_of_target_tenta_ay_sem(
                module_code, ay_sem)

            if tenta_quota is False:
                tenta_quota = '-'
            self.quota = tenta_quota

            if tenta_mounting_status is True:
                self.mounting_status = 1
            else:
                if fixed_mounting_status is True:
                    self.mounting_status = 0
                else:
                    self.mounting_status = -1

        self.is_current_ay = is_current_ay
    def test_edit_multiple_modules_quotas(self):
        '''
            Test that Edit All function can edit multiple modules' quota(s)
        '''
        test_data = {}

        # Modify Dummy Module 1's quota
        test_mod_1_code = self.DUMMY_MODULE_CODE_1
        test_mod_1_mounting = True
        test_mod_1_quota = 100
        test_data[test_mod_1_code+'_isEdited'] = "True"
        test_data[test_mod_1_code+'_Sem1Mounting'] = test_mod_1_mounting
        test_data[test_mod_1_code+'_Sem1Quota'] = test_mod_1_quota

        # Modify Dummy Module 2's quota
        test_mod_2_code = self.DUMMY_MODULE_CODE_2
        test_mod_2_mounting = True
        test_mod_2_quota = 200
        test_data[test_mod_2_code+'_isEdited'] = "True"
        test_data[test_mod_2_code+'_Sem2Mounting'] = test_mod_2_mounting
        test_data[test_mod_2_code+'_Sem2Quota'] = test_mod_2_quota

        self.edit_all_handler.POST(test_data)

        mounting = model.get_mounting_of_target_tenta_ay_sem(test_mod_1_code,
                                                             self.next_ay+" Sem 1")
        quota = model.get_quota_of_target_tenta_ay_sem(test_mod_1_code,
                                                       self.next_ay+" Sem 1")
        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 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)
        assert_equal(quota, test_mod_2_quota)

        model.update_quota(test_mod_1_code, self.next_ay+" Sem 1", self.DUMMY_QUOTA_1)
        model.update_quota(test_mod_2_code, self.next_ay+" Sem 2", self.DUMMY_QUOTA_2)
    def test_edit_single_module_multiple_quotas(self):
        '''
            Test that Edit All function can edit a single module's multiple quotas
        '''
        test_module_code = self.DUMMY_MODULE_CODE_3
        test_mounting_1 = True
        test_mounting_2 = True
        test_quota_1 = None
        test_quota_2 = 300

        # Modify Sem 1 and 2 quotas
        test_data = {}
        test_data[test_module_code+'_isEdited'] = "True"
        test_data[test_module_code+'_Sem1Mounting'] = test_mounting_1
        # Because quota is empty, no quota value will be returned by the UI
        test_data[test_module_code+'_Sem2Mounting'] = test_mounting_2
        test_data[test_module_code+'_Sem2Quota'] = test_quota_2    #modified

        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_1)
        assert_equal(quota, test_quota_1)

        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_2)
        assert_equal(quota, test_quota_2)

        model.update_quota(test_module_code, self.next_ay+" Sem 1", self.DUMMY_QUOTA_3)
        model.update_quota(test_module_code, self.next_ay+" Sem 2", self.DUMMY_QUOTA_0)
示例#8
0
    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 test_mounting_restore(self):
        '''
            Test if a module's whose mounting is modified can be restored
            and if the module will disappear from the table of modules with modified mounting
        '''
        # Restore to unmounted
        test_module_code = 'BB3003'
        test_target_aysem = self.next_ay+" Sem 2"

        modified_modules = self.modified_modules_handler.get_modules_with_modified_mounting()
        is_in_modified_modules = False
        mounting_change = None

        for module in modified_modules:
            code = module[0]
            if code == test_module_code:
                is_in_modified_modules = True
                mounting_change = module[4]
                break

        assert_true(is_in_modified_modules)
        assert_equal(mounting_change, 1)  # Mounted

        test_post_data = self.TestRestoreModuleData("mounting", test_module_code, None,
                                                    test_target_aysem, None, mounting_change)
        self.module_restore_handler.POST(test_post_data)

        modified_modules = self.modified_modules_handler.get_modules_with_modified_mounting()
        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)

        restored_mounting = model.get_mounting_of_target_tenta_ay_sem(test_module_code,
                                                                      test_target_aysem)
        assert_equal(restored_mounting, False)  # Not Mounted

        # Restore to mounted
        test_module_code = 'BB3004'
        test_current_aysem = self.current_ay+" Sem 2"
        test_target_aysem = self.next_ay+" Sem 2"

        modified_modules = self.modified_modules_handler.get_modules_with_modified_mounting()
        is_in_modified_modules = False
        mounting_change = None

        for module in modified_modules:
            code = module[0]
            if code == test_module_code:
                is_in_modified_modules = True
                mounting_change = module[4]
                break

        assert_true(is_in_modified_modules)
        assert_equal(mounting_change, 0)  # Not Mounted

        test_post_data = self.TestRestoreModuleData("mounting", test_module_code,
                                                    test_current_aysem, test_target_aysem,
                                                    None, mounting_change)
        self.module_restore_handler.POST(test_post_data)

        modified_modules = self.modified_modules_handler.get_modules_with_modified_mounting()
        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)

        restored_mounting = model.get_mounting_of_target_tenta_ay_sem(test_module_code,
                                                                      test_target_aysem)
        assert_equal(restored_mounting, True)  # Mounted