Beispiel #1
0
    def test_update_quota(self):
        '''
            Tests updating of module's quota for a target tentative AY/Sem
        '''
        model.update_quota(self.test_module_code,
                           self.test_module_tenta_mounting_s1, 999)

        mounting_data = model.get_tenta_mounting_and_quota(
            self.test_module_code)
        assert_equal(1, len(mounting_data))

        mounting_s1 = mounting_data[0][0]
        quota_s1 = mounting_data[0][1]

        assert_equal(mounting_s1, self.test_module_tenta_mounting_s1)
        assert_equal(quota_s1, 999)
    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)
Beispiel #3
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)
Beispiel #4
0
    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_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)
Beispiel #7
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)