aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--budget/tests.py77
1 files changed, 52 insertions, 25 deletions
diff --git a/budget/tests.py b/budget/tests.py
index 6e365bd..b79f16f 100644
--- a/budget/tests.py
+++ b/budget/tests.py
@@ -9,19 +9,24 @@ import models
class BudgetTestCase(unittest.TestCase):
- def test_notifications(self):
- """Test that the notifications are sent, and that email adresses
- are checked properly.
- """
- # create a project
- self.create_project("raclette")
+ def setUp(self):
+ web.app.config['TESTING'] = True
- with web.app.test_client() as c:
- self.login("raclette", test_client=c)
- result = c.post("/raclette/invite",
- data={"emails": 'test@test.com'})
- # check here that the mails are sent.
+ self.fd, self.fp = tempfile.mkstemp()
+ web.app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///%s" % self.fp
+ web.app.config['CSRF_ENABLED'] = False # simplify the tests
+ self.app = web.app.test_client()
+ models.db.init_app(web.app)
+ web.mail.init_app(web.app)
+
+ models.db.app = web.app
+ models.db.create_all()
+
+ def tearDown(self):
+ # clean after testing
+ os.close(self.fd)
+ os.unlink(self.fp)
def login(self, project, password=None, test_client=None):
password = password or project
@@ -40,24 +45,46 @@ class BudgetTestCase(unittest.TestCase):
return project
- def setUp(self):
- web.app.config['TESTING'] = True
+ def test_notifications(self):
+ """Test that the notifications are sent, and that email adresses
+ are checked properly.
+ """
+ # create a project
+ self.create_project("raclette")
- self.fd, self.fp = tempfile.mkstemp()
- web.app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///%s" % self.fp
- web.app.config['CSRF_ENABLED'] = False # simplify the tests
- self.app = web.app.test_client()
+ self.login("raclette")
- models.db.init_app(web.app)
- web.mail.init_app(web.app)
+ # sending a message to one person
+ with web.mail.record_messages() as outbox:
+ self.app.post("/raclette/invite", data=
+ {"emails": 'alexis@notmyidea.org'})
- models.db.app = web.app
- models.db.create_all()
+ self.assertEqual(len(outbox), 1)
+ self.assertEqual(outbox[0].recipients, ["alexis@notmyidea.org"])
- def tearDown(self):
- # clean after testing
- os.close(self.fd)
- os.unlink(self.fp)
+ # sending a message to multiple persons
+ with web.mail.record_messages() as outbox:
+ self.app.post("/raclette/invite", data=
+ {"emails": 'alexis@notmyidea.org, toto@notmyidea.org'})
+
+ # only one message is sent to multiple persons
+ self.assertEqual(len(outbox), 1)
+ self.assertEqual(outbox[0].recipients,
+ ["alexis@notmyidea.org", "toto@notmyidea.org"])
+
+ # mail address checking
+ with web.mail.record_messages() as outbox:
+ response = self.app.post("/raclette/invite", data={"emails": "toto"})
+ self.assertEqual(len(outbox), 0) # no message sent
+ self.assertIn("The email toto is not valid", response.data)
+
+ # mixing good and wrong adresses shouldn't send any messages
+ with web.mail.record_messages() as outbox:
+ self.app.post("/raclette/invite", data=
+ {"emails": 'alexis@notmyidea.org, alexis'}) # not valid
+
+ # only one message is sent to multiple persons
+ self.assertEqual(len(outbox), 0)
if __name__ == "__main__":