Example #1
0
    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())
Example #2
0
    def test_valid_data(self):
        test_resources = """\
            content_key|parent_content_key|title|resource_type
            1||Parent page|resource/x-bb-document
            2|1|Child page|resource/x-bb-document
        """

        importer = BlackboardImport('ignore.zip', self.offering)

        csv_data = io.StringIO(dedent(test_resources))
        resources_data = csv.DictReader(csv_data, delimiter='|')
        importer._process_resources(resources_data)

        self.assertTrue(
            Page.objects.filter(content_id=1,
                                parent__isnull=True,
                                title='Parent page',
                                content_type='resource/x-bb-document',
                                is_forum=False,
                                course_offering=self.offering).exists())
        self.assertTrue(
            Page.objects.filter(content_id=2,
                                parent__isnull=True,
                                title='Child page',
                                content_type='resource/x-bb-document',
                                is_forum=False,
                                course_offering=self.offering).exists())
Example #3
0
    def test_invalid_column_names(self):
        test_activity = """\
            user_key|content_key|invalid_col
            1|2|value
        """

        csv_data = io.StringIO(dedent(test_activity))
        activity_data = csv.DictReader(csv_data, delimiter='|')

        importer = BlackboardImport('ignore.zip', self.offering)

        with self.assertRaises(LMSImportFileError):
            importer._process_access_log(activity_data)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    def test_invalid_column_names(self):
        test_resources = """\
            content_key|parent_content_key|invalid_col
            1|2|value
        """

        csv_data = io.StringIO(dedent(test_resources))
        resources_data = csv.DictReader(csv_data, delimiter='|')

        importer = BlackboardImport('ignore.zip', self.offering)

        with self.assertRaises(LMSImportFileError):
            importer._process_resources(resources_data)
Example #7
0
    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)
Example #8
0
    def test_missing_parents_data(self):
        test_resources = """\
            content_key|parent_content_key|title|resource_type
            1||Parent page|resource/x-bb-document
            2|500|Child page|resource/x-bb-document
        """

        importer = BlackboardImport('ignore.zip', self.offering)

        PageFactory(content_id=1, course_offering=self.offering)
        PageFactory(content_id=2, course_offering=self.offering)

        csv_data = io.StringIO(dedent(test_resources))
        resources_data = csv.DictReader(csv_data, delimiter='|')
        importer._process_resource_parents(resources_data)
        self.assertEqual(len(importer.non_critical_error_list), 1)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
    def test_valid_data(self):
        test_users = """\
            user_key|username|firstname|lastname|email
            1|fred|Fred|Jones|[email protected]
        """

        csv_data = io.StringIO(dedent(test_users))
        user_data = csv.DictReader(csv_data, delimiter='|')

        importer = BlackboardImport('ignore.zip', self.offering)
        importer._process_users(user_data)

        self.assertTrue(
            LMSUser.objects.filter(lms_user_id=1,
                                   username='******',
                                   firstname='Fred',
                                   lastname='Jones',
                                   email='*****@*****.**',
                                   course_offering=self.offering).exists())
Example #12
0
    def test_valid_data(self):
        test_activity = """\
            user_key|content_key|forum_key|timestamp
            1|1||2017-10-05 13:30:00+00:00
            2|1||2017-10-05 13:30:00+00:00
            2||2|2017-10-05 13:30:00+00:00
        """

        importer = BlackboardImport('ignore.zip', self.offering)

        visit_dt = datetime.datetime(2017,
                                     10,
                                     5,
                                     13,
                                     30,
                                     0,
                                     tzinfo=datetime.timezone.utc)
        resource_page = PageFactory(content_id=1,
                                    is_forum=False,
                                    course_offering=self.offering)
        post_page = PageFactory(content_id=2,
                                is_forum=True,
                                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_activity))
        activity_data = csv.DictReader(csv_data, delimiter='|')
        importer._process_access_log(activity_data)

        self.assertTrue(
            PageVisit.objects.filter(page=resource_page,
                                     lms_user=user1,
                                     visited_at=visit_dt).exists())
        self.assertTrue(
            PageVisit.objects.filter(page=resource_page,
                                     lms_user=user2,
                                     visited_at=visit_dt).exists())
        self.assertTrue(
            PageVisit.objects.filter(page=post_page,
                                     lms_user=user2,
                                     visited_at=visit_dt).exists())
Example #13
0
    def test_missing_related_objects(self):
        test_activity = """\
            user_key|content_key|forum_key|timestamp
            1|500||2017-10-05 13:30:00+00:00
            1||500|2017-10-05 13:30:00+00:00
            500|1||2017-10-05 13:30:00+00:00
        """

        importer = BlackboardImport('ignore.zip', self.offering)

        PageFactory(content_id=1,
                    is_forum=False,
                    course_offering=self.offering)
        LMSUserFactory(lms_user_id=1, course_offering=self.offering)

        csv_data = io.StringIO(dedent(test_activity))
        activity_data = csv.DictReader(csv_data, delimiter='|')
        importer._process_access_log(activity_data)

        self.assertEqual(len(importer.non_critical_error_list), 2)
        self.assertEqual(len(importer.error_list), 1)
Example #14
0
    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())