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

Enhance the test suite

This commit is contained in:
Alexis Metaireau 2012-09-02 13:26:56 +02:00
parent b3ce91c79f
commit e75809dddf

View file

@ -68,8 +68,8 @@ class BudgetTestCase(TestCase):
self.login("raclette")
self.post_project("raclette")
self.app.post("/raclette/invite", data=
{"emails": 'alexis@notmyidea.org'})
self.app.post("/raclette/invite",
data={"emails": 'alexis@notmyidea.org'})
self.assertEqual(len(outbox), 2)
self.assertEqual(outbox[0].recipients, ["raclette@notmyidea.org"])
@ -77,8 +77,8 @@ class BudgetTestCase(TestCase):
# sending a message to multiple persons
with run.mail.record_messages() as outbox:
self.app.post("/raclette/invite", data=
{"emails": 'alexis@notmyidea.org, toto@notmyidea.org'})
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)
@ -87,19 +87,19 @@ class BudgetTestCase(TestCase):
# mail address checking
with run.mail.record_messages() as outbox:
response = self.app.post("/raclette/invite", data={"emails": "toto"})
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 run.mail.record_messages() as outbox:
self.app.post("/raclette/invite", data=
{"emails": 'alexis@notmyidea.org, alexis'}) # not valid
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)
def test_password_reminder(self):
# test that it is possible to have an email cotaining the password of a
# project in case people forget it (and it happens!)
@ -117,7 +117,6 @@ class BudgetTestCase(TestCase):
self.assertIn("raclette", outbox[0].body)
self.assertIn("raclette@notmyidea.org", outbox[0].recipients)
def test_project_creation(self):
with run.app.test_client() as c:
@ -138,7 +137,7 @@ class BudgetTestCase(TestCase):
# Add a second project with the same id
models.Project.query.get('raclette')
result = c.post("/create", data={
c.post("/create", data={
'name': 'Another raclette party',
'id': 'raclette', # already used !
'password': 'party',
@ -157,7 +156,9 @@ class BudgetTestCase(TestCase):
self.assertEqual(len(models.Project.query.get("raclette").members), 1)
# adds him twice
result = self.app.post("/raclette/members/add", data={'name': 'alexis' })
result = self.app.post("/raclette/members/add",
data={'name': 'alexis'})
# should not accept him
self.assertEqual(len(models.Project.query.get("raclette").members), 1)
@ -242,7 +243,6 @@ class BudgetTestCase(TestCase):
alexis = models.Project.query.get("raclette").members[-1]
self.assertTrue(alexis.has_bills())
def test_member_delete_method(self):
self.post_project("raclette")
self.login("raclette")
@ -254,17 +254,6 @@ class BudgetTestCase(TestCase):
response = self.app.get("/raclette/members/1/delete")
self.assertEqual(response.status_code, 405)
def test_demo(self):
# Test that it is possible to connect automatically by going onto /demo
with run.app.test_client() as c:
models.db.session.add(models.Project(id="demo", name=u"demonstration",
password="demo", contact_email="demo@notmyidea.org"))
models.db.session.commit()
c.get("/demo")
# session is updated
self.assertEqual(session['demo'], 'demo')
def test_demo(self):
# test that a demo project is created if none is defined
self.assertEqual([], models.Project.query.all())
@ -308,7 +297,8 @@ class BudgetTestCase(TestCase):
self.app.post("/raclette/members/add", data={'name': 'alexis'})
self.app.post("/raclette/members/add", data={'name': 'fred'})
members_ids = [m.id for m in models.Project.query.get("raclette").members]
members_ids = [m.id for m in
models.Project.query.get("raclette").members]
# create a bill
self.app.post("/raclette/add", data={
@ -318,12 +308,12 @@ class BudgetTestCase(TestCase):
'payed_for': members_ids,
'amount': '25',
})
raclette = models.Project.query.get("raclette")
models.Project.query.get("raclette")
bill = models.Bill.query.one()
self.assertEqual(bill.amount, 25)
# edit the bill
resp = self.app.post("/raclette/edit/%s" % bill.id, data={
self.app.post("/raclette/edit/%s" % bill.id, data={
'date': '2011-08-10',
'what': u'fromage à raclette',
'payer': members_ids[0],
@ -372,7 +362,9 @@ class BudgetTestCase(TestCase):
'what': u'fromage à raclette',
'payer': members_ids[0],
'payed_for': members_ids,
'amount': '-25', # bill with a negative value should be converted to a positive value
# bill with a negative value should be converted to a positive
# value
'amount': '-25'
})
bill = models.Bill.query.filter(models.Bill.date == '2011-08-12')[0]
self.assertEqual(bill.amount, 25)
@ -397,7 +389,7 @@ class BudgetTestCase(TestCase):
self.app.post("/raclette/members/add", data={'name': 'tata'})
# create bills
req = self.app.post("/raclette/add", data={
self.app.post("/raclette/add", data={
'date': '2011-08-10',
'what': u'fromage à raclette',
'payer': 1,
@ -405,7 +397,7 @@ class BudgetTestCase(TestCase):
'amount': '24.36',
})
req2 = self.app.post("/raclette/add", data={
self.app.post("/raclette/add", data={
'date': '2011-08-10',
'what': u'red wine',
'payer': 2,
@ -413,7 +405,7 @@ class BudgetTestCase(TestCase):
'amount': '19.12',
})
req3 = self.app.post("/raclette/add", data={
self.app.post("/raclette/add", data={
'date': '2011-08-10',
'what': u'delicatessen',
'payer': 1,
@ -424,7 +416,6 @@ class BudgetTestCase(TestCase):
balance = models.Project.query.get("raclette").balance
self.assertDictEqual(balance, {3: -8.12, 1: 8.12, 2: 0.0})
def test_edit_project(self):
# A project should be editable
@ -520,7 +511,8 @@ class APITestCase(TestCase):
})
self.assertTrue(400, resp.status_code)
self.assertEqual('{"contact_email": ["Invalid email address."]}', resp.data)
self.assertEqual('{"contact_email": ["Invalid email address."]}',
resp.data)
# create it
resp = self.api_create("raclette")