<commit_before>from django.test import TestCase
from mail_draft.mailer import generate_message
from mail_draft.dds_util import DDSUtil

class MailerTestCase(TestCase):

    def testGenerateMessage(self):
        sender_email = '<EMAIL>'
        rcpt_email = '<EMAIL>'
        subject = 'Data is ready'
        template_name = 'draft.txt'
        context = {
            'order_number': 12345,
            'project_name': 'Project ABC',
            'status' : 'Draft',
            'contents' : '12 folders, 3 files',
            'recipient_name': '<NAME>',
            'sender_name': '<NAME>',
            'sender_email': sender_email,
            'data_url': 'http://domain.com/data',
            'signature': 'Sender Co\n123Fake St\nAnytown WA 90909',
        }
        message = generate_message(sender_email, rcpt_email, subject, template_name, context)
        self.assertIn('Sender Name has sent you a data set, which can be previewed at http://domain.com/data.', message.body)
        self.assertIn('Contents: 12 folders, 3 files', message.body)
        self.assertIn('please contact <EMAIL>', message.body)
        self.assertEqual(sender_email, message.from_email)
        self.assertIn(rcpt_email, message.to)

class DDSUtilTestCase(TestCase):

    def testGetEmail(self):
        from handover_api.models import User

        # Requires user with an API key
        dds_id = 'abcd-1234-efgh-9696'
        User.objects.create(dds_id=dds_id, api_key='<KEY>')
        with self.settings(DDSCLIENT_PROPERTIES={}):
            dds_util = DDSUtil(dds_id)
            email_address = dds_util.get_email_address(dds_id)
            self.assertEqual(email_address, '<EMAIL>')

<commit_msg>Test case for DDSUtil get email<commit_after>from django.test import TestCase
from mail_draft.mailer import generate_message
from handover_api.models import User
import mock

class MailerTestCase(TestCase):

    def testGenerateMessage(self):
        sender_email = '<EMAIL>'
        rcpt_email = '<EMAIL>'
        subject = 'Data is ready'
        template_name = 'draft.txt'
        context = {
            'order_number': 12345,
            'project_name': 'Project ABC',
            'status' : 'Draft',
            'contents' : '12 folders, 3 files',
            'recipient_name': '<NAME>',
            'sender_name': '<NAME>',
            'sender_email': sender_email,
            'data_url': 'http://domain.com/data',
            'signature': 'Sender Co\n123Fake St\nAnytown WA 90909',
        }
        message = generate_message(sender_email, rcpt_email, subject, template_name, context)
        self.assertIn('Sender Name has sent you a data set, which can be previewed at http://domain.com/data.', message.body)
        self.assertIn('Contents: 12 folders, 3 files', message.body)
        self.assertIn('please contact <EMAIL>', message.body)
        self.assertEqual(sender_email, message.from_email)
        self.assertIn(rcpt_email, message.to)


class DDSUtilTestCase(TestCase):
    @mock.patch('ddsc.core.remotestore.RemoteStore')
    def testGetEmail(self, mockRemoteStore):
        user_id = 'abcd-1234-efgh-8876'
        email = '<EMAIL>'
        # Mock a remote user object, and bind it to fetch_user
        remote_user = mock.Mock()
        remote_user.email = email
        instance = mockRemoteStore.return_value
        instance.fetch_user.return_value = remote_user
        # Only import DDSUtil once we've patched RemoteStore
        from dds_util import DDSUtil
        User.objects.create(dds_id=user_id, api_key='<KEY>')
        with self.settings(DDSCLIENT_PROPERTIES={}):
            dds_util = DDSUtil(user_id)
            self.assertEqual(email, dds_util.get_email_address(user_id))
{'fraction_non_alphanumeric': 0.10877192982456141, 'fraction_numerical': 0.014574898785425101, 'mean_word_length': 2.739656912209889, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3293041', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1109, 'n_words': 256}