From 79bd22c25cab0c7b869ae35a72def30a5c2a6dba Mon Sep 17 00:00:00 2001 From: "A.Avenel" Date: Sat, 3 Nov 2012 20:53:51 +0100 Subject: [PATCH] Add unit tests for settle_bill --- budget/templates/settle_bill.html | 31 ++++++++++------ budget/tests.py | 59 ++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/budget/templates/settle_bill.html b/budget/templates/settle_bill.html index c91b03d..d04ff63 100644 --- a/budget/templates/settle_bill.html +++ b/budget/templates/settle_bill.html @@ -1,25 +1,36 @@ {% extends "layout.html" %} -{% block head %} - - {% if g.lang != "en" %} - - {% endif %} -{% endblock %} {% block js %} $('#cancel-form').click(function(){location.href={{ url_for(".list_bills") }};}); - $.datepicker.setDefaults({'dateFormat': 'yy-mm-dd'}); - $(".datepicker").datepicker($.datepicker.regional['{{ g.lang }}']); - {% endblock %} {% block navbar %}
  • {{ _("Bills") }}
  • {{ _("Settle") }}
  • {% endblock %} +{% block sidebar %} + +{% endblock %} + {% block content %} - +
    {% for bill in bills %} diff --git a/budget/tests.py b/budget/tests.py index d127b06..7790bb4 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -6,6 +6,7 @@ except ImportError: import base64 import json +from collections import defaultdict from flask import session @@ -432,7 +433,11 @@ class BudgetTestCase(TestCase): }) balance = models.Project.query.get("raclette").balance - self.assertDictEqual(balance, {3: -8.12, 1: 8.12, 2: 0.0}) + result = {} + result[models.Project.query.get("raclette").members[0]] = 8.12 + result[models.Project.query.get("raclette").members[1]] = 0.0 + result[models.Project.query.get("raclette").members[2]] = -8.12 + self.assertDictEqual(balance, result) def test_edit_project(self): # A project should be editable @@ -463,6 +468,58 @@ class BudgetTestCase(TestCase): response = self.app.get("/dashboard") self.assertEqual(response.status_code, 200) + def test_settle_page(self): + self.post_project("raclette") + response = self.app.get("/raclette/settle_bill") + self.assertEqual(response.status_code, 200) + + def test_settle(self): + self.post_project("raclette") + + # add members + self.app.post("/raclette/members/add", data={'name': 'alexis'}) + self.app.post("/raclette/members/add", data={'name': 'fred'}) + self.app.post("/raclette/members/add", data={'name': 'tata'}) + #Add a member with a balance=0 : + self.app.post("/raclette/members/add", data={'name': 'toto'}) + + # create bills + self.app.post("/raclette/add", data={ + 'date': '2011-08-10', + 'what': u'fromage à raclette', + 'payer': 1, + 'payed_for': [1, 2, 3], + 'amount': '10.0', + }) + + self.app.post("/raclette/add", data={ + 'date': '2011-08-10', + 'what': u'red wine', + 'payer': 2, + 'payed_for': [1], + 'amount': '20', + }) + + self.app.post("/raclette/add", data={ + 'date': '2011-08-10', + 'what': u'delicatessen', + 'payer': 1, + 'payed_for': [1, 2], + 'amount': '10', + }) + project = models.Project.query.get('raclette') + transactions = project.settle_bill() + members = defaultdict(int) + #We should have the same values between transactions and project balances + for t in transactions: + members[t['ower']]-=t['amount'] + members[t['payer']]+=t['amount'] + balance = models.Project.query.get("raclette").balance + for m, a in members.items(): + self.assertEqual(a, balance[m]) + return + + class APITestCase(TestCase): """Tests the API"""
    {{ _("Who pays?") }}{{ _("To whom?") }}{{ _("How much?") }}