def test_edit_preclude_already_in_prereq(self):
        '''
            Tests editing preclusion on a module to precludes which already
            exists as a prerequisite to that module.
            Note: this test case should fail to edit.
        '''
        if not self.edit_preclude_non_existent_tested:
            model.add_prerequisite(self.test_module_code,
                                   self.test_preclude_code, 0)

            preclude_units_to_change_to = [self.test_preclude_code]

            outcome = model.edit_preclusion(self.test_module_code,
                                            preclude_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_preclude_code,
                self.ERROR_MSG_MODULE_PRECLUSION_ALREADY_PREREQ
            ])

            preclude_info = model.get_preclusion(self.test_module_code)

            assert_true(preclude_info is not None)
            assert_true(len(preclude_info) == 0)

            model.delete_all_prerequisites(self.test_module_code)
            prereq_info = model.get_prerequisite(self.test_module_code)
            assert_true(len(prereq_info) == 0)
    def test_edit_preclude_duplicate_modules(self):
        '''
            Tests editing preclusion on a module to precludes with duplicates,
            note: this test case should fail to edit.
        '''
        if not self.edit_preclude_duplicate_tested:
            model.add_preclusion(self.test_module_code,
                                 self.test_preclude_code)

            preclude_units_to_change_to = [
                self.test_preclude2_code, self.test_preclude2_code
            ]

            outcome = model.edit_preclusion(self.test_module_code,
                                            preclude_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_preclude2_code, self.ERROR_MSG_MODULE_DUPLICATED])

            preclude_info = model.get_preclusion(self.test_module_code)

            assert_true(preclude_info is not None)
            assert_equal(self.test_preclude_code, preclude_info[0][0])

            model.delete_all_preclusions(self.test_module_code)

            preclude_info = model.get_preclusion(self.test_module_code)
            assert_true(len(preclude_info) == 0)
    def test_preclude_to_multiple_preclude(self):
        '''
            Tests editing preclusion on a module to multiple preclude.
        '''
        if not self.preclude_to_multiple_preclude_tested:
            model.add_preclusion(self.test_module_code,
                                 self.test_preclude_code)

            preclude_units_to_change_to = [
                self.test_preclude_code, self.test_preclude2_code,
                self.test_preclude3_code
            ]

            outcome = model.edit_preclusion(self.test_module_code,
                                            preclude_units_to_change_to)
            assert_true(outcome[0])

            preclude_info = model.get_preclusion(self.test_module_code)

            assert_true(preclude_info is not None)
            assert_equal(len(preclude_info), 3)
            assert_equal(self.test_preclude_code, preclude_info[0][0])
            assert_equal(self.test_preclude2_code, preclude_info[1][0])
            assert_equal(self.test_preclude3_code, preclude_info[2][0])

            model.delete_all_preclusions(self.test_module_code)

            preclude_info = model.get_preclusion(self.test_module_code)
            assert_true(len(preclude_info) == 0)
            return
    def test_no_preclude_to_no_preclude(self):
        '''
            Tests editing preclusion on a module originally with no preclude
            to no preclude.
        '''
        if not self.no_preclude_to_no_preclude_tested:
            preclude_units_to_change_to = []
            outcome = model.edit_preclusion(self.test_module_code,
                                            preclude_units_to_change_to)

            assert_true(outcome[0])

            preclude_info = model.get_preclusion(self.test_module_code)

            assert_true(preclude_info is not None)
            assert_true(len(preclude_info) == 0)
            return
    def POST(self):
        '''
            Handles the submission of updated module preclusions
            for a target module.
        '''
        isSucessfullyUpdated = False

        input_data = model.validate_input(web.input(), ["code"], show_404=False)

        if input_data:
            module_code = input_data.code.upper()
            preclusions = json.loads(input_data.preclusions)
            isSucessfullyUpdated = model.edit_preclusion(module_code, preclusions)

        new_preclusions = model.get_preclusion_as_string(module_code)
        response = [isSucessfullyUpdated, new_preclusions]

        return json.dumps(response)
    def test_edit_preclude_multiple_errors(self):
        '''
            Tests editing preclusion on a module to precludes with multiple
            errors.
            Note: this test case should fail to edit.
        '''
        if not self.edit_preclude_multiple_errors_tested:
            model.add_preclusion(self.test_module_code,
                                 self.test_preclude_code)

            preclude_units_to_change_to = [
                self.test_module_code, self.test_invalid_module_code
            ]

            outcome = model.edit_preclusion(self.test_module_code,
                                            preclude_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
            ])

            preclude_info = model.get_preclusion(self.test_module_code)

            assert_true(preclude_info is not None)
            assert_equal(self.test_preclude_code, preclude_info[0][0])

            model.delete_all_preclusions(self.test_module_code)

            preclude_info = model.get_preclusion(self.test_module_code)
            assert_true(len(preclude_info) == 0)
    def test_edit_preclude_non_existent_modules(self):
        '''
            Tests editing preclusion on a module to precludes which does
            not exist, note: this test case should fail to edit.
        '''
        if not self.edit_preclude_non_existent_tested:
            model.add_preclusion(self.test_module_code,
                                 self.test_preclude_code)

            preclude_units_to_change_to = [
                self.test_preclude2_code, self.test_invalid_module_code
            ]

            outcome = model.edit_preclusion(self.test_module_code,
                                            preclude_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
            ])

            preclude_info = model.get_preclusion(self.test_module_code)

            assert_true(preclude_info is not None)
            assert_equal(self.test_preclude_code, preclude_info[0][0])

            model.delete_all_preclusions(self.test_module_code)

            preclude_info = model.get_preclusion(self.test_module_code)
            assert_true(len(preclude_info) == 0)

            # Test another form

            model.add_preclusion(self.test_module_code,
                                 self.test_preclude_code)

            preclude_units_to_change_to = [
                self.test_invalid_module_code, self.test_preclude2_code
            ]

            outcome = model.edit_preclusion(self.test_module_code,
                                            preclude_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
            ])

            preclude_info = model.get_preclusion(self.test_module_code)

            assert_true(preclude_info is not None)
            assert_equal(self.test_preclude_code, preclude_info[0][0])

            model.delete_all_preclusions(self.test_module_code)

            preclude_info = model.get_preclusion(self.test_module_code)
            assert_true(len(preclude_info) == 0)
            return