Ejemplo n.º 1
0
    def test_01_enqueue_email(self):
        r = add_smtpserver(identifier="myserver",
                           server="1.2.3.4",
                           tls=False,
                           enqueue_job=True)
        self.assertTrue(r > 0)

        server = get_smtpserver("myserver")
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)

        queue = get_job_queue()
        self.assertEqual(len(queue.enqueued_jobs), 1)
        job_name, args, kwargs = queue.enqueued_jobs[0]
        self.assertEqual(job_name, "smtpserver.send_email")
        self.assertEqual(args[1], ["*****@*****.**"])
        self.assertEqual(args[2], "Hallo")
        self.assertEqual(args[3], "Body")

        # send_email returns True, even if the SMTP server will eventually reject the message
        smtpmock.setdata(
            response={"*****@*****.**": (550, "Message rejected")},
            support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)
        self.assertEqual(len(queue.enqueued_jobs), 2)
        job_name, args, kwargs = queue.enqueued_jobs[1]
        self.assertEqual(job_name, "smtpserver.send_email")
        self.assertEqual(args[1], ["*****@*****.**"])
        self.assertEqual(args[2], "Hallo")
        self.assertEqual(args[3], "Body")

        delete_smtpserver("myserver")
Ejemplo n.º 2
0
    def test_01_enqueue_email(self):
        r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=False, enqueue_job=True)
        self.assertTrue(r > 0)

        server = get_smtpserver("myserver")
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)

        queue = get_job_queue()
        self.assertEqual(len(queue.enqueued_jobs), 1)
        job_name, args, kwargs = queue.enqueued_jobs[0]
        self.assertEqual(job_name, "smtpserver.send_email")
        self.assertEqual(args[1], ["*****@*****.**"])
        self.assertEqual(args[2], "Hallo")
        self.assertEqual(args[3], "Body")

        # send_email returns True, even if the SMTP server will eventually reject the message
        smtpmock.setdata(response={"*****@*****.**": (550,
                                                        "Message rejected")},
                         support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)
        self.assertEqual(len(queue.enqueued_jobs), 2)
        job_name, args, kwargs = queue.enqueued_jobs[1]
        self.assertEqual(job_name, "smtpserver.send_email")
        self.assertEqual(args[1], ["*****@*****.**"])
        self.assertEqual(args[2], "Hallo")
        self.assertEqual(args[3], "Body")

        delete_smtpserver("myserver")
Ejemplo n.º 3
0
    def test_03_enqueue_jobs(self):
        queue = get_job_queue()
        queue.enqueue("test.my_add", (3, 4), {})  # No result is stored

        with mock.patch.object(SENDER, 'send_mail') as mock_mail:
            queue.enqueue("test.my_send_mail", ("hi", ), {})
            mock_mail.assert_called_once_with("hi")

        with self.assertRaises(QueueError):
            queue.enqueue("test.unknown", ("hi", ), {})
Ejemplo n.º 4
0
    def test_03_enqueue_jobs(self):
        queue = get_job_queue()
        queue.enqueue("test.my_add", (3, 4), {}) # No result is stored

        with mock.patch.object(SENDER, 'send_mail') as mock_mail:
            queue.enqueue("test.my_send_mail", ("hi",), {})
            mock_mail.assert_called_once_with("hi")

        with self.assertRaises(QueueError):
            queue.enqueue("test.unknown", ("hi",), {})
Ejemplo n.º 5
0
 def test_01_app_job_queue(self):
     queue = get_job_queue()
     self.assertIsInstance(queue, HueyQueue)
     self.assertEqual(queue.options, {"name": "myqueuename", "always_eager": True})
     self.assertTrue({"test.my_add", "test.my_send_mail"}.issubset(set(queue.jobs)))
     self.assertIsInstance(queue.huey, RedisHuey)
     self.assertEqual(queue.huey.name, "myqueuename")
     self.assertFalse(queue.huey.store_none)
     with self.assertRaises(QueueError):
         queue.register_job("test.my_add", lambda x: x)
Ejemplo n.º 6
0
 def test_01_app_job_queue(self):
     queue = get_job_queue()
     self.assertIsInstance(queue, HueyQueue)
     self.assertEqual(queue.options, {
         "name": "myqueuename",
         "always_eager": True
     })
     self.assertTrue({"test.my_add",
                      "test.my_send_mail"}.issubset(set(queue.jobs)))
     self.assertIsInstance(queue.huey, RedisHuey)
     self.assertEqual(queue.huey.name, "myqueuename")
     self.assertFalse(queue.huey.store_none)
     with self.assertRaises(QueueError):
         queue.register_job("test.my_add", lambda x: x)
Ejemplo n.º 7
0
    def test_02_send_email_without_queue(self):
        # enqueue_job is False!
        r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=False)
        self.assertTrue(r > 0)

        server = get_smtpserver("myserver")
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)

        smtpmock.setdata(response={"*****@*****.**": (550,
                                                        "Message rejected")},
                         support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, False)

        # Use TLS
        r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=True)
        self.assertTrue(r > 0)
        server = get_smtpserver("myserver")
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=True)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)

        # If we configure TLS but the server does not support this, we raise
        # an error
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=False)
        self.assertRaises(SMTPException, server.send_email,
                          ["*****@*****.**"], "Hallo", "Body")

        # Assert that no
        queue = get_job_queue()
        self.assertEqual(queue.enqueued_jobs, [])

        delete_smtpserver("myserver")
Ejemplo n.º 8
0
    def test_02_send_email_without_queue(self):
        # enqueue_job is False!
        r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=False)
        self.assertTrue(r > 0)

        server = get_smtpserver("myserver")
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)

        smtpmock.setdata(
            response={"*****@*****.**": (550, "Message rejected")},
            support_tls=False)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, False)

        # Use TLS
        r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=True)
        self.assertTrue(r > 0)
        server = get_smtpserver("myserver")
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=True)
        r = server.send_email(["*****@*****.**"], "Hallo", "Body")
        self.assertEqual(r, True)

        # If we configure TLS but the server does not support this, we raise
        # an error
        smtpmock.setdata(response={"*****@*****.**": (200, "OK")},
                         support_tls=False)
        self.assertRaises(SMTPException, server.send_email,
                          ["*****@*****.**"], "Hallo", "Body")

        # Assert that no
        queue = get_job_queue()
        self.assertEqual(queue.enqueued_jobs, [])

        delete_smtpserver("myserver")
Ejemplo n.º 9
0
 def test_01_no_job_queue(self):
     self.assertFalse(has_job_queue())
     with self.assertRaises(ServerError):
         get_job_queue()
Ejemplo n.º 10
0
 def test_01_no_job_queue(self):
     self.assertFalse(has_job_queue())
     with self.assertRaises(ServerError):
         get_job_queue()
Ejemplo n.º 11
0
 def setUp(self):
     get_job_queue().reset()
     OverrideConfigTestCase.setUp(self)