def test_invalid_date(self): """Validation should fail for invalid dates.""" workflow_dict = self.valid_human_review_workflow_dict workflow_dict['submission_due_date'] = 'test_string' workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assert_matching_errors([DATE_FORMAT_ERROR], self.errors) self.errors = [] workflow_dict = self.valid_human_review_workflow_dict workflow_dict['review_due_date'] = 'test_string' workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assert_matching_errors([DATE_FORMAT_ERROR], self.errors)
def test_empty_submission_date_in_grader(self): """Validation should pass for empty submission date.""" workflow = Workflow( self.to_yaml({ 'grader': 'auto', 'submission_due_date': '' })) workflow.validate(self.errors) self.assertFalse(self.errors)
def test_not_dict(self): """Validation should fail for non-dict YAML strings.""" yaml_strs = ['- first\n- second', 'grader'] for yaml_str in yaml_strs: self.errors = [] workflow = Workflow(yaml_str) workflow.validate(self.errors) self.assert_matching_errors( ['expected the YAML representation of a dict'], self.errors)
def test_valid_datetime(self): """Valid datetimes should be converted without problems.""" workflow = Workflow('') date_obj = workflow._convert_date_string_to_datetime( '2012-03-21 12:30') self.assertEqual(date_obj.year, 2012) self.assertEqual(date_obj.month, 3) self.assertEqual(date_obj.day, 21) self.assertEqual(date_obj.hour, 12) self.assertEqual(date_obj.minute, 30)
def test_submission_date_after_review_date_fails(self): """Validation should fail if review date precedes submission date.""" workflow_dict = self.valid_human_review_workflow_dict workflow_dict['submission_due_date'] = '2013-03-14 12:00' workflow_dict['review_due_date'] = '2013-03-13 12:00' workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assert_matching_errors( ['submission due date should be earlier than review due date.'], self.errors)
def test_invalid_datetime(self): """Valid datetimes should be converted without problems.""" invalid_date_strs = [ 'abc', '2012-13-31 12:30', '2012-12-31T12:30', '2012-13-31 12:30+0100' ] workflow = Workflow('') for date_str in invalid_date_strs: with self.assertRaises(Exception): workflow._convert_date_string_to_datetime(date_str)
def test_invalid_human_grader(self): """Validation should fail for invalid human grading specifications.""" workflow = Workflow(self.to_yaml({'grader': 'human'})) workflow.validate(self.errors) self.assert_matching_errors([ '%s matcher, review_min_count, review_window_mins, ' 'submission_due_date, review_due_date.' % MISSING_KEYS_PREFIX ], self.errors) self.errors = [] workflow = Workflow( self.to_yaml({ 'grader': 'human', 'matcher': 'peer' })) workflow.validate(self.errors) self.assert_matching_errors([ '%s review_min_count, review_window_mins, submission_due_date, ' 'review_due_date.' % MISSING_KEYS_PREFIX ], self.errors)
def test_multiple_errors(self): """Validation should fail with multiple errors when appropriate.""" workflow_dict = self.valid_human_review_workflow_dict workflow_dict['submission_due_date'] = '2013-03-14 12:00' workflow_dict['review_due_date'] = '2013-03-13 12:00' workflow_dict['review_window_mins'] = 'hello' workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assert_matching_errors([ 'review_window_mins should be an integer; submission due date ' 'should be earlier than review due date.' ], self.errors)
def test_invalid_review_window_mins(self): """Validation should fail for bad review_window_mins values.""" workflow_dict = self.valid_human_review_workflow_dict workflow_dict['review_window_mins'] = 'test_string' workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assert_matching_errors( ['review_window_mins should be an integer.'], self.errors) self.errors = [] workflow_dict['review_window_mins'] = -1 workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assert_matching_errors( ['review_window_mins should be a non-negative integer.'], self.errors) self.errors = [] workflow_dict['review_window_mins'] = 0 workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assertFalse(self.errors)
def test_invalid_string(self): """Validation should fail for invalid YAML strings.""" workflow = Workflow('(') workflow.validate(self.errors) self.assertTrue(self.errors)
def test_empty_string(self): """Validation should fail on an empty string.""" workflow = Workflow('') workflow.validate(self.errors) self.assert_matching_errors(['missing key: grader.'], self.errors)
def test_no_timezone_set(self): """Parsed date strings should contain no timezone information.""" workflow = Workflow('') date_obj = workflow._convert_date_string_to_datetime( '2012-03-21 12:30') self.assertIsNone(date_obj.tzinfo)
def test_valid_human_grader(self): """Validation should pass for valid human grading specifications.""" workflow_dict = self.valid_human_review_workflow_dict workflow = Workflow(self.to_yaml(workflow_dict)) workflow.validate(self.errors) self.assertFalse(self.errors)
def test_auto_grader(self): """Validation should pass for an auto-graded assessment.""" workflow = Workflow(self.to_yaml({'grader': 'auto'})) workflow.validate(self.errors) self.assertFalse(self.errors)
def test_missing_grader_key(self): """Validation should fail for missing grader key.""" workflow = Workflow(self.to_yaml({'not_grader': 'human'})) workflow.validate(self.errors) self.assert_matching_errors(['missing key: grader.'], self.errors)