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 about project creation and member add.

See #14
This commit is contained in:
Alexis Metaireau 2011-08-10 17:06:32 +02:00
parent 3dd34c6cc4
commit 683c7ee0b8
2 changed files with 62 additions and 12 deletions

View file

@ -26,6 +26,10 @@ class ProjectForm(Form):
contact_email = TextField("Email", validators=[Required(), Email()]) contact_email = TextField("Email", validators=[Required(), Email()])
submit = SubmitField("Create the project") submit = SubmitField("Create the project")
def validate_id(form, field):
if Project.query.get(field.data):
raise ValidationError("This project id is already used")
def save(self): def save(self):
"""Create a new project with the information given by this form. """Create a new project with the information given by this form.

View file

@ -2,12 +2,12 @@ import os
import tempfile import tempfile
import unittest import unittest
from flask import g from flask import session
import web import web
import models import models
class BudgetTestCase(unittest.TestCase): class TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
web.app.config['TESTING'] = True web.app.config['TESTING'] = True
@ -38,24 +38,26 @@ class BudgetTestCase(unittest.TestCase):
def create_project(self, name): def create_project(self, name):
"""Create a fake project""" """Create a fake project"""
# create the project # create the project
project = models.Project(id=name, name=unicode(name), password=name, self.app.post("/create", data={
contact_email="%s@notmyidea.org" % name) 'name': name,
models.db.session.add(project) 'id': name,
models.db.session.commit() 'password': name,
'contact_email': '%s@notmyidea.org' % name
})
return project class BudgetTestCase(TestCase):
def test_notifications(self): def test_notifications(self):
"""Test that the notifications are sent, and that email adresses """Test that the notifications are sent, and that email adresses
are checked properly. are checked properly.
""" """
# create a project
self.create_project("raclette")
self.login("raclette")
# sending a message to one person # sending a message to one person
with web.mail.record_messages() as outbox: with web.mail.record_messages() as outbox:
# create a project
self.login("raclette")
self.create_project("raclette")
self.app.post("/raclette/invite", data= self.app.post("/raclette/invite", data=
{"emails": 'alexis@notmyidea.org'}) {"emails": 'alexis@notmyidea.org'})
@ -87,5 +89,49 @@ class BudgetTestCase(unittest.TestCase):
self.assertEqual(len(outbox), 0) self.assertEqual(len(outbox), 0)
def test_project_creation(self):
with web.app.test_client() as c:
# add a valid project
c.post("/create", data={
'name': 'The fabulous raclette party',
'id': 'raclette',
'password': 'party',
'contact_email': 'raclette@notmyidea.org'
})
# session is updated
self.assertEqual(session['raclette'], 'party')
# project is created
self.assertEqual(len(models.Project.query.all()), 1)
# Add a second project with the same id
models.Project.query.get('raclette')
result = c.post("/create", data={
'name': 'Another raclette party',
'id': 'raclette', #already used !
'password': 'party',
'contact_email': 'raclette@notmyidea.org'
})
# no new project added
self.assertEqual(len(models.Project.query.all()), 1)
def test_add_member(self):
self.create_project("raclette")
self.login("raclette")
# adds a member to this project
self.app.post("/raclette/members/add", data={'name': 'alexis' })
self.assertEqual(len(models.Project.query.get("raclette").members), 1)
# adds him twice
result = self.app.post("/raclette/members/add", data={'name': 'alexis' })
# should not accept him
self.assertEqual(len(models.Project.query.get("raclette").members), 1)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()