Пример #1
0
    def test_format_assigned_offer_no_greeting(self):
        """
        Test that the assigned offer email message is formatted correctly if there is no greeting or closing.
        """
        code = 'ABC7RUEOU7VHBH7Q'
        placeholder_dict = SafeDict(
            REDEMPTIONS_REMAINING=499,
            USER_EMAIL='*****@*****.**',
            CODE=code,
            EXPIRATION_DATE='2018-12-19',
        )
        email = format_email(self._BROKEN_EMAIL_TEMPLATE, placeholder_dict,
                             None, None)
        self.assertIn('{DOES_NOT_EXIST}', email)
        self.assertIn(code, email)

        # Compare strings, ignoring whitespace differences
        expected_email = """
            <br/> Text<br/>
            {DOES_NOT_EXIST} [email protected]<br/>
            code: ABC7RUEOU7VHBH7Q ABC7RUEOU7VHBH7Q<br/>
            {}<br/>
            { abc d }<br/>
            More text.<br/>
            """
        self.assertEqual(email.split(), expected_email.split())
Пример #2
0
    def test_format_assigned_offer_broken_email(self):
        """
        Test that the assigned offer email message is formatted correctly if the template is broken.
        """
        greeting = 'hi {CODE} <h1>there</h1>\n'
        closing = '\nbye {CODE}, <h3>come back soon!</h3>'
        code = 'GIL7RUEOU7VHBH7Q'
        placeholder_dict = SafeDict(
            REDEMPTIONS_REMAINING=500,
            USER_EMAIL='*****@*****.**',
            CODE=code,
            EXPIRATION_DATE='2018-12-19',
        )
        email = format_email(self._BROKEN_EMAIL_TEMPLATE, placeholder_dict,
                             greeting, closing)
        self.assertIn('{DOES_NOT_EXIST}', email)
        self.assertIn(code, email)

        # Compare strings, ignoring whitespace differences
        expected_email = """
            hi {CODE} &lt;h1&gt;there&lt;/h1&gt;<br/><br/>
            Text<br/>
            {DOES_NOT_EXIST} [email protected]<br/>
            code: GIL7RUEOU7VHBH7Q GIL7RUEOU7VHBH7Q<br/>
            {}<br/>
            { abc d }<br/>
            More text.<br/> <br/>bye {CODE}, &lt;h3&gt;come back soon!&lt;/h3&gt;
            """
        self.assertEqual(email.split(), expected_email.split())
Пример #3
0
    def test_format_assigned_offer_broken_email(self):
        """
        Test that the assigned offer email message is formatted correctly if the template is broken.
        """
        greeting = 'hi {CODE} '
        closing = ' bye {CODE}'
        code = 'GIL7RUEOU7VHBH7Q'
        placeholder_dict = SafeDict(
            REDEMPTIONS_REMAINING=500,
            USER_EMAIL='*****@*****.**',
            CODE=code,
            EXPIRATION_DATE='2018-12-19',
        )
        email = format_email(self._BROKEN_EMAIL_TEMPLATE, placeholder_dict,
                             greeting, closing)
        self.assertIn('{DOES_NOT_EXIST}', email)
        self.assertIn(code, email)

        # Compare strings, ignoring whitespace differences
        expected_email = """
            hi {CODE} Text
            {DOES_NOT_EXIST} [email protected]
            code: GIL7RUEOU7VHBH7Q GIL7RUEOU7VHBH7Q
            {}
            { abc d }
            More text. bye {CODE}
            """
        self.assertEqual(email.split(), expected_email.split())
Пример #4
0
 def test_format_assigned_offer_email(
     self,
     template,
     greeting,
     closing,
     tokens,
 ):
     """
     Test that the assigned offer email message is formatted correctly.
     """
     placeholder_dict = SafeDict(
         REDEMPTIONS_REMAINING=tokens.get('redemptions_remaining'),
         USER_EMAIL=tokens.get('learner_email'),
         CODE=tokens.get('code'),
         EXPIRATION_DATE=tokens.get('code_expiration_date'),
     )
     email = format_email(template, placeholder_dict, greeting, closing)
     self.assertIn(str(tokens.get('redemptions_remaining')), email)
     self.assertIn(tokens.get('learner_email'), email)
     self.assertIn(tokens.get('code'), email)
     self.assertIn(tokens.get('code_expiration_date'), email)
     self.assertIn(greeting, email)
     self.assertIn(closing, email)