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.
Expose packages arg in the modify.json endpoint
Only available with the new `start-verification` action.
- Loading branch information
1 parent
2e979de
commit 8799c69
Showing
2 changed files
with
82 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import json | ||
import sys | ||
|
||
import urllib | ||
from pytest import raises | ||
|
||
from gratipay.exceptions import CannotRemovePrimaryEmail, EmailTaken, EmailNotVerified | ||
|
@@ -32,11 +33,21 @@ def add(self, participant, address, _flush=False): | |
|
||
class TestEndpoints(Alice): | ||
|
||
def hit_email_spt(self, action, address, user='alice', should_fail=False): | ||
def hit_email_spt(self, action, address, user='alice', package_ids=[], should_fail=False): | ||
f = self.client.PxST if should_fail else self.client.POST | ||
data = {'action': action, 'address': address} | ||
headers = {b'HTTP_ACCEPT_LANGUAGE': b'en'} | ||
response = f('/~alice/emails/modify.json', data, auth_as=user, **headers) | ||
|
||
# Hack to work around Aspen test client limitations. | ||
data = [ ('action', action) | ||
, ('address', address) | ||
] + [('package_id', str(p)) for p in package_ids] | ||
body = urllib.urlencode(data) | ||
|
||
response = f( '/~alice/emails/modify.json' | ||
, body=body | ||
, content_type=b'application/x-www-form-urlencoded' | ||
, auth_as=user | ||
, HTTP_ACCEPT_LANGUAGE=b'en' | ||
) | ||
if issubclass(response.__class__, (Throttled, ProblemChangingEmail)): | ||
response.render_body({'_': lambda a: a}) | ||
return response | ||
|
@@ -58,8 +69,7 @@ def verify_and_change_email(self, old_email, new_email, username='alice', _flush | |
|
||
def test_participant_can_start_email_verification(self): | ||
response = self.hit_email_spt('add-email', '[email protected]') | ||
actual = json.loads(response.body) | ||
assert actual | ||
assert json.loads(response.body) == 'Check your inbox for a verification link.' | ||
|
||
def test_starting_email_verification_triggers_verification_email(self): | ||
self.hit_email_spt('add-email', '[email protected]') | ||
|
@@ -229,6 +239,54 @@ def test_remove_email(self): | |
self.hit_email_spt('remove', '[email protected]') | ||
|
||
|
||
def test_participant_can_verify_a_package_along_with_email(self): | ||
foo = self.make_package(name='foo', emails=['[email protected]']) | ||
response = self.hit_email_spt( 'start-verification' | ||
, '[email protected]' | ||
, package_ids=[foo.id] | ||
) | ||
assert json.loads(response.body) == 'Check your inbox for a verification link.' | ||
assert self.db.all('select package_id from claims order by package_id') == [foo.id] | ||
|
||
def test_participant_cant_verify_packages_with_add_email_or_resend(self): | ||
foo = self.make_package(name='foo', emails=['[email protected]']) | ||
for action in ('add-email', 'resend'): | ||
assert self.hit_email_spt( action | ||
, '[email protected]' | ||
, package_ids=[foo.id] | ||
, should_fail=True | ||
).code == 400 | ||
|
||
def test_participant_can_verify_multiple_packages_along_with_email(self): | ||
package_ids = [self.make_package(name=name, emails=['[email protected]']).id | ||
for name in ('foo', 'bar', 'baz', 'buz')] | ||
response = self.hit_email_spt( 'start-verification' | ||
, '[email protected]' | ||
, package_ids=package_ids | ||
) | ||
assert json.loads(response.body) == 'Check your inbox for a verification link.' | ||
assert self.db.all('select package_id from claims order by package_id') == package_ids | ||
|
||
def test_package_verification_fails_if_email_not_listed(self): | ||
foo = self.make_package() | ||
response = self.hit_email_spt( 'start-verification' | ||
, '[email protected]' | ||
, package_ids=[foo.id] | ||
, should_fail=True | ||
) | ||
assert response.code == 400 | ||
assert self.db.all('select package_id from claims order by package_id') == [] | ||
|
||
def test_package_verification_fails_package_id_is_garbage(self): | ||
response = self.hit_email_spt( 'start-verification' | ||
, '[email protected]' | ||
, package_ids=['cheese monkey'] | ||
, should_fail=True | ||
) | ||
assert response.code == 400 | ||
assert self.db.all('select package_id from claims order by package_id') == [] | ||
|
||
|
||
class TestFunctions(Alice): | ||
|
||
def test_cannot_update_email_to_already_verified(self): | ||
|
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