mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Add unit tests for settle_bill
This commit is contained in:
parent
2b51131aa4
commit
79bd22c25c
2 changed files with 79 additions and 11 deletions
|
@ -1,25 +1,36 @@
|
|||
{% extends "layout.html" %}
|
||||
|
||||
{% block head %}
|
||||
<script src="{{ url_for("static", filename="js/jquery-ui.js") }}"></script>
|
||||
{% if g.lang != "en" %}
|
||||
<script src="{{ url_for("static", filename="js/i18n/jquery.ui.datepicker-%s.js" % g.lang ) }}"></script>
|
||||
{% 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 %}
|
||||
<li><a href="{{ url_for(".list_bills") }}">{{ _("Bills") }}</a></li>
|
||||
<li class="active"><a href="{{ url_for(".settle_bill") }}">{{ _("Settle") }}</a></li>
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
<div id="sidebar" class="sidebar">
|
||||
|
||||
<div id="table_overflow">
|
||||
<table class="balance table">
|
||||
{% set balance = g.project.balance %}
|
||||
{% for member in g.project.members | sort(attribute='name') if member.activated or balance[member] != 0 %}
|
||||
<tr id="bal-member-{{ member }}" action={% if member.activated %}delete{% else %}reactivate{% endif %}>
|
||||
<td class="balance-name">{{ member.name }}</td>
|
||||
<td class="balance-value {% if balance[member] > 0 %}positive{% elif balance[member] < 0 %}negative{% endif %}">
|
||||
{% if balance[member] > 0 %}+{% endif %}{{ balance[member] }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<table id="bill_table" class="split_bills common-table zebra-striped">
|
||||
<table id="bill_table" class="split_bills table table-striped">
|
||||
<thead><tr><th>{{ _("Who pays?") }}</th><th>{{ _("To whom?") }}</th><th>{{ _("How much?") }}</th></tr></thead>
|
||||
<tbody>
|
||||
{% for bill in bills %}
|
||||
|
|
|
@ -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"""
|
||||
|
|
Loading…
Reference in a new issue