Пример #1
0
def test_send_email():
    util._clear_test_inboxes()

    # send the email
    util.send_email(
        "*****@*****.**",
        ["*****@*****.**", "*****@*****.**"], "Testing is so much fun!",
        """HAYYY GUYS!

I hope you like unit tests JUST AS MUCH AS I DO!""")

    # check the main inbox
    assert len(util.EMAIL_TEST_INBOX) == 1
    message = util.EMAIL_TEST_INBOX.pop()
    assert message['From'] == "*****@*****.**"
    assert message['To'] == "[email protected], [email protected]"
    assert message['Subject'] == "Testing is so much fun!"
    assert message.get_payload() == """HAYYY GUYS!

I hope you like unit tests JUST AS MUCH AS I DO!"""

    # Check everything that the FakeMhost.sendmail() method got is correct
    assert len(util.EMAIL_TEST_MBOX_INBOX) == 1
    mbox_dict = util.EMAIL_TEST_MBOX_INBOX.pop()
    assert mbox_dict['from'] == "*****@*****.**"
    assert mbox_dict['to'] == ["*****@*****.**", "*****@*****.**"]
    mbox_message = email.message_from_string(mbox_dict['message'])
    assert mbox_message['From'] == "*****@*****.**"
    assert mbox_message['To'] == "[email protected], [email protected]"
    assert mbox_message['Subject'] == "Testing is so much fun!"
    assert mbox_message.get_payload() == """HAYYY GUYS!
Пример #2
0
def test_send_email():
    util._clear_test_inboxes()

    # send the email
    util.send_email(
        "*****@*****.**",
        ["*****@*****.**", "*****@*****.**"],
        "Testing is so much fun!",
        """HAYYY GUYS!

I hope you like unit tests JUST AS MUCH AS I DO!""")

    # check the main inbox
    assert len(util.EMAIL_TEST_INBOX) == 1
    message = util.EMAIL_TEST_INBOX.pop()
    assert message['From'] == "*****@*****.**"
    assert message['To'] == "[email protected], [email protected]"
    assert message['Subject'] == "Testing is so much fun!"
    assert message.get_payload() == """HAYYY GUYS!

I hope you like unit tests JUST AS MUCH AS I DO!"""

    # Check everything that the FakeMhost.sendmail() method got is correct
    assert len(util.EMAIL_TEST_MBOX_INBOX) == 1
    mbox_dict = util.EMAIL_TEST_MBOX_INBOX.pop()
    assert mbox_dict['from'] == "*****@*****.**"
    assert mbox_dict['to'] == ["*****@*****.**", "*****@*****.**"]
    mbox_message = email.message_from_string(mbox_dict['message'])
    assert mbox_message['From'] == "*****@*****.**"
    assert mbox_message['To'] == "[email protected], [email protected]"
    assert mbox_message['Subject'] == "Testing is so much fun!"
    assert mbox_message.get_payload() == """HAYYY GUYS!
Пример #3
0
def test_send_license_info_email():
    util._clear_test_inboxes()

    util.send_license_info_email(
        'Creative Commons Very-Silly License 5.8',
        SILLY_LICENSE_HTML,
        '*****@*****.**', 'en')

    assert len(util.EMAIL_TEST_INBOX) == 1
    message = util.EMAIL_TEST_INBOX.pop()
    assert message['From'] == "*****@*****.**"
    assert message['To'] == "*****@*****.**"
    assert message['Subject'] == "Your Creative Commons License Information"
    
    normal_payload = """Thank you for using a Creative Commons legal tool for your work.

You have selected Creative Commons Very-Silly License 5.8.
You should include a reference to this on the web page that includes
the work in question.

Here is the suggested HTML:

This work available under a
<a href="http://example.org/goes/nowhere">very silly license</a>.

Tips for marking your work can be found at
http://wiki.creativecommons.org/Marking.  Information on the supplied HTML and
metadata can be found at http://wiki.creativecommons.org/CC_REL.

This email and tech support has been brought to you by the nonprofit folks at
Creative Commons. CC relies on donations to provide you with licenses and
services like this. Please consider a donation to our annual fund:
https://creativecommons.net/donate.

Thank you!
Creative Commons Support
[email protected]"""
    campaign_payload = """Thank you for using a Creative Commons legal tool for your work.\n\nYou have selected Creative Commons Very-Silly License 5.8.\nYou should include a reference to this on the web page that includes\nthe work in question.\n\nHere is the suggested HTML:\n\nThis work available under a\n<a href="http://example.org/goes/nowhere">very silly license</a>.\n\nTips for marking your work can be found at\nhttp://wiki.creativecommons.org/Marking.  Information on the supplied HTML and\nmetadata can be found at http://wiki.creativecommons.org/CC_REL.\n\nThis email and tech support has been brought to you by the nonprofit folks at\nCreative Commons. CC relies on donations to provide you with licenses and\nservices like this. Please consider a donation to our annual fund:\nhttps://creativecommons.net/donate.\n\nThank you!\nCreative Commons Support\[email protected]"""

    assert message.get_payload() in [normal_payload, campaign_payload]
