diff options
| author | Alexis Metaireau <alexis@notmyidea.org> | 2011-08-09 23:22:57 +0200 |
|---|---|---|
| committer | Alexis Metaireau <alexis@notmyidea.org> | 2011-08-09 23:49:44 +0200 |
| commit | cdc6f2e1c456c9ba748db773c2f52428736c2255 (patch) | |
| tree | c9f824b71b21b2170d4e5bc2e2e07110e02d74f9 /budget/tests.py | |
| parent | fc0b7f9e66f3508615b99d0973578d516ea72956 (diff) | |
| download | ihatemoney-mirror-cdc6f2e1c456c9ba748db773c2f52428736c2255.zip ihatemoney-mirror-cdc6f2e1c456c9ba748db773c2f52428736c2255.tar.gz ihatemoney-mirror-cdc6f2e1c456c9ba748db773c2f52428736c2255.tar.bz2 | |
Add tests to make test that invitations are sent.
Fixes #7
Diffstat (limited to 'budget/tests.py')
| -rw-r--r-- | budget/tests.py | 77 |
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__": |
