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

Commit

Permalink
Fill out the test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 12, 2016
1 parent 6b30b0d commit a8901bf
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 13 deletions.
91 changes: 85 additions & 6 deletions tests/py/test_identity_pages.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
from gratipay.testing import Harness
from gratipay.models.country import Country
from gratipay.models.participant import Participant


class Tests(Harness):

def setUp(self):
self.alice = self.make_participant('alice', claimed_time='now', is_admin=True)
self.bob = self.make_participant('bob', claimed_time='now')
self.make_participant('alice', claimed_time='now', is_admin=True)
self.make_participant('bob', claimed_time='now', email_address='[email protected]')
self.verify('bob', 'TT')

def identify(self, username, *codes):
participant = Participant.from_username(username)
for code in codes:
country_id = Country.from_code(code).id
participant.store_identity_info(country_id, 'nothing-enforced', {})
return participant

def verify(self, username, *codes):
participant = Participant.from_username(username)
for code in codes:
country_id = Country.from_code(code).id
participant.store_identity_info(country_id, 'nothing-enforced', {})
participant.set_identity_verification(country_id, True)
return participant


# il - identities listing
Expand All @@ -17,7 +35,7 @@ def test_il_is_403_for_non_admin(self):
assert self.client.GxT('/~bob/identities/').code == 403

def test_il_is_200_for_self(self):
assert self.client.GET('/~bob/identities/', auth_as='alice').code == 200
assert self.client.GET('/~bob/identities/', auth_as='bob').code == 200

def test_il_is_200_for_admin(self):
assert self.client.GET('/~bob/identities/', auth_as='alice').code == 200
Expand All @@ -32,10 +50,71 @@ def test_ip_is_403_for_non_admin(self):
assert self.client.GxT('/~bob/identities/TT').code == 403

def test_ip_is_200_for_self(self):
assert self.client.GET('/~bob/identities/TT', auth_as='alice').code == 200
assert self.client.GET('/~bob/identities/TT', auth_as='bob').code == 200

def test_ip_is_200_for_admin(self):
assert self.client.GET('/~bob/identities/TT', auth_as='alice').code == 200

def test_ip_(self):
pass
def test_ip_is_404_for_unknown_code(self):
assert self.client.GxT('/~bob/identities/XX', auth_as='bob').code == 404

def test_ip_is_302_if_no_verified_email(self):
response = self.client.GxT('/~alice/identities/TT', auth_as='alice')
assert response.code == 302
assert response.headers['Location'] == '/about/me/emails/'


def test_ip_is_200_for_third_identity(self):
self.verify('bob', 'TT', 'US')
assert self.client.GET('/~bob/identities/US', auth_as='bob').code == 200

def test_ip_is_302_for_fourth_identity(self):
self.verify('bob', 'TT', 'US', 'GB')
assert self.client.GxT('/~bob/identities/CA', auth_as='bob').code == 302

def test_ip_is_302_for_fifth_identities(self):
self.verify('bob', 'TT', 'US', 'GB', 'GH')
assert self.client.GxT('/~bob/identities/CA', auth_as='bob').code == 302

def test_but_ip_always_loads_for_own_identity(self):
self.verify('bob', 'TT', 'US', 'GB', 'GH')
assert self.client.GET('/~bob/identities/TT', auth_as='bob').code == 200

def test_ip_always_loads_for_own_identity_even_if_unverified(self):
self.verify('bob', 'US', 'GB', 'GH')
self.identify('bob', 'TT')
assert self.client.GET('/~bob/identities/TT', auth_as='bob').code == 200


def test_ip_removes_identity(self):
bob = self.verify('bob', 'TT')
assert len(bob.list_identity_metadata()) == 1
data = {'action': 'remove'}
assert self.client.PxST('/~bob/identities/TT', auth_as='bob', data=data).code == 302
assert len(bob.list_identity_metadata()) == 0

def test_ip_stores_identity(self):
bob = Participant.from_username('bob')
assert len(bob.list_identity_metadata()) == 1
data = { 'id_type': ''
, 'id_number': ''
, 'legal_name': 'Bobsworth B. Bobbleton, IV'
, 'dob': ''
, 'address_1': ''
, 'address_2': ''
, 'city': ''
, 'region': ''
, 'postcode': ''
, 'action': 'store'
}
assert self.client.PxST('/~bob/identities/US', auth_as='bob', data=data).code == 302
assert len(bob.list_identity_metadata()) == 2
info = bob.retrieve_identity_info(Country.from_code('US').id)
assert info['legal_name'] == 'Bobsworth B. Bobbleton, IV'

def test_ip_validates_action(self):
bob = Participant.from_username('bob')
assert len(bob.list_identity_metadata()) == 1
data = {'action': 'cheese'}
assert self.client.PxST('/~bob/identities/TT', auth_as='bob', data=data).code == 400
assert len(bob.list_identity_metadata()) == 1
16 changes: 9 additions & 7 deletions www/~/%username/identities/%country.spt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ from gratipay.models.country import Country
[---]
participant = get_participant(state, restrict=True)

# require email
if not participant.email_address:
website.redirect('/about/me/emails/')

# load country
country = request.path['country']
if country not in locale.countries:
country_code = request.path['country']
country = Country.from_code(country_code)
title = locale.countries.get(country_code)
if country is None or title is None:
raise Response(404)
country = Country.from_code(country)
title = locale.countries[country.code]

# load identity & info
# load identities & info
identity = None
info = {}
identities = participant.list_identity_metadata()
Expand All @@ -30,8 +34,6 @@ if request.method == 'POST':
if action == 'remove':
participant.clear_identity(country.id)
elif action == 'store':
if identity is None and nidentities > 3:
raise Response(400, 'Only three identities allowed.') # How'd you get here?
info = {}
info['id_type'] = request.body['id_type']
info['id_number'] = request.body['id_number']
Expand Down

0 comments on commit a8901bf

Please sign in to comment.