From b15766d441ffa78685db928f935893930bcc4041 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 23 Nov 2016 21:26:19 -0500 Subject: [PATCH 1/2] Failing test for #3975 regression --- tests/py/test_db_checks.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/py/test_db_checks.py diff --git a/tests/py/test_db_checks.py b/tests/py/test_db_checks.py new file mode 100644 index 0000000000..ca9970caed --- /dev/null +++ b/tests/py/test_db_checks.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + +from gratipay import models +from gratipay.testing import Harness + + +class Tests(Harness): + + # cb - _check_balances - calls assert so we don't need asserts here + + def test_cb_is_fine_with_empty_database(self): + with self.db.get_cursor() as cursor: + models._check_balances(cursor) + + def test_cb_is_fine_with_status_unknown(self): + self.make_team() + alice = self.make_participant('alice') + self.make_exchange('braintree-cc', 12, 0, alice, status='unknown') + self.db.run('INSERT INTO payments (participant, team, amount, direction) ' + "VALUES ('alice', 'TheEnterprise', 11, 'to-team')") + + # force expected balance - unknown doesn't update balance, and we don't + # have a good make_payment to do it for us either + self.db.run("UPDATE participants SET balance=1 WHERE username='alice'") + + with self.db.get_cursor() as cursor: + models._check_balances(cursor) From 5d8610fcaf025f8c330c524dcb78a5d9c2b7f039 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 23 Nov 2016 18:20:34 -0500 Subject: [PATCH 2/2] Fix regression from #3975 --- gratipay/models/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gratipay/models/__init__.py b/gratipay/models/__init__.py index 5c78b6b802..dbea9dee8f 100644 --- a/gratipay/models/__init__.py +++ b/gratipay/models/__init__.py @@ -77,7 +77,7 @@ def _check_balances(cursor): select participant as username, sum(amount) as a from exchanges where amount > 0 - and (status is null or status = 'succeeded') + and (status = 'unknown' or status = 'succeeded') group by participant union all @@ -85,7 +85,7 @@ def _check_balances(cursor): select participant as username, sum(amount-fee) as a from exchanges where amount < 0 - and (status is null or status <> 'failed') + and (status = 'unknown' or status <> 'failed') group by participant union all