Пример #4
0
    def test_cc0_results_email_send(self):
        util._clear_test_template_context()
        # For doing a POST (email sending time!)
        # --------------------------------------
        response = TESTAPP.post(
            '/choose/zero/results',
            {'email': '*****@*****.**'})

        # assert that there's 1 message in the inbox,
        # and that it's the right one
        assert_equal(len(util.EMAIL_TEST_INBOX), 1)
        sent_mail = util.EMAIL_TEST_INBOX.pop()
        assert_equal(sent_mail['To'], '*****@*****.**')
        assert_equal(sent_mail['From'], '*****@*****.**')
        assert_equal(
            sent_mail['Subject'],
            "Your Creative Commons License Information")
        mail_body = sent_mail.get_payload()

        assert 'You have selected CC0 1.0 Universal' in mail_body
        assert 'To the extent possible under law,' in mail_body

        # check that the right template was loaded
        assert util.TEST_TEMPLATE_CONTEXT.has_key(
            'chooser_pages/zero/results.html')

        # For doing a GET (shouldn't send email!)
        # ---------------------------------------
        util._clear_test_inboxes()
        util._clear_test_template_context()

        response = TESTAPP.get(
            '/choose/zero/[email protected]')

        # assert that there's no messages in the inbox
        assert_equal(len(util.EMAIL_TEST_INBOX), 0)

        # check that the right template was loaded
        assert util.TEST_TEMPLATE_CONTEXT.has_key(
            'chooser_pages/zero/results.html')
Пример #5
0
def test_send_license_info_email():
    util._clear_test_inboxes()

    util.send_license_info_email('Creative Commons Very-Silly License 5.8',
                                 SILLY_LICENSE_HTML,
                                 '*****@*****.**', 'en')

    assert len(util.EMAIL_TEST_INBOX) == 1
    message = util.EMAIL_TEST_INBOX.pop()
    assert message['From'] == "*****@*****.**"
    assert message['To'] == "*****@*****.**"
    assert message['Subject'] == "Your Creative Commons License Information"

    normal_payload = """Thank you for using a Creative Commons legal tool for your work.

You have selected Creative Commons Very-Silly License 5.8.
You should include a reference to this on the web page that includes
the work in question.

Here is the suggested HTML:

This work available under a
<a href="http://example.org/goes/nowhere">very silly license</a>.

Tips for marking your work can be found at
http://wiki.creativecommons.org/Marking.  Information on the supplied HTML and
metadata can be found at http://wiki.creativecommons.org/CC_REL.

This email and tech support has been brought to you by the nonprofit folks at
Creative Commons. CC relies on donations to provide you with licenses and
services like this. Please consider a donation to our annual fund:
https://creativecommons.net/donate.

Thank you!
Creative Commons Support
[email protected]"""
    campaign_payload = """Thank you for using a Creative Commons legal tool for your work.\n\nYou have selected Creative Commons Very-Silly License 5.8.\nYou should include a reference to this on the web page that includes\nthe work in question.\n\nHere is the suggested HTML:\n\nThis work available under a\n<a href="http://example.org/goes/nowhere">very silly license</a>.\n\nTips for marking your work can be found at\nhttp://wiki.creativecommons.org/Marking.  Information on the supplied HTML and\nmetadata can be found at http://wiki.creativecommons.org/CC_REL.\n\nThis email and tech support has been brought to you by the nonprofit folks at\nCreative Commons. CC relies on donations to provide you with licenses and\nservices like this. Please consider a donation to our annual fund:\nhttps://creativecommons.net/donate.\n\nThank you!\nCreative Commons Support\[email protected]"""

    assert message.get_payload() in [normal_payload, campaign_payload]
Пример #6
0
    def test_cc0_results_email_send(self):
        util._clear_test_template_context()
        # For doing a POST (email sending time!)
        # --------------------------------------
        response = TESTAPP.post('/choose/zero/results',
                                {'email': '*****@*****.**'})

        # assert that there's 1 message in the inbox,
        # and that it's the right one
        assert_equal(len(util.EMAIL_TEST_INBOX), 1)
        sent_mail = util.EMAIL_TEST_INBOX.pop()
        assert_equal(sent_mail['To'], '*****@*****.**')
        assert_equal(sent_mail['From'], '*****@*****.**')
        assert_equal(sent_mail['Subject'],
                     "Your Creative Commons License Information")
        mail_body = sent_mail.get_payload()

        assert 'You have selected CC0 1.0 Universal' in mail_body
        assert 'To the extent possible under law,' in mail_body

        # check that the right template was loaded
        assert util.TEST_TEMPLATE_CONTEXT.has_key(
            'chooser_pages/zero/results.html')

        # For doing a GET (shouldn't send email!)
        # ---------------------------------------
        util._clear_test_inboxes()
        util._clear_test_template_context()

        response = TESTAPP.get(
            '/choose/zero/[email protected]')

        # assert that there's no messages in the inbox
        assert_equal(len(util.EMAIL_TEST_INBOX), 0)

        # check that the right template was loaded
        assert util.TEST_TEMPLATE_CONTEXT.has_key(
            'chooser_pages/zero/results.html')
Пример #7
0
 def setUp(self):
     util._clear_test_inboxes()
     util._clear_test_template_context()
Пример #8
0
 def setUp(self):
     util._clear_test_inboxes()
     util._clear_test_template_context()