def test_preview_available_email_with_notification_disabled(self):
        """ Verify that email not sent if notification disabled by user."""
        factories.UserAttributeFactory(user=self.course.course_team_admin,
                                       enable_email_notification=False)
        emails.send_email_preview_page_is_available(self.run_state.course_run)

        self.assertEqual(len(mail.outbox), 0)
    def test_preview_accepted_email_with_notification_disabled(self):
        """ Verify that preview accepted email not sent if notification disabled by user."""
        factories.UserAttributeFactory(user=self.course.publisher,
                                       enable_email_notification=False)
        emails.send_email_preview_accepted(self.run_state.course_run)

        self.assertEqual(len(mail.outbox), 0)
 def test_str(self):
     """ Verify casting an instance to a string returns a string containing the user name and
     current enable status. """
     user_attr = factories.UserAttributeFactory()
     assert str(user_attr) == '{user}: {enable_email_notification}'.format(
         user=user_attr.user,
         enable_email_notification=user_attr.enable_email_notification)
Esempio n. 4
0
    def test_decline_preview_comment_with_disable_email(self):
        """ Verify that no email will be sent if publisher user has disabled the email."""
        user = UserFactory()
        factories.CourseUserRoleFactory(course=self.course,
                                        role=PublisherUserRole.Publisher,
                                        user=user)
        factories.UserAttributeFactory(user=user,
                                       enable_email_notification=False)

        self._create_decline_comment()
        self.assertEqual(len(mail.outbox), 0)
    def test_get_course_users_emails(self):
        """ Verify the method returns the email addresses of users who are
        permitted to access the course AND have not disabled email notifications.
        """
        self.assertListEqual(
            self.course.get_course_users_emails(),
            [self.user1.email, self.user2.email, self.user3.email]
        )

        # The email addresses of users who have disabled email notifications should NOT be returned.
        factories.UserAttributeFactory(user=self.user1, enable_email_notification=False)
        self.assertListEqual(self.course.get_course_users_emails(), [self.user2.email, self.user3.email])
Esempio n. 6
0
    def test_is_email_notification_enabled(self):
        """ Test email notification enabled/disabled for the user."""

        user_attribute = factories.UserAttributeFactory(user=self.user)

        # Verify email notifications are enabled for user with associated attributes,
        # but no explicit value set for the enable_email_notification attribute
        self.assertEqual(is_email_notification_enabled(self.user), True)

        # Disabled email notification
        user_attribute.enable_email_notification = False
        user_attribute.save()  # pylint: disable=no-member

        # Verify that email notifications are disabled for the user
        self.assertEqual(is_email_notification_enabled(self.user), False)
    def test_is_email_notification_enabled(self):
        """ Test email notification enabled/disabled for the user."""

        user_attribute = factories.UserAttributeFactory(user=self.user)

        # Verify email notifications are enabled for user with associated attributes,
        # but no explicit value set for the enable_email_notification attribute
        assert is_email_notification_enabled(self.user) is True

        # Disabled email notification
        user_attribute.enable_email_notification = False
        user_attribute.save()

        # Verify that email notifications are disabled for the user
        assert is_email_notification_enabled(self.user) is False
Esempio n. 8
0
    def setUp(self):
        super(ChangeCourseStateViewTests, self).setUp()
        self.course_state = factories.CourseStateFactory(name=CourseStateChoices.Draft)
        self.user = UserFactory()
        self.user.groups.add(Group.objects.get(name=INTERNAL_USER_GROUP_NAME))

        self.course = self.course_state.course
        self.course.image = make_image_file('test_banner.jpg')
        self.course.save()

        self.organization_extension = factories.OrganizationExtensionFactory()
        self.course.organizations.add(self.organization_extension.organization)
        factories.UserAttributeFactory(user=self.user, enable_email_notification=True)
        toggle_switch('enable_publisher_email_notifications', True)

        self.change_state_url = reverse('publisher:api:change_course_state', kwargs={'pk': self.course_state.id})

        self.client.login(username=self.user.username, password=USER_PASSWORD)
Esempio n. 9
0
    def test_update_preview_url_with_notification_disabled(self):
        """
        Verify that no email sent on update course preview url if
        notification disabled by user.
        """
        preview_url = 'https://example.com/abc/course'
        factories.CourseRunStateFactory.create(course_run=self.course_run, owner_role=PublisherUserRole.Publisher)
        course_team_role = factories.CourseUserRoleFactory(
            course=self.course_run.course, role=PublisherUserRole.CourseTeam
        )
        factories.UserAttributeFactory(user=course_team_role.user, enable_email_notification=False)

        response = self._make_request(preview_url)

        self.assertEqual(response.status_code, 200)
        course_run = CourseRun.objects.get(id=self.course_run.id)
        self.assertEqual(course_run.preview_url, preview_url)
        self.assertEqual(len(mail.outbox), 0)
Esempio n. 10
0
    def setUp(self):
        super(UpdateCourseRunViewTests, self).setUp()
        self.course_run = factories.CourseRunFactory()
        self.user = UserFactory()
        self.user.groups.add(Group.objects.get(name=INTERNAL_USER_GROUP_NAME))

        self.organization_extension = factories.OrganizationExtensionFactory()
        self.course_run.course.organizations.add(self.organization_extension.organization)

        self.update_course_run_url = reverse(
            'publisher:api:update_course_run', kwargs={'pk': self.course_run.id}
        )

        factories.CourseUserRoleFactory(
            role=PublisherUserRole.ProjectCoordinator,
            course=self.course_run.course,
            user=self.user
        )

        factories.UserAttributeFactory(user=self.user, enable_email_notification=True)
        toggle_switch('enable_publisher_email_notifications', True)
        self.client.login(username=self.user.username, password=USER_PASSWORD)
Esempio n. 11
0
    def test_update_preview_url_with_notification_disabled(self):
        """
        Verify that no email sent on update course preview url if
        notification disabled by user.
        """
        self.course_run.lms_course_id = 'course-v1:testX+TC167+2018T1'
        self.course_run.save()
        factories.CourseRunStateFactory.create(course_run=self.course_run, owner_role=PublisherUserRole.Publisher)
        course_team_role = factories.CourseUserRoleFactory(
            course=self.course_run.course, role=PublisherUserRole.CourseTeam
        )
        factories.UserAttributeFactory(user=course_team_role.user, enable_email_notification=False)
        person = PersonFactory()
        DiscoveryCourseRunFactory(key=self.course_run.lms_course_id, staff=[person])

        preview_url = 'https://example.com/abc/new-course-preview'
        response = self._make_request(preview_url)

        self.assertEqual(response.status_code, 200)
        course_run = CourseRun.objects.get(id=self.course_run.id)
        self.assertTrue(course_run.preview_url.endswith('/new-course-preview'))
        self.assertEqual(len(mail.outbox), 0)
 def setUp(self):
     super(UserAttributeTests, self).setUp()
     self.user_attr = factories.UserAttributeFactory()