Exemple #1
0
    def text_nested_extending_mail_template(self):
        email_message = BaseEmailMessage(template_name='nested_extends.html')
        email_message.render()

        self.assertEquals(email_message.subject, 'Text and HTML mail subject')
        self.assertEquals(email_message.body, 'Some extended text body')
        self.assertEquals(email_message.html, 'Some extended HTML body')
    def test_get_context_data_without_request_no_context(self):
        email_message = BaseEmailMessage(template_name='text_mail.html')
        context = email_message.get_context_data()

        self.assertEquals(context['domain'], '')
        self.assertEquals(context['protocol'], 'http')
        self.assertEquals(context['site_name'], '')
        self.assertEquals(context['user'], None)
    def test_get_context_data_without_request_user_context(self):
        user = AnonymousUser()
        email_message = BaseEmailMessage(context={'user': user},
                                         template_name='text_mail.html')
        context = email_message.get_context_data()

        self.assertEquals(context['domain'], '')
        self.assertEquals(context['protocol'], 'http')
        self.assertEquals(context['site_name'], '')
        self.assertEquals(context['user'], user)
Exemple #4
0
def check_reminders(bms, reminder):
    try:
        event_code = bms.get_event_code(reminder.name,
                                        reminder.language,
                                        dimension=reminder.dimension)
        active_theaters = TheaterLink.objects.filter(reminder=reminder,
                                                     found=False)
        theaters = [link.theater for link in active_theaters]
        showtimes = bms.get_showtimes_by_venue(event_code, theaters,
                                               reminder.date)
        formatted_date = reminder.date.strftime("%a, %B %d %Y")
        formatted_shows = format_shows_list(showtimes)

        theaters_found = [show['venue'] for show in showtimes]
        if len(theaters_found) > 1:
            subject = f"{reminder.name} tickets out at {theaters_found[0].name} and more!"
        else:
            subject = f"{reminder.name} tickets out at {theaters_found[0].name}!"

        email = BaseEmailMessage(
            template_name='email_reminder.html',
            context={
                'subject': subject,
                'reminder': reminder,
                'formatted_date': formatted_date,
                'shows': formatted_shows,
            },
        )

        email.send(
            from_email=settings.DEFAULT_FROM_EMAIL,
            to=[reminder.user.email],
            reply_to=[settings.DEFAULT_REPLY_TO],
        )

        for theater in theaters_found:
            TheaterLink.objects.filter(reminder=reminder,
                                       theater=theater).update(
                                           found=True,
                                           found_at=timezone.localtime())

        if TheaterLink.objects.filter(reminder=reminder,
                                      found=False).count() == 0:
            reminder.completed = True
        reminder.save()
        logger.info("Hit on {}".format(str(reminder)))
    except BMSError as e:
        logger.info("Miss on {}. Reason: {}".format(str(reminder), e))
        reminder.save()
    def test_get_context_data_with_secure_request(self, is_secure_mock):
        is_secure_mock.return_value = True

        request = self.factory.get('/')
        request.user = AnonymousUser()

        email_message = BaseEmailMessage(request=request,
                                         template_name='text_mail.html')
        context = email_message.get_context_data()
        site = get_current_site(request)

        self.assertEquals(context['domain'], site.domain)
        self.assertEquals(context['protocol'], 'https')
        self.assertEquals(context['site_name'], site.name)
        self.assertEquals(context['user'], request.user)
def send_mail(template_name, recipients_email_list, context_dict=None):
    BaseEmailMessage(
        template_name=template_name,
        context=context_dict or {},
    ).send(
        to=recipients_email_list,
    )
    def test_mail_without_from_email_is_sent_with_valid_from_email(self):
        BaseEmailMessage(
            request=None,
            template_name='text_mail.html').send(to=self.recipients)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, self.recipients)
        self.assertEqual(mail.outbox[0].from_email, '*****@*****.**')
Exemple #8
0
def find_movies(task):
    region_code = task.city.code
    region_name = task.city.name
    key = task.movie_name
    language = task.movie_language
    dimension = task.movie_dimension
    date = task.movie_date
    formatted_date = date.strftime("%a, %B %d %Y")

    bms = BMS(region_code, region_name)
    
    try:
        showtimes = bms.get_showtimes(key, language, date, dimension)
        movie_url = bms.get_movie_url(key, language, date, dimension)
        shows = format_shows_list(showtimes)

        email = BaseEmailMessage(
                template_name='email.html',
                context={
                        'task': task,
                        'formatted_date': formatted_date,
                        'shows': shows,
                        'movie_url': movie_url,
                        },
        )

        email.send(
                from_email=settings.DEFAULT_FROM_EMAIL,
                to=[task.user.email],
                reply_to=[settings.DEFAULT_REPLY_TO],
        )

        task.task_completed = True
        task.save()
        logger.info("Hit on {}".format(str(task)))
    except BMSError as e:
        task.search_count += 1
        if task.search_count > config.SEARCH_COUNT_LIMIT:
            task.dropped = True
            logger.info("Dropping {}. Reason: {}".format(str(task), e))
        else:
            logger.info("Miss on {}. Reason: {}".format(str(task), e))
        task.save()
    def test_can_send_mail_with_none_request(self):
        BaseEmailMessage(
            request=None,
            template_name='text_mail.html').send(to=self.recipients)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
        self.assertEqual(mail.outbox[0].alternatives, [])
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
    def test_html_mail_contains_valid_data(self):
        request = self.factory.get('/')
        request.user = AnonymousUser()

        BaseEmailMessage(
            request=request,
            template_name='html_mail.html').send(to=self.recipients)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
        self.assertEqual(mail.outbox[0].subject, 'HTML mail subject')
        self.assertEqual(mail.outbox[0].body, '<p>Foobar email content</p>')
        self.assertEqual(mail.outbox[0].alternatives, [])
        self.assertEqual(mail.outbox[0].content_subtype, 'html')
    def test_mail_from_email_is_sent_with_valid_from_email(self):
        request = self.factory.get('/')
        request.user = AnonymousUser()

        from_email = '<Example - [email protected]>'

        BaseEmailMessage(request=request, template_name='text_mail.html').send(
            to=self.recipients, from_email=from_email)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, self.recipients)
        self.assertEqual(mail.outbox[0].from_email, from_email)
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
        self.assertEqual(mail.outbox[0].alternatives, [])
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
    def test_mail_bcc_is_sent_to_valid_bcc(self):
        request = self.factory.get('/')
        request.user = AnonymousUser()

        bcc = ['*****@*****.**']

        BaseEmailMessage(request=request, template_name='text_mail.html').send(
            to=self.recipients, bcc=bcc)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, self.recipients)
        self.assertEqual(mail.outbox[0].bcc, bcc)
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
        self.assertEqual(mail.outbox[0].alternatives, [])
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
Exemple #13
0
    def dispatch_message(self, *args, **kwargs):
        """
        Sends an email with verification code.
        :return:
        """

        code = self.create_code()

        BaseEmailMessage(
            context={
                'subject': self.EMAIL_SUBJECT,
                'text_body': code,
                'html_body': code,
            },
            template_name='email.html',
        ).send(
            to=[self.to],
            from_email=api_settings.FROM_EMAIL,
        )
        return {'message': _('Email message with MFA code had been sent.')}