コード例 #1
0
    def test_create_course_email_with_optional_args(self):
        """
        Additional testing to verify that optional data is used as expected when passed into the `create_course_email`
        function.
        """
        text_message = "everything is awesome!"
        template_name = "gnarly_template"
        from_addr = "*****@*****.**"

        course_email = create_course_email(self.course.id,
                                           self.instructor,
                                           self.target,
                                           self.subject,
                                           self.html_message,
                                           text_message=text_message,
                                           template_name=template_name,
                                           from_addr=from_addr)

        assert course_email.sender.id == self.instructor.id
        assert course_email.subject == self.subject
        assert course_email.html_message == self.html_message
        assert course_email.course_id == self.course.id
        assert course_email.text_message == text_message
        assert course_email.template_name == template_name
        assert course_email.from_addr == from_addr
コード例 #2
0
    def test_create_course_email_expect_exception(self):
        """
        Test to verify behavior when an exception occurs when calling teh `create_course_email` function.
        """
        targets = ["humpty dumpty"]

        expected_message = (
            f"Cannot create course email for {self.course.id} requested by user {self.instructor} for targets "
            f"{targets}")

        with self.assertRaises(ValueError):
            with LogCapture() as log:
                create_course_email(self.course.id, self.instructor, targets,
                                    self.subject, self.html_message)

        log.check_present((LOG_PATH, "ERROR", expected_message), )
コード例 #3
0
 def _create_course_email(self, course_id, author, targets, subject,
                          message):
     """
     Utility function to create CourseEmail objects for the test suite.
     """
     return create_course_email(course_id, author, targets, subject,
                                message)
コード例 #4
0
    def _create_course_email(self, targets):
        """
        Create CourseEmail object for testing.
        """
        course_email = create_course_email(self.course.id, self.instructor,
                                           targets, "Test Subject",
                                           "<p>Test message.</p>")

        return course_email
コード例 #5
0
    def test_create_course_email_expect_exception(self):
        """
        Test to verify behavior when an exception occurs when calling teh `create_course_email` function.
        """
        targets = ["humpty dumpty"]

        expected_messages = [
            f"Cannot create course email for {self.course.id} requested by user {self.instructor} for targets "
            f"{targets}",
        ]

        with self.assertRaises(ValueError):
            with LogCapture() as log:
                create_course_email(self.course.id, self.instructor, targets,
                                    self.subject, self.html_message)

        for index, message in enumerate(expected_messages):
            assert message in log.records[index].getMessage()
コード例 #6
0
ファイル: test_api.py プロジェクト: uetuluk/edx-platform
 def _define_course_email(self):
     """Create CourseEmail object for testing."""
     email_recipient_groups = [
         BulkEmailTargetChoices.SEND_TO_MYSELF,
         BulkEmailTargetChoices.SEND_TO_STAFF,
         BulkEmailTargetChoices.SEND_TO_LEARNERS
     ]
     course_email = create_course_email(self.course.id, self.instructor,
                                        email_recipient_groups,
                                        "Test Subject",
                                        "<p>This is a test message</p>")
     return course_email.id
コード例 #7
0
    def test_create_course_email(self):
        """
        Happy path test for the `create_course_email` function. Verifies the creation of a CourseEmail instance with
        the bare minimum information required for the function call.
        """
        course_email = create_course_email(
            self.course.id,
            self.instructor,
            self.target,
            self.subject,
            self.html_message,
        )

        assert course_email.sender.id == self.instructor.id
        assert course_email.subject == self.subject
        assert course_email.html_message == self.html_message
        assert course_email.course_id == self.course.id
        assert course_email.text_message == html_to_text(self.html_message)
コード例 #8
0
    def test_get_course_email(self):
        """
        A test to verify the happy path behavior of the `get_course_email` utility function and the presence of an
        expected log message when an email instance can't be found for a given id.
        """
        course_email = create_course_email(
            self.course.id,
            self.instructor,
            self.target,
            self.subject,
            self.html_message,
        )

        email_instance = get_course_email(course_email.id)
        assert email_instance.id == course_email.id

        email_id_dne = 3463435
        expected_message = (
            f"CourseEmail instance with id '{email_id_dne}' could not be found"
        )
        with LogCapture() as log:
            get_course_email(email_id_dne)

        log.check_present((LOG_PATH, "ERROR", expected_message), )