def test_create_user_with_invalid_or_missing_field_raises_error(self): user_payload_with_missing_field = { 'first_name': 'Maliha', 'last_name': 'Islam', 'email': '*****@*****.**' } response = self.client.post( f'{TEST_USER_URL_PATH}/', data=json.dumps(user_payload_with_missing_field), content_type='application/json') self.assertEqual(response.status_code, 400) assert_error( response.data, 'Bad Request: One or more required fields are missing or invalid: first_name, last_name, email, password' ) user_payload_with_invalid_field = { 'first_name': 'Maliha', 'last_name': 'Islam', 'email': '*****@*****.**', 'password': '******', 'INVALID': 'invalid' } response = self.client.post( f'{TEST_USER_URL_PATH}/', data=json.dumps(user_payload_with_invalid_field), content_type='application/json') self.assertEqual(response.status_code, 400) assert_error( response.data, 'Bad Request: One or more required fields are missing or invalid: first_name, last_name, email, password' )
def test_course3(): """Test for XML error in course.xml""" errorstore = ErrorStore() course = load_course("testcourses/testcourse3", "course.xml", errorstore) assert_error(errorstore, InvalidXML, 'course.xml', 'attributes construct error, line 1, column 61') assert_caught_all_errors(errorstore)
def test_delete_user_without_token_raises_error(self): user = self.register_user() user_id = json.loads(user.get_data())['id'] response = self.client.delete(f'{TEST_USER_URL_PATH}/{user_id}', ) self.assertEqual(response.status_code, 401) assert_error(response.data, 'Unauthorized: Token is missing!')
def handle_general_errors_in_10(errorstore): assert_error( errorstore, TagMismatch, 'chapter/broken_chapter.xml', "The file is of type <chapter> but opens with a <sequential> tag") assert_error( errorstore, Obsolete, 'vertical/dndvert.xml', "The tag <lti url_name='lti2' display_name='something'> should be converted to the newer lti_consumer Xblock." )
def test_validate_course8(): """This test includes individual component validation. Almost everything should pass.""" course, errorstore, url_names = validate("testcourses/testcourse8", 6) assert_error( errorstore, InvalidSetting, 'course/mycourseurl.xml', "The tag <course url_name='mycourseurl'> does not have the required setting 'course_image'." ) assert_caught_all_errors(errorstore)
def handle_course1_errors(errorstore): assert_error( errorstore, PolicyNotFound, 'policies/mycourseurl/policy.json', "The policy file 'policies/mycourseurl/policy.json' was not found.") assert_error( errorstore, PolicyNotFound, 'policies/mycourseurl/grading_policy.json', "The policy file 'policies/mycourseurl/grading_policy.json' was not found." )
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)
def test_signup_username_already_used(client): username = "******" password = "******" signup_user(client=client, username=username, email="*****@*****.**", password=password) response = signup_user(client=client, username=username, email="*****@*****.**", password=password) assert_error(response, 422) data = json.loads(response.data) assert data["errorCode"] == "INVALID_FIELD" assert "Username is already used" in data["errorMessage"]
def test_login_bad_credentials(client): username = "******" email = "*****@*****.**" password = "******" signup_user(client=client, username=username, email=email, password=password) response = login_user(client=client, username=username, password="******") assert_error(response, 401) data = json.loads(response.data) assert data["errorCode"] == "INVALID_CREDENTIALS" assert not "token" in data
def test_update_user_with_invalid_field_raises_error(self): user = self.register_user() user_id = json.loads(user.get_data())['id'] logged_in_user = self.login_user() token = json.loads(logged_in_user.get_data())['token'] updated_user = {'INVALID': 'invalid'} response = self.client.put(f'{TEST_USER_URL_PATH}/{user_id}', data=json.dumps(updated_user), content_type='application/json', headers={'x-access-token': token}) self.assertEqual(response.status_code, 400) assert_error( response.data, 'Bad Request: Field "INVALID" is not allowed. Allowed fields are: first_name, last_name, password' )
def test_update_user_with_unauthorized_user_login_raises_error(self): self.register_user() logged_in_user = self.login_user() token = json.loads(logged_in_user.get_data())['token'] user2 = self.register_user('*****@*****.**') user2_id = json.loads(user2.get_data())['id'] updated_user = {'first_name': 'Maliha'} response = self.client.put(f'{TEST_USER_URL_PATH}/{user2_id}', data=json.dumps(updated_user), content_type='application/json', headers={'x-access-token': token}) self.assertEqual(response.status_code, 401) assert_error(response.data, 'Unauthorized: You can only modify your own account.')
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)
def handle_display_name_errors_in_10(errorstore): assert_error( errorstore, MissingDisplayName, 'course/mycourseurl.xml', "The tag <course url_name='mycourseurl'> is missing the display_name attribute." ) assert_error( errorstore, MissingDisplayName, 'course/mycourseurl.xml', "The tag <html url_name='html'> is missing the display_name attribute." ) assert_error( errorstore, ExtraDisplayName, 'vertical/oravert.xml', "The tag <openassessment url_name='paper-draft' display_name='Hah!'> has an erroneous display_name attribute." )
def handle_discussion_id_errors_in_10(errorstore): assert_error( errorstore, DuplicateID, 'course/mycourseurl.xml', "The <discussion display_name='Here's a discussion'> tag and the <discussion display_name='Here's a discussion'> tag both use the same discussion id: Me" )
def handle_link_errors_in_10(errorstore): assert_error( errorstore, BadJumpToLink, 'html/linktest.xml', "The <html url_name='linktest' display_name='Testing links'> tag contains a link to a url_name that doesn't exist: /jump_to_id/oravert2" ) assert_error( errorstore, MissingFile, 'html/linktest.xml', "The <html url_name='linktest' display_name='Testing links'> tag contains a reference to a missing static file: /static/testing2.css" ) assert_error( errorstore, MissingFile, 'html/linktest.xml', "The <html url_name='linktest' display_name='Testing links'> tag contains a reference to a missing static file: /static/testing.png" ) assert_error( errorstore, BadCourseLink, 'html/linktest.xml', "The <html url_name='linktest' display_name='Testing links'> tag contains a link to a location that doesn't exist: /course/courseware/testing" ) assert_error( errorstore, BadCourseLink, 'html/linktest.xml', "The <html url_name='linktest' display_name='Testing links'> tag contains a link to a location that doesn't exist: /course/courseware/chapter/sequential/vertical/10" ) assert_error( errorstore, BadCourseLink, 'html/linktest.xml', "The <html url_name='linktest' display_name='Testing links'> tag contains a link to a location that doesn't exist: /course/courseware/chapter/sequential/vertical/0" ) assert_error( errorstore, BadCourseLink, 'html/linktest.xml', "The <html url_name='linktest' display_name='Testing links'> tag contains a link to a location that doesn't exist: /course/courseware/chapter/sequential/vertical/html" ) assert_error( errorstore, MissingFile, 'vertical/dndvert.xml', "The <problem url_name='dndtest' display_name='Mwa'> tag contains a reference to a missing static file: /static/ex34_dnd_sol.png" ) assert_error( errorstore, MissingFile, 'vertical/dndvert.xml', "The <problem url_name='dndtest' display_name='Mwa'> tag contains a reference to a missing static file: /static/ex34_dnd.png" ) assert_error( errorstore, MissingFile, 'vertical/dndvert.xml', "The <problem url_name='dndtest' display_name='Mwa'> tag contains a reference to a missing static file: /static/ex34_dnd_label1.png" ) assert_error( errorstore, MissingFile, 'vertical/dnd2vert.xml', "The <drag-and-drop-v2 url_name='studio_mess' display_name='This is my title'> tag contains a reference to a missing static file: /static/ex34_dnd.png" ) assert_error( errorstore, MissingFile, 'vertical/dnd2vert.xml', "The <drag-and-drop-v2 url_name='studio_mess' display_name='This is my title'> tag contains a reference to a missing static file: /static/ex34_dnd_label1.png" )
def test_validate_course9(): """This test includes individual component validation. This similar to course8, but riddled with errors.""" course, errorstore, url_names = validate("testcourses/testcourse9", 6) assert_error(errorstore, InvalidSetting, 'course/mycourseurl.xml', "Unable to recognize graceperiod format in policy.") assert_error( errorstore, InvalidSetting, 'problem/problem.xml', "The tag <problem url_name='problem'> has an invalid setting 'showanswer=bad'." ) assert_error( errorstore, InvalidSetting, 'chapter/chapter.xml', "The tag <chapter url_name='chapter' display_name='Hi there!'> has an invalid date setting for start: 'Feb 20, 2019, 17:00zzz'." ) assert_error( errorstore, DateOrdering, 'sequential/sequential.xml', "The tag <sequential url_name='sequential' display_name='Hi there!'> has a date out of order: start date cannot be before course start date" ) assert_error( errorstore, DateOrdering, 'vertical/vertical.xml', "The tag <vertical url_name='vertical' display_name='Hi mom!'> has a date out of order: due date must be before course end date" ) assert_error( errorstore, DateOrdering, 'problem/problem.xml', "The tag <problem url_name='problem'> has a date out of order: start date must be before due date" ) assert_error( errorstore, MissingURLName, 'vertical/vertical.xml', "The tag <problem display_name='no url_name'> has no url_name.") assert_error( errorstore, InvalidSetting, 'vertical/vertical.xml', "The tag <problem display_name='no url_name'> has an invalid setting 'showanswer=hah!'." ) assert_error( errorstore, DateOrdering, 'vertical/vertical.xml', "The tag <problem display_name='no url_name'> has a date out of order: due date must be before course end date" ) assert_error( errorstore, Obsolete, 'vertical/vertical.xml', "The tag <discussion url_name='discussion'> should be included inline rather than through the discussion directory." ) assert_error( errorstore, InvalidSetting, 'discussion/discussion.xml', "The tag <discussion url_name='discussion'> does not have the required setting 'discussion_id'." ) assert_error( errorstore, InvalidSetting, 'discussion/discussion.xml', "The tag <discussion url_name='discussion'> does not have the required setting 'discussion_category'." ) assert_error( errorstore, InvalidSetting, 'discussion/discussion.xml', "The tag <discussion url_name='discussion'> does not have the required setting 'discussion_target'." ) assert_error( errorstore, Obsolete, 'lti/lti.xml', "The tag <lti url_name='lti'> should be converted to the newer lti_consumer Xblock." ) assert_error( errorstore, InvalidSetting, 'lti/lti.xml', "The tag <lti url_name='lti'> does not have the required setting 'launch_url'." ) assert_error( errorstore, LTIError, 'lti/lti.xml', "Course policy does not include an 'lti_passports' entry for 'nothere', required for <lti url_name='lti'>." ) assert_error( errorstore, LTIError, 'lti/lti.xml', "Course policy does not include the 'lti' advanced module, required for <lti url_name='lti'>." ) assert_error( errorstore, InvalidSetting, 'vertical/vertical.xml', "The tag <lti_consumer url_name='meep'> does not have the required setting 'launch_url'." ) assert_error( errorstore, LTIError, 'vertical/vertical.xml', "Course policy does not include an 'lti_passports' entry for 'nothere', required for <lti_consumer url_name='meep'>." ) assert_error( errorstore, LTIError, 'vertical/vertical.xml', "Course policy does not include the 'lti_consumer' advanced module, required for <lti_consumer url_name='meep'>." ) assert_error( errorstore, MissingFile, 'course/mycourseurl.xml', "The <course url_name='mycourseurl'> tag contains a reference to a missing static file: course_image_small.jpg" ) assert_error( errorstore, InvalidSetting, 'problem/problem.xml', "The tag <problem url_name='problem'> has a negative problem weight.") assert_error( errorstore, InvalidSetting, 'course/mycourseurl.xml', "The tag <course url_name='mycourseurl'> should have a positive number of attempts." ) assert_error( errorstore, InvalidSetting, 'problem/problem.xml', "The tag <problem url_name='problem'> should have a positive number of attempts." ) assert_error( errorstore, InvalidSetting, 'vertical/vertical.xml', "The tag <drag-and-drop-v2 url_name='studio_mess2' display_name='This is my title'> has an error in the data JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)." ) assert_error( errorstore, InvalidSetting, 'vertical/vertical.xml', "The tag <drag-and-drop-v2 url_name='studio_mess3' display_name='This is my title'> data JSON is not a dictionary." ) assert_error( errorstore, InvalidSetting, 'sequential/examseq.xml', "The tag <sequential url_name='examseq' display_name='Exam'> is a timed exam, but the course policy does not have 'enable_timed_exams=true'." ) assert_error( errorstore, DateOrdering, 'vertical/oravert.xml', "The tag <openassessment url_name='paper-draft'> has a date out of order: assessment 1 due date must be before course end date" ) assert_caught_all_errors(errorstore) # Ensure that we got the scripts from the problem file assert set( url_names['problem'].scripts) == {'python', 'perl', 'javascript'} # Also make sure we detected the response types assert set(url_names['problem'].response_types) == { 'customresponse', 'multiplechoiceresponse' } # as well as the input types assert set(url_names['problem'].input_types) == {'choicegroup', 'textline'} # We also found the solution assert url_names['problem'].has_solution # Make sure our exam sequential was detected assert url_names['examseq'].is_exam
def handle_course2_errors(errorstore): assert_error(errorstore, CourseXMLName, 'coursefile.xml', 'The course file, coursefile.xml, is not named course.xml') assert_error( errorstore, URLNameMismatch, 'sequential/mysequential.xml', "The opening <sequential> tag has a mismatched url in url_name.") assert_error( errorstore, FileDoesNotExist, 'sequential/mysequential.xml', "The <vertical url_name='myverticalnone'> tag points to the file vertical/myverticalnone.xml that does not exist" ) assert_error( errorstore, EmptyTag, 'vertical/myvertical4.xml', "The <vertical url_name='myvertical4' display_name='Hello'> tag is unexpectedly empty" ) assert_error(errorstore, EmptyTag, 'sequential/mysequential.xml', "The <vertical> tag is unexpectedly empty") assert_error( errorstore, UnexpectedContent, 'vertical/myvertical4-2.xml', "The <vertical url_name='myvertical4-2' display_name='Hello'> tag should not contain any text (but not really...)" ) assert_error( errorstore, InvalidXML, 'vertical/myvertical5.xml', 'Opening and ending tag mismatch: vertical line 1 and chapter, line 2, column 11' ) assert_error( errorstore, UnexpectedTag, 'vertical/myvertical6.xml', "A <vertical> tag was unexpectedly found inside the <vertical url_name='myvertical6' display_name='Hello'> tag" ) assert_error( errorstore, UnexpectedTag, 'sequential/mysequential.xml', "A <chapter> tag was unexpectedly found inside the <vertical> tag") assert_error( errorstore, TagMismatch, 'vertical/myvertical7.xml', 'The file is of type <vertical> but opens with a <chapter> tag') assert_error( errorstore, SelfPointer, 'vertical/myvertical8.xml', "The tag <vertical url_name='myvertical8'> tag appears to be pointing to itself" ) assert_error( errorstore, UnexpectedContent, 'vertical/myvertical10.xml', "The <vertical url_name='myvertical10' display_name='something'> tag should not contain any text (Here is some co...)" ) assert_error( errorstore, UnexpectedContent, 'sequential/mysequential.xml', "The <vertical> tag should not contain any text (Here's some bad...)") assert_error(errorstore, InvalidHTML, 'html/html3.html', 'Unexpected end tag : b, line 1, column 34') assert_error( errorstore, PossiblePointer, 'vertical/myvertical1.xml', "The <problem url_name='problem2'> tag is not a pointer, but a file that it could point to exists (problem/problem2.xml)" ) assert_error( errorstore, PossibleHTMLPointer, 'html/html6.xml', "The <html url_name='html6'> tag is not a pointer, but a file that it could point to exists (html/html3.html)" ) assert_error( errorstore, PossibleHTMLPointer, 'vertical/myvertical3.xml', "The <html> tag is not a pointer, but a file that it could point to exists (html/html3.html)" ) assert_error( errorstore, NonFlatURLName, 'vertical/myvertical2.xml', "The <video url_name='stuff:video2'> tag uses obsolete colon notation in the url_name to point to a subdirectory" ) assert_error( errorstore, NonFlatFilename, 'html/html2.xml', "The <html url_name='html2'> tag uses obsolete colon notation to point to a subdirectory for filename html/stuff/html2.html" ) assert_error( errorstore, NonFlatFilename, 'vertical/myvertical3.xml', "The <html> tag uses obsolete colon notation to point to a subdirectory for filename html/stuff/here.html" ) assert_error( errorstore, FileDoesNotExist, 'html/html4.xml', "The <html url_name='html4'> tag points to the file html/htmlnotexist.html that does not exist" ) assert_error( errorstore, FileDoesNotExist, 'vertical/myvertical3.xml', "The <html> tag points to the file html/nonexistant.html that does not exist" ) assert_error( errorstore, DuplicateHTMLName, 'vertical/myvertical3.xml', "Two html tags refer to the same HTML file (using the 'filename' attribute): html/html7.html is referenced in vertical/myvertical3.xml and html/html7.xml" ) assert_error( errorstore, EmptyTag, 'problem/problem3.xml', "The <problem url_name='problem3' display_name='Blank Common Problem'> tag is unexpectedly empty" ) assert_error(errorstore, URLNameMismatch, 'video/video3.xml', "The opening <video> tag has a mismatched url in url_name.") assert_error( errorstore, URLNameMismatch, 'discussion/discussion1.xml', "The opening <discussion> tag has a mismatched url in url_name.") assert_error( errorstore, InvalidPointer, 'sequential/mysequential.xml', "The <vertical url_name='myvertical9' display_name='Hi there'> tag looks like it's trying to be a pointer but contains other attributes." ) assert_error( errorstore, PointerAlreadyPointedAt, 'sequential/sequence2.xml', "The <sequential url_name='some-non-existant-sequential'> tag has been pointed to and is pointing to another url_name" ) assert_error( errorstore, FileDoesNotExist, 'chapter/mychapter.xml', "The <sequential url_name='some-other-sequential-not-found'> tag points to the file sequential/some-other-sequential-not-found.xml that does not exist" )
def handle_nocourse_errors(errorstore): assert_error(errorstore, CourseXMLDoesNotExist, 'testcourses/nocourse.xml', 'The file \'testcourses/nocourse.xml\' does not exist.')
def handle_course7_errors(errorstore): assert_error( errorstore, DuplicateURLName, 'course/mycourseurl.xml', "Duplicate url_name found: 'html4' appears as <html> in course/mycourseurl.xml and also as <html> in course/mycourseurl.xml" ) assert_error( errorstore, PolicyRefNotFound, 'policy.json', "The policy file refers to <problem url_name='noexist'> which does not exist in the course structure" ) assert_error( errorstore, WrongObjectType, 'policy.json', "The policy file refers to a <video> tag with url_name 'html4'. However, that url_name points to a <html> tag." ) assert_error( errorstore, BadEntry, 'policy.json', "The policy file entry for <vertical url_name='vertical3'> is not a dictionary" ) assert_error( errorstore, SettingOverride, 'policy.json', "The policy file entry for <sequential url_name='sequential2'> is overriding the setting for 'setting'" ) assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is missing 'A'")
def test_grading_policy(): # Test grading policy entries in isolation errorstore = ErrorStore() # Set up the policy policy = {} # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "'GRADER' entry not found in grading policy") assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "'GRADE_CUTOFFS' entry not found in grading policy") assert_caught_all_errors(errorstore) # Set up the policy policy = {'GRADER': {}, 'GRADE_CUTOFFS': []} # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "'GRADER' entry not in grading policy is not a list") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'GRADE_CUTOFFS' entry not in grading policy is not a dictionary") assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Lab", "short_label": 15, "weight": 0.15 }, { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 0.15 }, ], 'GRADE_CUTOFFS': { 'Pass': -1 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "'weight' settings do not add up to 1") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'short_label' setting is not a string for entry 1 in the grading policy" ) assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 'hi', "min_count": 'hi', "type": 0, "weight": 'hi' }, { "drop_count": -1, "min_count": 0, "type": "Something", "weight": 1.1 }, {}, ], 'GRADE_CUTOFFS': { 'Pass': 2 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'drop_count' setting is not an integer for entry 1 in the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'min_count' setting is not an integer for entry 1 in the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'type' setting is not a string for entry 1 in the grading policy") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'weight' setting is not a number between 0 and 1 for entry 1 in the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'drop_count' setting is negative for entry 2 in the grading policy") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'min_count' setting is less than 1 for entry 2 in the grading policy") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'weight' setting is not a number between 0 and 1 for entry 2 in the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'drop_count' setting is omitted for entry 3 in the grading policy") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'min_count' setting is omitted for entry 3 in the grading policy") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'type' setting is omitted for entry 3 in the grading policy") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'weight' setting is omitted for entry 3 in the grading policy") assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "'weight' settings do not add up to 1") assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'Pass' entry is not between 0 and 1 in the GRADE_CUTOFFS part of the grading policy" ) assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 0.6 }, { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 0.4 }, ], 'GRADE_CUTOFFS': { 'A': -1, 'C': 3, 'D': 0.5, 'Pass': '******', 'pass': 1 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'A' entry is not between 0 and 1 in the GRADE_CUTOFFS part of the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'C' entry is not between 0 and 1 in the GRADE_CUTOFFS part of the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'pass' is not allowed in the GRADE_CUTOFFS part of the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "'Pass' entry is not a number in the GRADE_CUTOFFS part of the grading policy" ) assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "Assessment type 'Something' appears multiple times in the grading policy" ) assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 1 }, ], 'GRADE_CUTOFFS': { 'A': 0, 'C': 0.2, 'D': 0.5, 'Pass': 0.6, } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error( errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS should have either 'Pass' or letters, not both") assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 1 }, ], 'GRADE_CUTOFFS': { 'A': 0, 'C': 0.2, 'D': 0.5 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is missing 'B'") assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is entry 'C' is not decreasing") assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is entry 'D' is not decreasing") assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 1 }, ], 'GRADE_CUTOFFS': { 'A': 0, 'B': 0.1, 'C': 0.2, 'D': 0.5 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is entry 'B' is not decreasing") assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is entry 'C' is not decreasing") assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is entry 'D' is not decreasing") assert_caught_all_errors(errorstore) # Set up the policy policy = {'GRADER': [], 'GRADE_CUTOFFS': {}} # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADER entry in grading policy should not be empty") assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS entry in grading policy should not be empty") assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 1 }, ], 'GRADE_CUTOFFS': { 'A': 1, 'C': 0.1 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is missing 'B'") assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 1 }, ], 'GRADE_CUTOFFS': { 'B': 1, 'C': 0.1 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is missing 'A'") assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 1 }, ], 'GRADE_CUTOFFS': { 'B': 1 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS is missing 'A'") assert_caught_all_errors(errorstore) # Set up the policy policy = { 'GRADER': [ { "drop_count": 2, "min_count": 12, "type": "Something", "weight": 1 }, ], 'GRADE_CUTOFFS': { 'A': 1 } } # Validate it validate_grading_policy(policy, errorstore) # Handle errors assert_error(errorstore, GradingPolicyIssue, 'grading_policy.json', "GRADE_CUTOFFS should use 'Pass' instead of 'A'") assert_caught_all_errors(errorstore)
def handle_course6_errors(errorstore): assert_error( errorstore, MissingURLName, 'course/mycourseurl.xml', "The tag <vertical display_name='vertical name'> has no url_name.") assert_error( errorstore, MissingURLName, 'course/mycourseurl.xml', "The tag <vertical display_name='vertical name'> has no url_name.") assert_error( errorstore, DuplicateURLName, 'course/mycourseurl.xml', "Duplicate url_name found: 'html' appears as <html> in course/mycourseurl.xml and also as <html> in course/mycourseurl.xml" ) assert_error( errorstore, DuplicateURLName, 'course/mycourseurl.xml', "Duplicate url_name found: 'html' appears as <html> in course/mycourseurl.xml and also as <html> in course/mycourseurl.xml" ) assert_error( errorstore, DuplicateURLName, 'course/mycourseurl.xml', "Duplicate url_name found: 'html2' appears as <html> in course/mycourseurl.xml and also as <html> in course/mycourseurl.xml" ) assert_error(errorstore, BadPolicyFormat, 'policy.json', "The policy file is not a dictionary of values")