def test_valid_data(self): test_posts = """\ forum_key|user_key|thread|post|timestamp 1|1|Name of thread|User 1 post|2017-10-05 13:30:00+00:00 1|2|Name of thread|User 2 post|2017-10-05 13:30:00+00:00 """ importer = BlackboardImport('ignore.zip', self.offering) posted_dt = datetime.datetime(2017, 10, 5, 13, 30, 0, tzinfo=datetime.timezone.utc) page = PageFactory(content_id=1, is_forum=True, content_type='resource/x-bb-discussionboard', 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_posts)) posts_data = csv.DictReader(csv_data, delimiter='|') importer._process_posts(posts_data) self.assertTrue( SummaryPost.objects.filter(page=page, lms_user=user1, posted_at=posted_dt).exists()) self.assertTrue( SummaryPost.objects.filter(page=page, lms_user=user2, posted_at=posted_dt).exists())
def test_invalid_column_names(self): test_posts = """\ forum_key|user_key|invalid_col 1|2|value """ csv_data = io.StringIO(dedent(test_posts)) posts_data = csv.DictReader(csv_data, delimiter='|') importer = BlackboardImport('ignore.zip', self.offering) with self.assertRaises(LMSImportFileError): importer._process_posts(posts_data)
def test_missing_related_objects(self): test_posts = """\ forum_key|user_key|thread|post|timestamp 1|500|Name of thread|User 1 post|2017-10-05 13:30:00+00:00 """ importer = BlackboardImport('ignore.zip', self.offering) PageFactory(content_id=1, is_forum=True, course_offering=self.offering) LMSUserFactory(lms_user_id=1, course_offering=self.offering) csv_data = io.StringIO(dedent(test_posts)) posts_data = csv.DictReader(csv_data, delimiter='|') importer._process_posts(posts_data) self.assertEqual(len(importer.error_list), 1)