def test_invalid_column_names(self): test_submissions = """\ user_key|content_key|invalid_col 1|2|value """ csv_data = io.StringIO(dedent(test_submissions)) submissions_data = csv.DictReader(csv_data, delimiter='|') importer = BlackboardImport('ignore.zip', self.offering) with self.assertRaises(LMSImportFileError): importer._process_submission_attempts(submissions_data)
def test_missing_related_objects(self): test_submissions = """\ user_key|content_key|user_grade|timestamp 1|500|0|2017-10-05 13:30:00+00:00 500|1|10.5|2017-10-05 13:30:00+00:00 """ importer = BlackboardImport('ignore.zip', self.offering) PageFactory(content_id=1, course_offering=self.offering) LMSUserFactory(lms_user_id=1, course_offering=self.offering) csv_data = io.StringIO(dedent(test_submissions)) submissions_data = csv.DictReader(csv_data, delimiter='|') importer._process_submission_attempts(submissions_data) self.assertEqual(len(importer.error_list), 2)
def test_submission_for_invalid_resource_type(self): test_submissions = """\ user_key|content_key|user_grade|timestamp 1|1|0|2017-10-05 13:30:00+00:00 """ importer = BlackboardImport('ignore.zip', self.offering) PageFactory(content_id=1, content_type='resource/x-bb-document', course_offering=self.offering) LMSUserFactory(lms_user_id=1, course_offering=self.offering) csv_data = io.StringIO(dedent(test_submissions)) submissions_data = csv.DictReader(csv_data, delimiter='|') importer._process_submission_attempts(submissions_data) self.assertEqual(len(importer.non_critical_error_list), 1)
def test_valid_data(self): test_submissions = """\ user_key|content_key|user_grade|timestamp 1|1|0|2017-10-05 13:30:00+00:00 2|1|10.5|2017-10-05 13:30:00+00:00 """ importer = BlackboardImport('ignore.zip', self.offering) attempt_dt = datetime.datetime(2017, 10, 5, 13, 30, 0, tzinfo=datetime.timezone.utc) page = PageFactory(content_id=1, content_type='course/x-bb-courseassessment', course_offering=self.offering) user1 = LMSUserFactory(lms_user_id=1, course_offering=self.offering) user2 = LMSUserFactory(lms_user_id=2, course_offering=self.offering) csv_data = io.StringIO(dedent(test_submissions)) submissions_data = csv.DictReader(csv_data, delimiter='|') importer._process_submission_attempts(submissions_data) self.assertTrue( SubmissionAttempt.objects.filter(page=page, lms_user=user1, grade='0', attempted_at=attempt_dt).exists()) self.assertTrue( SubmissionAttempt.objects.filter(page=page, lms_user=user2, grade='10.5', attempted_at=attempt_dt).exists())