This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retire the "making the world better" statement prefix
closes #1659
- Loading branch information
Showing
10 changed files
with
83 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from __future__ import print_function, unicode_literals | ||
|
||
import json | ||
|
||
from gratipay.testing import Harness | ||
|
||
|
||
class Tests(Harness): | ||
|
||
def change_number(self, number, auth_as='alice', expecting_error=False): | ||
self.make_participant('alice', claimed_time='now') | ||
|
||
method = self.client.POST if not expecting_error else self.client.PxST | ||
response = method( "/alice/number.json" | ||
, {'number': number} | ||
, auth_as=auth_as | ||
) | ||
return response | ||
|
||
def test_participant_can_change_their_number(self): | ||
response = self.change_number('plural') | ||
actual = json.loads(response.body)['number'] | ||
assert actual == 'plural' | ||
|
||
def test_invalid_is_400(self): | ||
response = self.change_number('none', expecting_error=True) | ||
assert response.code == 400, response.code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from __future__ import print_function, unicode_literals | ||
|
||
from aspen import Response | ||
from gratipay.utils import get_participant, wrap | ||
from gratipay.exceptions import ProblemChangingNumber | ||
|
||
[-----------------------------------------------------------------------------] | ||
|
||
request.allow("POST") | ||
participant = get_participant(request, restrict=True) | ||
|
||
number = request.body["number"] | ||
|
||
if number not in ("singular", "plural"): | ||
raise Response(400) | ||
|
||
if number != participant.number: | ||
try: | ||
participant.update_number(number) | ||
except ProblemChangingNumber, e: | ||
raise Response(400, unicode(e)) | ||
|
||
[---] application/json via json_dump | ||
{"number": wrap(number)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,16 @@ | ||
from __future__ import print_function, unicode_literals | ||
|
||
from aspen import Response | ||
from gratipay.utils import wrap, markdown | ||
from gratipay.exceptions import ProblemChangingNumber | ||
from gratipay.utils import get_participant, markdown | ||
|
||
[-----------------------------------------------------------------------------] | ||
|
||
if user.ANON: | ||
raise Response(404) | ||
request.allow("POST") | ||
participant = get_participant(request, restrict=True) | ||
|
||
statement = request.body["statement"] | ||
number = request.body["number"] | ||
|
||
if number not in ("singular", "plural"): | ||
raise Response(400) | ||
|
||
if number != user.participant.number: | ||
try: | ||
user.participant.update_number(number) | ||
except ProblemChangingNumber, e: | ||
raise Response(400, unicode(e)) | ||
user.participant.update_statement(statement) | ||
|
||
I_AM_MAKING = _("I am making the world better by {0}") | ||
WE_ARE_MAKING = _("We are making the world better by {0}") | ||
|
||
MAKING = I_AM_MAKING if (number == 'singular') else WE_ARE_MAKING | ||
participant.update_statement(statement) | ||
|
||
[---] application/json via json_dump | ||
{"statement": markdown.render(MAKING.format(statement)), "number": wrap(number)} | ||
{"statement": markdown.render(statement)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters