Beispiel #1
0
    def test_wrong_smtp_credentials(self):
        with self.assertRaises(SendEmailError) as e:
            self.send(user="******")
        self.assertEquals(e.exception.args[0].smtp_code, 535)

        with self.assertRaises(SendEmailError) as e:
            smtp_send_email("*****@*****.**", "no credentials", "*****@*****.**", "body", port=self.port)
        self.assertEquals(e.exception.args[0].smtp_code, 530)
Beispiel #2
0
    def test_send_and_search(self):
        to = [("Rcpt1", "*****@*****.**"), ("Rcpt2", "*****@*****.**"),
              ("", "*****@*****.**")]
        emails = [t[1] for t in to]
        to = prepare_send_to_field(to)
        n = 3
        body_fmt = u"you you привет {}"
        subject_fmt = u"Test subject хэллоу {}"
        file_content = "file content"
        for i in range(n):
            smtp_send_email(to,
                            subject_fmt.format(i),
                            u"Me <*****@*****.**>",
                            body_fmt.format(i),
                            user=self.inbox,
                            password=self.password,
                            port=self.port,
                            emails=emails,
                            attachments=[(u"tасдest.txt", file_content)])
        res = self.get("/messages/").json
        self.assertEquals(res["message_count"], n)

        msg = res["message_list"][0]
        self.assertEquals(len(msg["parts"]), 2)
        self.assertEquals(msg["parts"][0]["body"], body_fmt.format(n - 1))
        self.assertEquals(msg["parts"][0]["is_attachment"], False)
        self.assertEquals(msg["parts"][1]["is_attachment"], True)
        self.assertIsNone(msg["parts"][1]["body"])

        def msg_count(params=None):
            return self.get("/messages/", params=params).json["message_count"]

        self.assertEquals(msg_count({"subject": subject_fmt.format(0)}), 1)
        self.assertEquals(msg_count({"subject_contains": "Test"}), n)
        self.assertEquals(msg_count({"subject_contains": "no such message"}),
                          0)

        before_send = utcnow()
        smtp_send_email("*****@*****.**",
                        "test",
                        "*****@*****.**",
                        "Hello",
                        user=self.inbox,
                        password=self.password,
                        port=self.port)

        self.assertEquals(msg_count({"recipients.address": emails[0]}), n)
        self.assertEquals(msg_count({"recipients.name": "Rcpt1"}), n)

        self.assertEquals(
            msg_count({"recipients.address": "*****@*****.**"}), 0)
        now = utcnow()
        self.assertEquals(msg_count({"created_at_lt": before_send}), n)
        self.assertEquals(msg_count({"created_at_gt": before_send}), 1)
        self.assertEquals(msg_count({"created_at_lt": now}), n + 1)
        self.assertEquals(msg_count({"created_at_gt": now}), 0)
Beispiel #3
0
 def test_binary_attach(self):
     binary_data = "%PDF\x93"
     smtp_send_email(
         "*****@*****.**", "Binary test", u"Test <*****@*****.**>", u"Text body да",
         user=self.inbox, password=self.password, port=self.port,
         attachments=[("filename.pd", binary_data)]
     )
     msg = self.get("/messages/").json["message_list"][0]
     self.assertEquals(self.get("/messages/{}/attachments/{}".format(msg["_id"], 1),
                                parse_json=False).data, binary_data)
Beispiel #4
0
    def test_wrong_smtp_credentials(self):
        with self.assertRaises(SendEmailError) as e:
            self.send(user="******")
        self.assertEquals(e.exception.args[0].smtp_code, 535)

        with self.assertRaises(SendEmailError) as e:
            smtp_send_email("*****@*****.**",
                            "no credentials",
                            "*****@*****.**",
                            "body",
                            port=self.port)
        self.assertEquals(e.exception.args[0].smtp_code, 530)
Beispiel #5
0
    def test_send_and_search(self):
        to_tuple = [("Rcpt1", "*****@*****.**"), ("Rcpt2", "*****@*****.**"), ("", "*****@*****.**")]
        emails = [t[1] for t in to_tuple]
        to = prepare_send_to_field(to_tuple)
        n = 3
        body_fmt = "you you привет {} \n\naaa\nbbb\n<a href='aaa'>zz</a>"
        subject_fmt = "Test subject хэллоу {}"
        file_content = "file content"
        sender_name = "Me"
        sender_addr = "*****@*****.**"

        for i in range(n):
            smtp_send_email(
                to, subject_fmt.format(i), "%s <%s>" % (sender_name, sender_addr), body_fmt.format(i),
                user=self.inbox, password=self.password, port=self.port, emails=emails,
                attachments=[("tасдest.txt", file_content)]
            )
        res = self.get("/messages/").json
        self.assertEquals(res["message_count"], n)

        msg = res["message_list"][0]
        self.assertEquals(len(msg["parts"]), 2)
        self.assertEquals(msg["parts"][0]["body"], body_fmt.format(n - 1))
        self.assertEquals(msg["parts"][0]["is_attachment"], False)
        self.assertEquals(msg["parts"][1]["is_attachment"], True)
        self.assertIsNone(msg["parts"][1]["body"])
        self.assertEquals(len(msg["recipients"]), len(to_tuple))
        self.assertEquals([(rcpt["name"], rcpt["address"]) for rcpt in msg["recipients"]], to_tuple)
        self.assertEquals(msg["sender"]["name"], sender_name)
        self.assertEquals(msg["sender"]["address"], sender_addr)

        def msg_count(params=None):
            return self.get("/messages/", params=params).json["message_count"]

        self.assertEquals(msg_count({"subject": subject_fmt.format(0)}), 1)
        self.assertEquals(msg_count({"subject_contains": "Test"}), n)
        self.assertEquals(msg_count({"subject_contains": "no such message"}), 0)

        before_send = utcnow()
        smtp_send_email("*****@*****.**", "test", "*****@*****.**", "Hello",
                        user=self.inbox, password=self.password, port=self.port)

        self.assertEquals(msg_count({"recipients.address": emails[0]}), n)
        self.assertEquals(msg_count({"recipients.name": "Rcpt1"}), n)

        self.assertEquals(msg_count({"recipients.address": "*****@*****.**"}), 0)
        now = utcnow()
        self.assertEquals(msg_count({"created_at_lt": before_send}), n)
        self.assertEquals(msg_count({"created_at_gt": before_send}), 1)
        self.assertEquals(msg_count({"created_at_lt": now}), n + 1)
        self.assertEquals(msg_count({"created_at_gt": now}), 0)
Beispiel #6
0
 def test_binary_attach(self):
     binary_data = b"%PDF\x93"
     smtp_send_email("*****@*****.**",
                     "Binary test",
                     "Test <*****@*****.**>",
                     "Text body да",
                     user=self.inbox,
                     password=self.password,
                     port=self.port,
                     attachments=[("filename.pd", binary_data)])
     msg = self.get("/messages/").json["message_list"][0]
     self.assertEquals(
         self.get("/messages/{}/attachments/{}".format(msg["_id"], 1),
                  parse_json=False).data, binary_data)
Beispiel #7
0
 def test_html_alternative_and_attach(self):
     binary_data = b"%PDF\x93"
     html_body = "<html><body><h1>hello</h1></body></html>"
     text_body = "Text body да"
     smtp_send_email(
         "*****@*****.**", "Binary test", "Test <*****@*****.**>", text_body,
         user=self.inbox, password=self.password, port=self.port,
         attachments=[("filename.pd", binary_data)],
         html_body=html_body
     )
     msg = self.get("/messages/").json["message_list"][0]
     self.assertEqual(len(msg["parts"]), 3)
     self.assertEqual(msg["parts"][0]["body"], text_body)
     self.assertEqual(msg["parts"][1]["body"], html_body)
     self.assertIsNone(msg["parts"][2]["body"])
     self.assertEquals(self.get("/messages/{}/attachments/{}".format(msg["_id"], 2),
                                parse_json=False).data, binary_data)
Beispiel #8
0
 def test_html_alternative_and_attach(self):
     binary_data = b"%PDF\x93"
     html_body = "<html><body><h1>hello</h1></body></html>"
     text_body = "Text body да"
     smtp_send_email("*****@*****.**",
                     "Binary test",
                     "Test <*****@*****.**>",
                     text_body,
                     user=self.inbox,
                     password=self.password,
                     port=self.port,
                     attachments=[("filename.pd", binary_data)],
                     html_body=html_body)
     msg = self.get("/messages/").json["message_list"][0]
     self.assertEqual(len(msg["parts"]), 3)
     self.assertEqual(msg["parts"][0]["body"], text_body)
     self.assertEqual(msg["parts"][1]["body"], html_body)
     self.assertIsNone(msg["parts"][2]["body"])
     self.assertEquals(
         self.get("/messages/{}/attachments/{}".format(msg["_id"], 2),
                  parse_json=False).data, binary_data)
