Esempio n. 1
0
    def setUp(self):
        """
        Setup the test data
        """
        super(SendCodeAssignmentNudgeEmailsTests, self).setUp()
        # Create a voucher with valid offer so we can get
        voucher = VoucherFactory()
        voucher.offers.add(EnterpriseOfferFactory(max_global_applications=98))

        self.total_nudge_emails_for_today = 5
        self.nudge_emails = CodeAssignmentNudgeEmailsFactory.create_batch(
            self.total_nudge_emails_for_today, code=voucher.code)
        CodeAssignmentNudgeEmailsFactory(email_date=datetime.datetime.now() +
                                         relativedelta(days=1))
        CodeAssignmentNudgeEmailsFactory(email_date=datetime.datetime.now() +
                                         relativedelta(days=2))

        for nudge_email in self.nudge_emails:
            OfferAssignmentFactory(code=nudge_email.code,
                                   user_email=nudge_email.user_email)
 def test_nudge_email_command_with_invalid_code(self):
     """
     Test the send_enterprise_offer_limit_emails command
     """
     code = "dummy-code"
     CodeAssignmentNudgeEmailsFactory(code=code)
     log = self._assert_sent_count()
     log.check_present((
         LOGGER_NAME, 'INFO',
         '[Code Assignment Nudge Email] Total count of Enterprise Nudge Emails that are scheduled for '
         'today is {send_nudge_email_count}.'.format(
             send_nudge_email_count=self.total_nudge_emails_for_today + 1)
     ), (LOGGER_NAME, 'INFO',
         '[Code Assignment Nudge Email] {send_nudge_emails_count} out of {total_nudge_emails} added to the '
         'email sending queue.'.format(
             total_nudge_emails=self.total_nudge_emails_for_today + 1,
             send_nudge_emails_count=self.total_nudge_emails_for_today)))
Esempio n. 3
0
    def test_update_assigned_voucher_offer_assignment(self, __):
        """
        Verify the "update_assigned_voucher_offer_assignment" works as expected.
        """
        enterprise_offer = EnterpriseOfferFactory()
        voucher = VoucherFactory()
        voucher.offers.add(enterprise_offer)
        basket = create_basket(owner=self.user, site=self.site)
        basket.vouchers.add(voucher)
        order = create_order(user=self.user, basket=basket)
        voucher_application = VoucherApplication.objects.create(
            voucher=voucher, user=self.user, order=order)
        offer_assignment = OfferAssignmentFactory(offer=enterprise_offer,
                                                  code=voucher.code,
                                                  user_email=self.user.email)

        # create nudge email templates and subscription records
        for email_type in (DAY3, DAY10, DAY19):
            nudge_email_template = CodeAssignmentNudgeEmailTemplatesFactory(
                email_type=email_type)
            nudge_email = CodeAssignmentNudgeEmailsFactory(
                email_template=nudge_email_template,
                user_email=self.user.email,
                code=voucher.code)

            # verify subscription is active
            assert nudge_email.is_subscribed

        EdxOrderPlacementMixin().update_assigned_voucher_offer_assignment(
            order)

        offer_assignment = OfferAssignment.objects.get(id=offer_assignment.id)
        assert offer_assignment.status == OFFER_REDEEMED
        assert offer_assignment.voucher_application == voucher_application

        # verify that nudge emails subscriptions are inactive
        assert CodeAssignmentNudgeEmails.objects.filter(
            is_subscribed=True).count() == 0
        assert CodeAssignmentNudgeEmails.objects.filter(
            code__in=[voucher.code],
            user_email__in=[self.user.email],
            is_subscribed=False).count() == 3
Esempio n. 4
0
 def test_nudge_email_command_with_invalid_code(self):
     """
     Test the send_enterprise_offer_limit_emails command
     """
     code = "dummy-code"
     nudge_email_without_voucher = CodeAssignmentNudgeEmailsFactory(
         code=code)
     log = self._assert_sent_count()
     log.check_present((
         LOGGER_NAME, 'INFO',
         '[Code Assignment Nudge Email] Total count of Enterprise Nudge Emails that are scheduled for '
         'today is {send_nudge_email_count}.'.format(
             send_nudge_email_count=self.total_nudge_emails_for_today + 1)
     ), (
         MODEL_LOGGER_NAME, 'WARNING',
         '[Code Assignment Nudge Email] Unable to send the email for user_email: {user_email}, code: '
         '{code} because code does not have associated voucher.'.format(
             user_email=nudge_email_without_voucher.user_email, code=code)
     ), (LOGGER_NAME, 'INFO',
         '[Code Assignment Nudge Email] {send_nudge_emails_count} out of {total_nudge_emails} added to the '
         'email sending queue.'.format(
             total_nudge_emails=self.total_nudge_emails_for_today + 1,
             send_nudge_emails_count=self.total_nudge_emails_for_today)))