コード例 #1
0
ファイル: test_parser.py プロジェクト: openedx/olxcleaner
def test_course7_url():
    errorstore = ErrorStore()

    # Load course
    course = load_course("testcourses/testcourse7", "course.xml", errorstore)
    assert_caught_all_errors(errorstore)

    # Load policy
    policy, grading_policy = load_policy("testcourses/testcourse7", course,
                                         errorstore)
    assert_caught_all_errors(errorstore)

    # Make a dictionary of url_names
    url_names = find_url_names(course, errorstore)

    # Merge the policy file
    merge_policy(policy, url_names, errorstore)
    # Ensure that settings were indeed merged
    assert (url_names['sequential2'].attributes['setting'])

    # Validate the grading policy
    validate_grading_policy(grading_policy, errorstore)

    # Handle the errors
    handle_course7_errors(errorstore)
    assert_caught_all_errors(errorstore)
コード例 #2
0
def test_no_policy():
    errorstore = ErrorStore()
    # Load course (needed before loading policy)
    course = load_course("testcourses/testcourse1", "course.xml", errorstore)
    assert_caught_all_errors(errorstore)
    # Load the (nonexistent) policy files
    policy, grading_policy = load_policy("testcourses/testcourse1", course,
                                         errorstore)
    handle_course1_errors(errorstore)
    assert_caught_all_errors(errorstore)
コード例 #3
0
def test_no_url_name():
    errorstore = ErrorStore()
    # Load course (needed before loading policy)
    course = load_course("testcourses/testcourse4", "course.xml", errorstore)
    assert_caught_all_errors(errorstore)
    # Load the (nonexistent) policy files
    policy, grading_policy = load_policy("testcourses/testcourse4", course,
                                         errorstore)
    assert_error(errorstore, NoRunName, 'course.xml',
                 "The course tag has no url_name.")
    assert_caught_all_errors(errorstore)
コード例 #4
0
ファイル: test_parser.py プロジェクト: openedx/olxcleaner
def test_url_names():
    errorstore = ErrorStore()

    # Load course
    course = load_course("testcourses/testcourse1", "course.xml", errorstore)
    assert_caught_all_errors(errorstore)

    # Make a dictionary of url_names
    url_names = find_url_names(course, errorstore)
    assert_caught_all_errors(errorstore)

    expected = ['mycourseurl', 'chapter', 'sequential', 'vertical', 'html']
    for i in expected:
        assert i in url_names
コード例 #5
0
def test_bad_json():
    errorstore = ErrorStore()
    # Load course (needed before loading policy)
    course = load_course("testcourses/testcourse5", "course.xml", errorstore)
    assert_caught_all_errors(errorstore)
    # Load the policy files
    policy, grading_policy = load_policy("testcourses/testcourse5", course,
                                         errorstore)
    assert_error(
        errorstore, BadPolicy, 'policies/mycourseurl/policy.json',
        "The policy file 'policies/mycourseurl/policy.json' has invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"
    )
    assert_error(
        errorstore, BadPolicy, 'policies/mycourseurl/grading_policy.json',
        "The policy file 'policies/mycourseurl/grading_policy.json' has invalid JSON: Expecting property name enclosed in double quotes: line 2 column 3 (char 4)"
    )
    assert_caught_all_errors(errorstore)
コード例 #6
0
ファイル: test_parser.py プロジェクト: openedx/olxcleaner
def test_course6_url():
    errorstore = ErrorStore()

    # Load course
    course = load_course("testcourses/testcourse6", "course.xml", errorstore)
    assert_caught_all_errors(errorstore)

    # Load policy
    policy, grading_policy = load_policy("testcourses/testcourse6", course,
                                         errorstore)
    assert_caught_all_errors(errorstore)

    # Make a dictionary of url_names
    url_names = find_url_names(course, errorstore)

    # Merge the policy file
    merge_policy(policy, url_names, errorstore)

    # Handle the errors
    handle_course6_errors(errorstore)
    assert_caught_all_errors(errorstore)
コード例 #7
0
def validate(filename, steps=8, ignore=None):
    """
    Validate an OLX course by performing the given number of steps:

      * 1: Load the course
      * 2: Load the policy and grading policy
      * 3: Validate url_names
      * 4: Merge policy data with course, ensuring that all references are valid
      * 5: Validate the grading policy
      * 6: Have every object validate itself
      * 7: Parse the course for global errors
      * 8: Parse the course for global errors that may be time-consuming to detect

    :param filename: Location of course xml file or directory
    :param steps: Number of validation steps to take (1 = first only, 8 = all)
    :param ignore: List of errors to ignore
    :return: course object, errorstore object, url_names dictionary (or None if steps < 3)
    """
    # Create an error store
    if ignore is None:
        ignore = []
    errorstore = ErrorStore(ignore)

    # Validation Step #1: Load the course
    if os.path.isdir(filename):
        directory = os.path.join(filename)
        file = "course.xml"
    else:
        directory, file = os.path.split(filename)
    course = load_course(directory, file, errorstore)
    if not course:
        return None, errorstore, None

    if steps > 1:
        # Validation Step #2: Load the policy files
        policy, grading_policy = load_policy(directory, course, errorstore)

    url_names = None
    if steps > 2:
        # Validation Step #3: Construct a dictionary of url_names
        url_names = find_url_names(course, errorstore)

    if steps > 3:
        # Validation Step #4: Merge policy data into object attributes
        merge_policy(policy, url_names, errorstore)

    if steps > 4:
        # Validation Step #5: Validate grading policy
        validate_grading_policy(grading_policy, errorstore)

    if steps > 5:
        # Validation Step #6: Have every object validate itself
        for edxobj in traverse(course):
            edxobj.validate(course, errorstore)

    if steps > 6:
        # Validation Step #7: Parse the course for global errors
        for validator in GlobalValidator.validators():
            validator(course, errorstore, url_names)

    if steps > 7:
        # Validation Step #8: Parse the course for global errors that are time-consuming to detect
        for validator in SlowValidator.validators():
            validator(course, errorstore, url_names)

    return course, errorstore, url_names