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

Commit

Permalink
Convert payin_suspended to is_suspicious (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Nov 6, 2012
1 parent 7f8bff0 commit 4b08a1f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 84 deletions.
6 changes: 3 additions & 3 deletions gittip/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def get_participants(self, ts_start):
, balance
, balanced_account_uri
, stripe_customer_id
, payin_suspended
, is_suspicious
FROM participants
WHERE claimed_time IS NOT NULL
AND claimed_time < %s
Expand Down Expand Up @@ -230,8 +230,8 @@ def charge_and_or_transfer(self, ts_start, participant, tips, total):
money between Gittip accounts.
"""
if participant['payin_suspended']:
log("PAYIN SUSPENDED: %s" % participant['id'])
if participant['is_suspicious']:
log("SUSPICIOUS: %s" % participant['id'])
return

short = total - participant['balance']
Expand Down
17 changes: 0 additions & 17 deletions gittip/participant.py

This file was deleted.

23 changes: 14 additions & 9 deletions gittip/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from aspen.testing import Website, StubRequest
from aspen.utils import utcnow
from gittip import wireup
from gittip.authentication import User
from gittip.billing.payday import Payday


Expand Down Expand Up @@ -312,24 +313,24 @@ def setup_tips(*recs):
_participants = {}

for rec in recs:
defaults = good_cc, payin_suspended, claimed = (True, False, True)
defaults = good_cc, is_suspicious, claimed = (True, False, True)

if len(rec) == 3:
tipper, tippee, amount = rec
elif len(rec) == 4:
tipper, tippee, amount, good_cc = rec
payin_suspended, claimed = (False, True)
is_suspicious, claimed = (False, True)
elif len(rec) == 5:
tipper, tippee, amount, good_cc, payin_suspended = rec
tipper, tippee, amount, good_cc, is_suspicious = rec
claimed = True
elif len(rec) == 6:
tipper, tippee, amount, good_cc, payin_suspended, claimed = rec
tipper, tippee, amount, good_cc, is_suspicious, claimed = rec

assert good_cc in (True, False, None), good_cc
assert payin_suspended in (True, False), payin_suspended
assert is_suspicious in (True, False), is_suspicious
assert claimed in (True, False), claimed

_participants[tipper] = (good_cc, payin_suspended, claimed)
_participants[tipper] = (good_cc, is_suspicious, claimed)
if tippee not in _participants:
_participants[tippee] = defaults
now = utcnow()
Expand All @@ -343,12 +344,12 @@ def setup_tips(*recs):
then = utcnow() - datetime.timedelta(seconds=3600)

participants = []
for participant_id, (good_cc, payin_suspended, claimed) in _participants.items():
for participant_id, (good_cc, is_suspicious, claimed) in _participants.items():
rec = {"id": participant_id}
if good_cc is not None:
rec["last_bill_result"] = "" if good_cc else "Failure!"
rec["balanced_account_uri"] = "/v1/blah/blah/" + participant_id
rec["payin_suspended"] = payin_suspended
rec["is_suspicious"] = is_suspicious
if claimed:
rec["claimed_time"] = then
participants.append(rec)
Expand All @@ -363,11 +364,15 @@ def setup_tips(*recs):
, '--project_root', str('..')
])

def serve_request(path):
def serve_request(path, user=None):
"""Given an URL path, return response.
"""
request = StubRequest(path)
request.website = test_website
if user is not None:
user = User.from_id(user)
# Note that Cookie needs a bytestring.
request.headers.cookie[str('session')] = user.session_token
response = test_website.handle_safely(request)
return response

Expand Down
8 changes: 8 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ ALTER TABLE participants ALTER COLUMN balance SET NOT NULL;
-- https://github.com/whit537/www.gittip.com/issues/350

ALTER TABLE participants ADD COLUMN payin_suspended bool NOT NULL DEFAULT FALSE;


-------------------------------------------------------------------------------
-- https://github.com/whit537/www.gittip.com/issues/354

ALTER TABLE participants ADD COLUMN is_suspicious bool DEFAULT NULL;
UPDATE participants SET is_suspicious=true WHERE payin_suspended;
ALTER TABLE participants DROP COLUMN payin_suspended;
10 changes: 5 additions & 5 deletions tests/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_payday_moves_money(charge_on_balanced):
assert actual == expected, actual

@mock.patch('gittip.billing.payday.Payday.charge_on_balanced')
def test_payday_doesnt_move_money_from_a_suspended_payin_account(charge_on_balanced):
def test_payday_doesnt_move_money_from_a_suspicious_account(charge_on_balanced):
charge_on_balanced.return_value = (Decimal('10.00'), Decimal('0.68'), None)
tips = testing.setup_tips(('buz', 'bar', '6.00', True, True)) # under $10!
with testing.load(*tips) as context:
Expand All @@ -417,7 +417,7 @@ def test_payday_doesnt_move_money_from_a_suspended_payin_account(charge_on_balan
assert actual == {"paydays": [1,0,0]}, actual

@mock.patch('gittip.billing.payday.Payday.charge_on_balanced')
def test_payday_does_move_money_TO_a_suspended_payin_account(charge_on_balanced):
def test_payday_does_move_money_TO_a_suspicious_account(charge_on_balanced):
charge_on_balanced.return_value = (Decimal('10.00'), Decimal('0.68'), None)
tips = testing.setup_tips( ('buz', 'bar', '6.00', True, True)
, ('foo', 'buz', '1.00')
Expand Down Expand Up @@ -731,7 +731,7 @@ def test_charge_and_or_transfer_no_tips(self, get_tips_and_total):
participant = { 'balance': 1
, 'id': self.participant_id
, 'balanced_account_uri': self.balanced_account_uri
, 'payin_suspended': False
, 'is_suspicious': False
}

initial_payday = self._get_payday()
Expand Down Expand Up @@ -763,7 +763,7 @@ def test_charge_and_or_transfer(self, tip, get_tips_and_total):
participant = { 'balance': 1
, 'id': self.participant_id
, 'balanced_account_uri': self.balanced_account_uri
, 'payin_suspended': False
, 'is_suspicious': False
}

return_values = [1, 1, 0, -1]
Expand Down Expand Up @@ -803,7 +803,7 @@ def test_charge_and_or_transfer_short(self, charge, get_tips_and_total):
participant = { 'balance': 0
, 'id': self.participant_id
, 'balanced_account_uri': self.balanced_account_uri
, 'payin_suspended': False
, 'is_suspicious': False
}


Expand Down
53 changes: 53 additions & 0 deletions tests/test_is_suspicious.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from gittip.testing import load, serve_request


def participants(foo_starts_suspicious=None):
participants = ( {"id": "foo"}
, {"id": "bar", "is_admin": True}
)
if foo_starts_suspicious is not None:
participants[0]["is_suspicious"] = foo_starts_suspicious
return load('participants', *participants)


def toggle_is_suspicious():
response = serve_request('/foo/toggle-is-suspicious.json', user='bar')
return response.body


def test_participants_start_out_with_is_suspicious_None():
with participants() as context:
actual = context.dump()['participants']['foo']['is_suspicious']
assert actual is None, actual

def test_toggling_NULL_gives_true():
with participants() as context:
toggle_is_suspicious()
actual = context.diff()['participants']['updates'][0]['is_suspicious']
assert actual is True, actual

def test_toggling_changes_two_things():
with participants() as context:
toggle_is_suspicious()
actual = context.diff(compact=True)
assert actual == {'participants': [0,2,0]}, actual

def test_but_the_second_thing_is_just_bars_session():
with participants() as context:
toggle_is_suspicious()
expected = ('bar', ['id', 'session_expires', 'session_token'])
second = context.diff()['participants']['updates'][1]
actual = (second['id'], sorted(second.keys()))
assert actual == expected, actual

def test_toggling_true_gives_false():
with participants(True) as context:
toggle_is_suspicious()
actual = context.diff()['participants']['updates'][0]['is_suspicious']
assert actual is False, actual

def test_toggling_false_gives_true():
with participants(False) as context:
toggle_is_suspicious()
actual = context.diff()['participants']['updates'][0]['is_suspicious']
assert actual is True, actual
44 changes: 0 additions & 44 deletions tests/test_suspension.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from aspen import Response
from gittip import db
^L
if not user.ADMIN:
Expand All @@ -6,12 +7,12 @@ if not user.ADMIN:
rec = db.fetchone("""

UPDATE participants
SET payin_suspended = not payin_suspended
SET is_suspicious = (is_suspicious IS NULL) OR (is_suspicious IS false)
WHERE id=%s
RETURNING payin_suspended
RETURNING is_suspicious

""", (path['participant_id'],))

assert rec is not None

response.body = {"payin_suspended": rec['payin_suspended']}
response.body = {"is_suspicious": rec['is_suspicious']}
6 changes: 3 additions & 3 deletions www/about/fraud/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SELECT id
, balance
FROM participants
WHERE payin_suspended
WHERE is_suspicious

""")
if _suspicious is None:
Expand All @@ -23,7 +23,7 @@
person['gives_to'] = db.fetchall("""

SELECT DISTINCT tippee AS id
, payin_suspended AS is_suspicious
, is_suspicious
FROM tips
JOIN participants p
ON tippee = p.id
Expand All @@ -34,7 +34,7 @@
person['receives_from'] = db.fetchall("""

SELECT DISTINCT tipper AS id
, payin_suspended AS is_suspicious
, is_suspicious
FROM tips
JOIN participants p
ON tipper = p.id
Expand Down

0 comments on commit 4b08a1f

Please sign in to comment.