コード例 #1
0
 def setUp(self):
     super(ExtractorTest, self).setUp()
     self.extractor = Extractor()
コード例 #2
0
 def setUp(self):
     super(ExtractorTest, self).setUp()
     self.extractor = Extractor()
コード例 #3
0
class ExtractorTest(TestCase):
    """ Tests that Extractor extracts correct data and transforms it into expected format """
    def setUp(self):
        super(ExtractorTest, self).setUp()
        self.extractor = Extractor()

    @ddt.unpack
    @ddt.data(*_std_parameters_list)
    def test_extract_invokes_correct_data_extraction_methods(self, course_key, end_date, thread_type, thread_ids):
        """ Tests that correct underlying extractors are called with proper arguments """
        with mock.patch(_target_module + '.CourseEnrollment.objects.users_enrolled_in') as patched_users_enrolled_in, \
                mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats:
            self.extractor.extract(course_key, end_date=end_date, thread_type=thread_type, thread_ids=thread_ids)
            patched_users_enrolled_in.return_value = []
            patched_users_enrolled_in.patched_all_social_stats = {}
            patched_users_enrolled_in.assert_called_with(course_key)
            patched_all_social_stats.assert_called_with(
                str(course_key), end_date=end_date, thread_type=thread_type, thread_ids=thread_ids
            )

    @ddt.unpack
    @ddt.data(
        ([], {}, []),
        (
            [_make_user_mock(1)],
            {"1": _make_social_stats(num_threads=1)},
            [_make_result(1, num_threads=1)]
        ),
        (
            [
                _make_user_mock(1, username="******", email="*****@*****.**", first_name="w", last_name="e"),
                _make_user_mock(2, username="******", email="*****@*****.**", first_name="s", last_name="d"),
                _make_user_mock(3, username="******", email="*****@*****.**", first_name="x", last_name="c"),
            ],
            {
                "1": _make_social_stats(
                    num_threads=1, num_comments=3, num_replies=7,
                    num_upvotes=2, num_thread_followers=4, num_comments_generated=4
                ),
                "2": _make_social_stats(
                    num_threads=7, num_comments=15, num_replies=3,
                    num_upvotes=4, num_thread_followers=5, num_comments_generated=19
                )
            },
            [
                _make_result(
                    1, username="******", email="*****@*****.**", first_name="w", last_name="e",
                    num_threads=1, num_comments=3, num_replies=7,
                    num_upvotes=2, num_thread_followers=4, num_comments_generated=4
                ),
                _make_result(
                    2, username="******", email="*****@*****.**", first_name="s", last_name="d",
                    num_threads=7, num_comments=15, num_replies=3,
                    num_upvotes=4, num_thread_followers=5, num_comments_generated=19
                ),
                _make_result(3, username="******", email="*****@*****.**", first_name="x", last_name="c")
            ]
        ),
    )
    def test_extract_correctly_merges_data(self, user_data, social_stats, expected_result):
        """ Tests that extracted data is merged correctly """
        with mock.patch(_target_module + '.CourseEnrollment.objects.users_enrolled_in') as patched_users_enrolled_in, \
                mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats:
            patched_users_enrolled_in.return_value = user_data
            patched_all_social_stats.return_value = social_stats

            result = self.extractor.extract(CourseLocator("completely", "irrelevant", "here"))
            self.assertEqual(sorted(result, key=lambda i: i[DiscussionExportFields.USER_ID]), expected_result)
コード例 #4
0
class ExtractorTest(TestCase):
    """ Tests that Extractor extracts correct data and transforms it into expected format """
    def setUp(self):
        super(ExtractorTest, self).setUp()
        self.extractor = Extractor()

    @ddt.unpack
    @ddt.data(*_std_parameters_list)
    def test_extract_invokes_correct_data_extraction_methods(
            self, course_key, end_date, thread_type, thread_ids):
        """ Tests that correct underlying extractors are called with proper arguments """
        with mock.patch(_target_module + '.CourseEnrollment.objects.users_enrolled_in') as patched_users_enrolled_in, \
                mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats:
            self.extractor.extract(course_key,
                                   end_date=end_date,
                                   thread_type=thread_type,
                                   thread_ids=thread_ids)
            patched_users_enrolled_in.return_value = []
            patched_users_enrolled_in.patched_all_social_stats = {}
            patched_users_enrolled_in.assert_called_with(course_key)
            patched_all_social_stats.assert_called_with(
                str(course_key),
                end_date=end_date,
                thread_type=thread_type,
                thread_ids=thread_ids)

    @ddt.unpack
    @ddt.data(
        ([], {}, []),
        ([_make_user_mock(1)], {
            "1": _make_social_stats(num_threads=1)
        }, [_make_result(1, num_threads=1)]),
        ([
            _make_user_mock(1,
                            username="******",
                            email="*****@*****.**",
                            first_name="w",
                            last_name="e"),
            _make_user_mock(2,
                            username="******",
                            email="*****@*****.**",
                            first_name="s",
                            last_name="d"),
            _make_user_mock(3,
                            username="******",
                            email="*****@*****.**",
                            first_name="x",
                            last_name="c"),
        ], {
            "1":
            _make_social_stats(num_threads=1,
                               num_comments=3,
                               num_replies=7,
                               num_upvotes=2,
                               num_thread_followers=4,
                               num_comments_generated=4),
            "2":
            _make_social_stats(num_threads=7,
                               num_comments=15,
                               num_replies=3,
                               num_upvotes=4,
                               num_thread_followers=5,
                               num_comments_generated=19)
        }, [
            _make_result(1,
                         username="******",
                         email="*****@*****.**",
                         first_name="w",
                         last_name="e",
                         num_threads=1,
                         num_comments=3,
                         num_replies=7,
                         num_upvotes=2,
                         num_thread_followers=4,
                         num_comments_generated=4),
            _make_result(2,
                         username="******",
                         email="*****@*****.**",
                         first_name="s",
                         last_name="d",
                         num_threads=7,
                         num_comments=15,
                         num_replies=3,
                         num_upvotes=4,
                         num_thread_followers=5,
                         num_comments_generated=19),
            _make_result(3,
                         username="******",
                         email="*****@*****.**",
                         first_name="x",
                         last_name="c")
        ]),
    )
    def test_extract_correctly_merges_data(self, user_data, social_stats,
                                           expected_result):
        """ Tests that extracted data is merged correctly """
        with mock.patch(_target_module + '.CourseEnrollment.objects.users_enrolled_in') as patched_users_enrolled_in, \
                mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats:
            patched_users_enrolled_in.return_value = user_data
            patched_all_social_stats.return_value = social_stats

            result = self.extractor.extract(
                CourseLocator("completely", "irrelevant", "here"))
            self.assertEqual(
                sorted(result,
                       key=lambda i: i[DiscussionExportFields.USER_ID]),
                expected_result)