def test_filter_out_verified_schedules(self):
        current_day, offset, target_day, upgrade_deadline = self._get_dates()

        user = UserFactory.create()
        schedules = [
            self._schedule_factory(
                enrollment__user=user,
                enrollment__course__id=CourseLocator('edX', 'toy',
                                                     'Course{}'.format(i)),
                enrollment__mode=CourseMode.VERIFIED
                if i in (0, 3) else CourseMode.AUDIT,
            ) for i in range(5)
        ]

        sent_messages = []
        with patch.object(self.task, 'async_send_task') as mock_schedule_send:
            mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(
                args[1])

            self.task().apply(kwargs=dict(
                site_id=self.site_config.site.id,
                target_day_str=serialize(target_day),
                day_offset=offset,
                bin_num=self._calculate_bin_for_user(user),
            ))

            messages = [Message.from_string(m) for m in sent_messages]
            self.assertEqual(len(messages), 1)
            message = messages[0]
            six.assertCountEqual(
                self, message.context['course_ids'],
                [str(schedules[i].enrollment.course.id) for i in (1, 2, 4)])
    def test_filter_out_verified_schedules(self):
        current_day, offset, target_day, upgrade_deadline = self._get_dates()

        user = UserFactory.create()
        schedules = [
            self._schedule_factory(
                enrollment__user=user,
                enrollment__course__id=CourseLocator('edX', 'toy', 'Course{}'.format(i)),
                enrollment__mode=CourseMode.VERIFIED if i in (0, 3) else CourseMode.AUDIT,
            )
            for i in range(5)
        ]

        sent_messages = []
        with patch.object(self.task, 'async_send_task') as mock_schedule_send:
            mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(args[1])

            self.task.apply(kwargs=dict(
                site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset,
                bin_num=self._calculate_bin_for_user(user),
            ))

            messages = [Message.from_string(m) for m in sent_messages]
            self.assertEqual(len(messages), 1)
            message = messages[0]
            self.assertItemsEqual(
                message.context['course_ids'],
                [str(schedules[i].enrollment.course.id) for i in (1, 2, 4)]
            )
Exemplo n.º 3
0
    def setUp(self):
        patcher = patch(
            'openedx.core.djangoapps.schedules.templatetags.ace.get_current_request'
        )
        self.mock_get_current_request = patcher.start()
        self.addCleanup(patcher.stop)

        self.fake_request = HttpRequest()
        self.fake_request.user = UserFactory.create()
        self.fake_request.site = SiteFactory.create()
        self.fake_request.site.domain = 'example.com'
        self.mock_get_current_request.return_value = self.fake_request

        self.message = Message(
            app_label='test_app_label',
            name='test_name',
            recipient=Recipient(username='******'),
            context={},
            send_uuid=uuid.uuid4(),
        )
        self.context = {'message': self.message}
Exemplo n.º 4
0
    def setUp(self):
        super(EmailTemplateTagMixin, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        patcher = patch(
            'openedx.core.djangoapps.ace_common.templatetags.ace.get_current_request'
        )
        self.mock_get_current_request = patcher.start()
        self.addCleanup(patcher.stop)

        self.fake_request = HttpRequest()
        self.fake_request.user = UserFactory.create()
        self.fake_request.site = SiteFactory.create()
        self.fake_request.site.domain = 'example.com'
        self.mock_get_current_request.return_value = self.fake_request

        self.message = Message(
            app_label='test_app_label',
            name='test_name',
            recipient=Recipient(username='******'),
            context={},
            send_uuid=uuid.uuid4(),
        )
        self.context = {'message': self.message}