diff --git a/tests/py/test_tips_json.py b/tests/py/test_tips_json.py deleted file mode 100644 index 9232b254b3..0000000000 --- a/tests/py/test_tips_json.py +++ /dev/null @@ -1,130 +0,0 @@ -from __future__ import print_function, unicode_literals - -import json - -import pytest -from aspen.utils import utcnow -from gratipay.testing import Harness - - -class TestTipsJson(Harness): - - def also_prune_variant(self, also_prune, tippees=1): - - now = utcnow() - self.make_participant("test_tippee1", claimed_time=now) - self.make_participant("test_tippee2", claimed_time=now) - self.make_participant("test_tipper", claimed_time=now) - - data = [ - {'username': 'test_tippee1', 'platform': 'gratipay', 'amount': '1.00'}, - {'username': 'test_tippee2', 'platform': 'gratipay', 'amount': '2.00'} - ] - - response = self.client.POST( '/~test_tipper/tips.json' - , body=json.dumps(data) - , content_type='application/json' - , auth_as='test_tipper' - ) - - assert response.code == 200 - assert len(json.loads(response.body)) == 2 - - response = self.client.POST( '/~test_tipper/tips.json?also_prune=' + also_prune - , body=json.dumps([{ 'username': 'test_tippee2' - , 'platform': 'gratipay' - , 'amount': '1.00' - }]) - , content_type='application/json' - , auth_as='test_tipper' - ) - - assert response.code == 200 - - response = self.client.GET('/~test_tipper/tips.json', auth_as='test_tipper') - assert response.code == 200 - assert len(json.loads(response.body)) == tippees - - def test_get_response(self): - now = utcnow() - self.make_participant("test_tipper", claimed_time=now) - - response = self.client.GET('/~test_tipper/tips.json', auth_as='test_tipper') - - assert response.code == 200 - assert len(json.loads(response.body)) == 0 # empty array - - @pytest.mark.xfail(reason="migrating to Teams; #3399") - def test_get_response_with_tips(self): - now = utcnow() - self.make_participant("test_tippee1", claimed_time=now) - self.make_participant("test_tipper", claimed_time=now) - - response = self.client.POST( '/~test_tippee1/tip.json' - , {'amount': '1.00'} - , auth_as='test_tipper' - ) - - assert response.code == 200 - assert json.loads(response.body)['amount'] == '1.00' - - response = self.client.GET('/~test_tipper/tips.json', auth_as='test_tipper') - data = json.loads(response.body)[0] - - assert response.code == 200 - assert data['username'] == 'test_tippee1' - assert data['amount'] == '1.00' - - def test_post_bad_platform(self): - now = utcnow() - self.make_participant("test_tippee1", claimed_time=now) - self.make_participant("test_tipper", claimed_time=now) - - response = self.client.POST( '/~test_tipper/tips.json' - , body=json.dumps([{ 'username': 'test_tippee1' - , 'platform': 'badname' - , 'amount': '1.00' - }]) - , auth_as='test_tipper' - , content_type='application/json' - ) - - assert response.code == 200 - - resp = json.loads(response.body) - - for tip in resp: - assert 'error' in tip - - def test_gittip_as_platform_works(self): - now = utcnow() - self.make_participant("test_tippee1", claimed_time=now) - self.make_participant("test_tipper", claimed_time=now) - - response = self.client.POST( '/~test_tipper/tips.json' - , body=json.dumps([{ 'username': 'test_tippee1' - , 'platform': 'gittip' - , 'amount': '1.00' - }]) - , auth_as='test_tipper' - , content_type='application/json' - ) - - assert response.code == 200 - - resp = json.loads(response.body) - assert len(resp) == 1 - tip = resp[0] - assert tip['platform'] == 'gittip' - - def test_also_prune_as_1(self): - self.also_prune_variant('1') - - def test_also_prune_as_true(self): - self.also_prune_variant('true') - - def test_also_prune_as_yes(self): - self.also_prune_variant('yes') - - def test_also_prune_as_0(self): - self.also_prune_variant('0', 2) diff --git a/www/~/%username/tips.json.spt b/www/~/%username/tips.json.spt deleted file mode 100644 index 880a255236..0000000000 --- a/www/~/%username/tips.json.spt +++ /dev/null @@ -1,52 +0,0 @@ -import re -from aspen import json, Response -from gratipay.utils import get_participant - -callback_pattern = re.compile(r'^[_A-Za-z0-9.]+$') - -class BadPlatform(Exception): pass - -[-----------------------] -participant = get_participant(state, restrict=True) -if user.participant != participant: - raise Response(403) # disallow admins - -if request.method == 'POST': - out = [] - new_tips = request.body - seen = set() - for tip in new_tips: - seen.add(tip['username']) - one = {"username": tip['username'], "platform": tip['platform']} - try: - if tip['platform'] not in ('gittip', 'gratipay'): - raise BadPlatform - amount = participant.set_tip_to( tip['username'] - , parse_decimal(tip['amount']) - )['amount'] - except Exception, exc: - amount = "error" - one['error'] = exc.__class__.__name__ - one['amount'] = str(amount) - out.append(one) - - if request.qs.get('also_prune', 'false').lower() in ('true', '1', 'yes'): - old_tips = participant.get_current_tips() - for tip in old_tips: - if tip['tippee'] not in seen: - participant.set_tip_to(tip['tippee'], '0.00') - -else: - tips, total = participant.get_giving_for_profile() - - out = [] - for tip in tips: - if tip.amount == 0: - continue - out.append({ "username": tip.tippee - , "platform": "gratipay" - , "amount": str(tip.amount) - }) - -[---] application/json via json_dump -out