Beispiel #9
0
    def test_send_and_search(self):
        to_tuple = [("Rcpt1", "*****@*****.**"),
                    ("Rcpt2", "*****@*****.**"), ("", "*****@*****.**")]
        emails = [t[1] for t in to_tuple]
        to = prepare_send_to_field(to_tuple)
        n = 3
        body_fmt = "you you привет {} \n\naaa\nbbb\n<a href='aaa'>zz</a>"
        subject_fmt = "Test subject хэллоу {}"
        file_content = "file content"
        sender_name = "Me"
        sender_addr = "*****@*****.**"

        for i in range(n):
            smtp_send_email(to,
                            subject_fmt.format(i),
                            "%s <%s>" % (sender_name, sender_addr),
                            body_fmt.format(i),
                            user=self.inbox,
                            password=self.password,
                            port=self.port,
                            emails=emails,
                            attachments=[("tасдest.txt", file_content)])
        res = self.get("/messages/").json
        self.assertEquals(res["message_count"], n)

        msg = res["message_list"][0]
        self.assertEquals(len(msg["parts"]), 2)
        self.assertEquals(msg["parts"][0]["body"], body_fmt.format(n - 1))
        self.assertEquals(msg["parts"][0]["is_attachment"], False)
        self.assertEquals(msg["parts"][1]["is_attachment"], True)
        self.assertIsNone(msg["parts"][1]["body"])
        self.assertEquals(len(msg["recipients"]), len(to_tuple))
        self.assertEquals([(rcpt["name"], rcpt["address"])
                           for rcpt in msg["recipients"]], to_tuple)
        self.assertEquals(msg["sender"]["name"], sender_name)
        self.assertEquals(msg["sender"]["address"], sender_addr)

        def msg_count(params=None):
            return self.get("/messages/", params=params).json["message_count"]

        self.assertEquals(msg_count({"subject": subject_fmt.format(0)}), 1)
        self.assertEquals(msg_count({"subject_contains": "Test"}), n)
        self.assertEquals(msg_count({"subject_contains": "no such message"}),
                          0)

        before_send = utcnow()
        smtp_send_email("*****@*****.**",
                        "wwwww",
                        "*****@*****.**",
                        "wwwwwwww",
                        user=self.inbox,
                        password=self.password,
                        port=self.port)

        self.assertEquals(msg_count({"recipients.address": emails[0]}), n)
        self.assertEquals(
            msg_count({"recipients.address": "*****@*****.**"}), 0)
        self.assertEquals(
            msg_count({"recipients.address_contains": emails[0][3:]}), n)
        self.assertEquals(
            msg_count({"recipients.address_contains": emails[0][:3]}), n)
        self.assertEquals(msg_count({"recipients.name": "Rcpt1"}), n)
        self.assertEquals(msg_count({"recipients.name": "Rcpt"}), 0)
        self.assertEquals(msg_count({"recipients.name_contains": "Rcpt"}), n)
        self.assertEquals(msg_count({"sender.name": sender_name}), n)
        self.assertEquals(msg_count({"sender.name": "unknown"}), 0)
        self.assertEquals(msg_count({"sender.name": sender_name[0]}), 0)
        self.assertEquals(msg_count({"sender.name_contains": sender_name[0]}),
                          n)
        self.assertEquals(msg_count({"sender.name_contains": sender_name[-1]}),
                          n)
        self.assertEquals(msg_count({"sender.address": sender_addr}), n)
        self.assertEquals(msg_count({"sender.address": sender_addr[0]}), 0)
        self.assertEquals(
            msg_count({"sender.address_contains": sender_addr[0]}), n)
        self.assertEquals(
            msg_count({"sender.address_contains": sender_addr[-1]}), n)

        now = utcnow()
        self.assertEquals(msg_count({"created_at_lt": before_send}), n)
        self.assertEquals(msg_count({"created_at_gt": before_send}), 1)
        self.assertEquals(msg_count({"created_at_lt": now}), n + 1)
        self.assertEquals(msg_count({"created_at_gt": now}), 0)