From caf9b6fcc24d97586a50b21022fbf673435fe939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Sureau?= Date: Sat, 28 Jan 2012 12:40:10 +0100 Subject: [PATCH 1/2] Correct bug in members model. The has_bills method did not worked as expected. Fix #73. --- budget/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/budget/models.py b/budget/models.py index 3dcd709..5b50e3e 100644 --- a/budget/models.py +++ b/budget/models.py @@ -110,7 +110,7 @@ class Person(db.Model): def has_bills(self): """return if the user do have bills or not""" bills_as_ower_number = db.session.query(billowers)\ - .filter(billowers.columns.get("bill_id") == self.id)\ + .filter(billowers.columns.get("person_id") == self.id)\ .count() return bills_as_ower_number != 0 or len(self.bills) != 0 From 192ca41b0a7b294029a7a836f556f8f1863dd91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Sureau?= Date: Thu, 29 Mar 2012 01:13:00 +0200 Subject: [PATCH 2/2] Adds test for the has_bills() method of Person model --- budget/tests.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/budget/tests.py b/budget/tests.py index 0dcd8a1..5e03cde 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -214,6 +214,31 @@ class BudgetTestCase(TestCase): self.assertEqual( len(models.Project.query.get("randomid").active_members), 1) + def test_person_model(self): + self.post_project("raclette") + self.login("raclette") + + # adds a member to this project + self.app.post("/raclette/members/add", data={'name': 'alexis' }) + alexis = models.Project.query.get("raclette").members[-1] + + # should not have any bills + self.assertFalse(alexis.has_bills()) + + # bound him to a bill + self.app.post("/raclette/add", data={ + 'date': '2011-08-10', + 'what': u'fromage à raclette', + 'payer': alexis.id, + 'payed_for': [alexis.id,], + 'amount': '25', + }) + + # should have a bill now + 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")