From 7710c69ea5779e8eebcf8ccf8770e7e58b2d9969 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 1 Jul 2016 12:01:42 -0400 Subject: [PATCH] Start bringing back individual member endpoint --- tests/py/test_www_team_distributing.py | 14 ++++++++++++-- .../{%membername.json.spt => %member_id.json.spt} | 11 +++++------ 2 files changed, 17 insertions(+), 8 deletions(-) rename www/%team/distributing/{%membername.json.spt => %member_id.json.spt} (92%) diff --git a/tests/py/test_www_team_distributing.py b/tests/py/test_www_team_distributing.py index 9ddd79eef9..aca4c61120 100644 --- a/tests/py/test_www_team_distributing.py +++ b/tests/py/test_www_team_distributing.py @@ -15,11 +15,21 @@ def test_distributing_doesnt_redirect_when_money_is_available(self): assert self.client.GET('/TheEnterprise/distributing/').code == 200 - def test_distributing_json_redirects_when_no_money_is_available(self): + def test_json_redirects_when_no_money_is_available(self): self.make_team() assert self.client.GxT('/TheEnterprise/distributing/index.json').code == 302 - def test_distributing_json_doesnt_redirect_when_money_is_available(self): + def test_json_doesnt_redirect_when_money_is_available(self): self.make_team() self.db.run("UPDATE teams SET available=537") assert self.client.GET('/TheEnterprise/distributing/index.json', raise_immediately=False).code == 500 + + + def test_member_json_redirects_when_no_money_is_available(self): + self.make_team() + assert self.client.GxT('/TheEnterprise/distributing/1.json').code == 302 + + def test_member_json_doesnt_redirect_when_money_is_available(self): + self.make_team() + self.db.run("UPDATE teams SET available=537") + assert self.client.GET('/TheEnterprise/distributing/1.json', raise_immediately=False).code == 500 diff --git a/www/%team/distributing/%membername.json.spt b/www/%team/distributing/%member_id.json.spt similarity index 92% rename from www/%team/distributing/%membername.json.spt rename to www/%team/distributing/%member_id.json.spt index 2b235117c1..624411f11b 100644 --- a/www/%team/distributing/%membername.json.spt +++ b/www/%team/distributing/%member_id.json.spt @@ -4,20 +4,19 @@ from decimal import Decimal, InvalidOperation from aspen import Response from babel.numbers import NumberFormatError -from gratipay.utils import get_participant +from gratipay.utils import get_team from gratipay.models.participant import Participant ZERO = Decimal('0.00') A_PENNY = Decimal('0.01') [--------------------] -website.redirect('..', base_url='') # XXX Migrating to Teams! Fix this up! request.allow('GET', 'POST') -team = get_participant(state, restrict=False) -if not team.show_as_team(user): - raise Response(404) +team = get_team(state) +if team.available == 0: + website.redirect('..', base_url='') -member = Participant.from_username(request.path['membername']) +member = Participant.from_id(request.path['member_id']) if member is None or member.is_suspicious: raise Response(404, _("User not found.")) is_member = member.member_of(team)