Ejemplo n.º 1
0
    def test_course_publish_successfully(self):
        """ Verify all courses are successfully published."""

        second_course = CourseFactory.create()
        self.create_course_ids_file(self.tmp_file_path,
                                    [self.course.id, second_course.id])
        expected = ((LOGGER_NAME, "INFO", "Publishing 2 courses."),
                    (LOGGER_NAME, "INFO",
                     u"(1/2) Successfully published {}.".format(
                         self.course.id)),
                    (LOGGER_NAME, "INFO",
                     u"(2/2) Successfully published {}.".format(
                         second_course.id)),
                    (LOGGER_NAME, "INFO",
                     "All 2 courses successfully published."))
        with mock.patch.object(Course, 'publish_to_lms',
                               autospec=True) as mock_publish:
            mock_publish.return_value = None
            with LogCapture(LOGGER_NAME) as lc:
                call_command('publish_to_lms',
                             course_ids_file=self.tmp_file_path)
                lc.check(*expected)
        # Check that the mocked function was called twice.
        self.assertListEqual(
            mock_publish.call_args_list,
            [call(self.course), call(second_course)])
    def test_course_publish_successfully(self):
        """ Verify all courses are successfully published."""

        second_course = CourseFactory.create()
        self.create_course_ids_file(self.tmp_file_path, [self.course.id, second_course.id])
        expected = (
            (
                LOGGER_NAME,
                "INFO",
                "Publishing 2 courses."
            ),
            (
                LOGGER_NAME,
                "INFO",
                u"(1/2) Successfully published {}.".format(self.course.id)
            ),
            (
                LOGGER_NAME,
                "INFO",
                u"(2/2) Successfully published {}.".format(second_course.id)),
            (
                LOGGER_NAME,
                "INFO",
                "All 2 courses successfully published."
            )
        )
        with mock.patch.object(Course, 'publish_to_lms', autospec=True) as mock_publish:
            mock_publish.return_value = None
            with LogCapture(LOGGER_NAME) as lc:
                call_command('publish_to_lms', course_ids_file=self.tmp_file_path)
                lc.check(*expected)
        # Check that the mocked function was called twice.
        self.assertListEqual(mock_publish.call_args_list, [call(self.course), call(second_course)])