diff options
| author | Alexis Metaireau <alexis@notmyidea.org> | 2017-01-16 21:13:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-16 21:13:56 +0100 |
| commit | dc75a72dd0caeafce20b09d3ad538bdcbabf4408 (patch) | |
| tree | 49b0a33793fd626a0251b3662e8af45f3bb5b4ff /budget/tests.py | |
| parent | d33f4a92a6384937169881f78e52afdb76412a20 (diff) | |
| parent | d6cf89008fdb5e40395d3ccc879db2255f13e461 (diff) | |
| download | ihatemoney-mirror-dc75a72dd0caeafce20b09d3ad538bdcbabf4408.zip ihatemoney-mirror-dc75a72dd0caeafce20b09d3ad538bdcbabf4408.tar.gz ihatemoney-mirror-dc75a72dd0caeafce20b09d3ad538bdcbabf4408.tar.bz2 | |
Merge pull request #164 from zorun/fix_zero_transfers
Fix zero-amount transfers and other rounding issues
Diffstat (limited to 'budget/tests.py')
| -rw-r--r-- | budget/tests.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/budget/tests.py b/budget/tests.py index eea7537..f0a5ea7 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -580,6 +580,46 @@ class BudgetTestCase(TestCase): self.assertEqual(a, balance[m.id]) return + def test_settle_zero(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'}) + + # create bills + self.app.post("/raclette/add", data={ + 'date': '2016-12-31', + 'what': u'fromage à raclette', + 'payer': 1, + 'payed_for': [1, 2, 3], + 'amount': '10.0', + }) + + self.app.post("/raclette/add", data={ + 'date': '2016-12-31', + 'what': u'red wine', + 'payer': 2, + 'payed_for': [1, 3], + 'amount': '20', + }) + + self.app.post("/raclette/add", data={ + 'date': '2017-01-01', + 'what': u'refund', + 'payer': 3, + 'payed_for': [2], + 'amount': '13.33', + }) + project = models.Project.query.get('raclette') + transactions = project.get_transactions_to_settle_bill() + members = defaultdict(int) + # There should not be any zero-amount transfer after rounding + for t in transactions: + rounded_amount = round(t['amount'], 2) + self.assertNotEqual(0.0, rounded_amount, + msg='%f is equal to zero after rounding' % t['amount']) class APITestCase(TestCase): |
