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

Fix nmasspays check during payday #4360

Merged
merged 3 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/masspay.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def post_back_to_gratipay(force=False):
except KeyError:
gratipay_base_url = 'https://gratipay.com'

nmasspays = int(requests.get(gratipay_base_url + '/dashboard/nmasspays').text())
nmasspays = int(requests.get(gratipay_base_url + '/dashboard/nmasspays').text)
if nmasspays < 10 and not force:
print("It looks like we didn't run MassPay last week! If you are absolutely sure that we "
"did, then rerun with -f.")
Expand Down
58 changes: 29 additions & 29 deletions tests/py/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@

class TestNMassPays(BillingHarness):

# nmp - nmasspays

def setUp(self):
BillingHarness.setUp(self)
self.make_participant('admin', claimed_time='now', is_admin=True).username
team = self.make_team(owner=self.homer, is_approved=True)
self.obama.set_payment_instruction(team, '20.00')

def post_masspay(self, username, route, amount):
self.client.PxST( '/~{}/history/record-an-exchange'.format(username)
, { 'amount': unicode(amount)
, 'fee': '0'
, 'note': 'Exchange!'
, 'status': 'succeeded'
, 'route_id': unicode(route.id)
}
, auth_as='admin'
) # responds with 302
def post_masspays(self, n):
for i in range(n):
self.client.PxST( '/~homer/history/record-an-exchange'
, { 'amount': '-20'
, 'fee': '0'
, 'note': 'Exchange!'
, 'status': 'succeeded'
, 'route_id': unicode(self.homer_route.id)
}
, auth_as='admin'
) # responds with 302


def test_nmp_returns_zero_for_no_paydays(self):
self.client.GET('/dashboard/nmasspays').body == '0'
def test_returns_zero_for_no_paydays(self):
assert self.client.GET('/dashboard/nmasspays').body == '0'

def test_nmp_returns_zero_for_no_masspays(self):
def test_returns_zero_for_one_payday(self):
self.run_payday()
self.client.GET('/dashboard/nmasspays').body == '0'
assert self.client.GET('/dashboard/nmasspays').body == '0'

def test_nmp_returns_one_for_one_payday_with_one_masspay(self):
team = self.make_team(owner=self.homer, is_approved=True)
self.obama.set_payment_instruction(team, '20.00')
def test_returns_zero_for_penultimate_payday_with_no_masspays(self):
self.run_payday(); self.post_masspays(2)
self.run_payday()
self.post_masspay('homer', self.homer_route, 20)
self.client.GET('/dashboard/nmasspays').body == '1'

def test_nmp_returns_one_for_many_paydays_with_one_masspay(self):
team = self.make_team(owner=self.homer, is_approved=True)
self.obama.set_payment_instruction(team, '20.00')
for i in range(10):
self.run_payday()
self.post_masspay('homer', self.homer_route, 20)
self.client.GET('/dashboard/nmasspays').body == '1'
self.run_payday(); self.post_masspays(1)
assert self.client.GET('/dashboard/nmasspays').body == '0'

def test_returns_three_for_penultimate_payday_with_three_masspays(self):
self.run_payday(); self.post_masspays(1)
self.run_payday(); self.post_masspays(4)
self.run_payday(); self.post_masspays(2)
self.run_payday(); self.post_masspays(3)
self.run_payday(); self.post_masspays(8)
assert self.client.GET('/dashboard/nmasspays').body == '3'
12 changes: 7 additions & 5 deletions www/dashboard/nmasspays.spt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
[--------]
nmasspays = website.db.one("""

WITH payday AS (SELECT ts_start FROM paydays ORDER BY ts_start DESC LIMIT 1)
starts = website.db.all("""
SELECT ts_start FROM paydays ORDER BY ts_start DESC LIMIT 2
""")
nmasspays = 0 if len(starts) < 2 else website.db.one("""

SELECT count(*)
FROM exchanges e
JOIN exchange_routes er
ON e.route = er.id
WHERE er.network = 'paypal'
AND e.amount < 0
AND timestamp > (SELECT ts_start FROM payday)
AND timestamp < %s
AND timestamp > %s

""")
""", starts)
[--------] text/plain
{{ nmasspays }}