<commit_before># Copyright 2013 <NAME>
# All rights reserved
#
# Author: <NAME> - <EMAIL>
#

from django.contrib.auth.models import User
from django.template import Context
from django.template.loader import get_template
from mock import call, patch, Mock
import unittest

from unchained import format_cents, send_html_email, UsernameOrEmailBackend


class SendHtmlEmailTest(unittest.TestCase):

    @patch('unchained.EmailMultiAlternatives')
    def test_renders_to_correct_templates_and_then_delegates(
            self, mockEmail
    ):

        subject = 'I am subject'
        sender = '<EMAIL>'
        recipients = ['<EMAIL>']
        msg = Mock()
        mockEmail.return_value = msg
        email_context = {'some': 'random context'}

        send_html_email(
            subject, 'confirm_email', sender, recipients, email_context
        )

        email_txt = get_template('confirm_email.txt').render(Context(email_context))
        email_html = get_template('confirm_email.html').render(Context(email_context))

        self.assertEqual(msg.attach_alternative.call_args_list,
            [call(email_html, 'text/html')]
        )

        self.assertEqual(mockEmail.call_args_list,
            [call(subject, email_txt, sender, recipients)]
        )


class FormatCentsTest(unittest.TestCase):

    def test_format_cents(self):<commit_msg>Allow the importing tests to override the default email templates<commit_after># Copyright 2013 <NAME>
# All rights reserved
#
# Author: <NAME> - <EMAIL>
#

from django.contrib.auth.models import User
from django.template import Context
from django.template.loader import get_template
from mock import call, patch, Mock
import unittest

from unchained import format_cents, send_html_email, UsernameOrEmailBackend


class SendHtmlEmailTest(unittest.TestCase):

    html_template = 'confirm_email.html'
    txt_template = 'confirm_email.txt'

    @patch('unchained.EmailMultiAlternatives')
    def test_renders_to_correct_templates_and_then_delegates(
            self, mockEmail
    ):

        subject = 'I am subject'
        sender = '<EMAIL>'
        recipients = ['<EMAIL>']
        msg = Mock()
        mockEmail.return_value = msg
        email_context = {'some': 'random context'}

        send_html_email(
            subject, 'confirm_email', sender, recipients, email_context
        )

        email_txt = get_template(self.txt_template).render(Context(email_context))
        email_html = get_template(self.html_template).render(Context(email_context))

        self.assertEqual(msg.attach_alternative.call_args_list,
            [call(email_html, 'text/html')]
        )

        self.assertEqual(mockEmail.call_args_list,
            [call(subject, email_txt, sender, recipients)]
        )


class FormatCentsTest(unittest.TestCase):

    def test_format_cents(self):
{'fraction_non_alphanumeric': 0.09382716049382717, 'fraction_numerical': 0.0028218694885361554, 'mean_word_length': 3.424336973478939, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1646515', 'n_tokens_mistral': 838, 'n_tokens_neox': 803, 'n_words': 174}