Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #4204 from gratipay/fix-check-balances
Browse files Browse the repository at this point in the history
Fix regression from #3975
  • Loading branch information
clone1018 authored Nov 25, 2016
2 parents 4d68357 + b42cc99 commit 63cc20b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gratipay/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ 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
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
Expand Down
28 changes: 28 additions & 0 deletions tests/py/test_db_checks.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 63cc20b

Please sign in to comment.