1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Add tests to make test that invitations are sent.

Fixes #7
This commit is contained in:
Alexis Metaireau 2011-08-09 23:22:57 +02:00
parent fc0b7f9e66
commit cdc6f2e1c4

View file

@ -9,37 +9,6 @@ import models
class BudgetTestCase(unittest.TestCase): 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")
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.
def login(self, project, password=None, test_client=None):
password = password or project
test_client = test_client or self.app
return test_client.post('/authenticate', data=dict(
id=project, password=password), follow_redirects=True)
def create_project(self, name):
"""Create a fake project"""
# create the project
project = models.Project(id=name, name=unicode(name), password=name,
contact_email="%s@notmyidea.org" % name)
models.db.session.add(project)
models.db.session.commit()
return project
def setUp(self): def setUp(self):
web.app.config['TESTING'] = True web.app.config['TESTING'] = True
@ -59,6 +28,64 @@ class BudgetTestCase(unittest.TestCase):
os.close(self.fd) os.close(self.fd)
os.unlink(self.fp) os.unlink(self.fp)
def login(self, project, password=None, test_client=None):
password = password or project
test_client = test_client or self.app
return test_client.post('/authenticate', data=dict(
id=project, password=password), follow_redirects=True)
def create_project(self, name):
"""Create a fake project"""
# create the project
project = models.Project(id=name, name=unicode(name), password=name,
contact_email="%s@notmyidea.org" % name)
models.db.session.add(project)
models.db.session.commit()
return project
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.login("raclette")
# sending a message to one person
with web.mail.record_messages() as outbox:
self.app.post("/raclette/invite", data=
{"emails": 'alexis@notmyidea.org'})
self.assertEqual(len(outbox), 1)
self.assertEqual(outbox[0].recipients, ["alexis@notmyidea.org"])
# 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__": if __name__ == "__main__":
unittest.main() unittest.main()