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

Commit

Permalink
implement clearing identities
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 11, 2016
1 parent 84ab83b commit c3abaf4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions gratipay/models/participant/mixins/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,30 @@ def set_identity_verification(self, country_id, is_verified):
add_event(cursor, 'participant', payload)


def clear_identity(self, country_id):
"""Clear the participant's national identity record for a given country.
:param int country_id: an ``id`` from the ``countries`` table
"""
with self.db.get_cursor() as cursor:
identity_id = cursor.one("""
DELETE
FROM participant_identities
WHERE participant_id=%(participant_id)s
AND country_id=%(country_id)s
RETURNING id
""", dict(locals(), participant_id=self.id))
payload = dict( id=self.id
, identity_id=identity_id
, country_id=country_id
, action='clear identity'
)
add_event(cursor, 'participant', payload)


# Rekeying
# ========

Expand Down
25 changes: 25 additions & 0 deletions tests/py/test_participant_identities.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,31 @@ def test_siv_still_logs_an_event_when_noop(self):
)


# ci - clear_identity

def test_ci_clears_identity(self):
self.crusher.store_identity_info(self.TT, 'nothing-enforced', {'name': 'Crusher'})
assert self.crusher.clear_identity(self.TT) is None
assert self.crusher.list_identity_metadata() == []

def test_ci_is_a_noop_when_there_is_no_identity(self):
assert self.crusher.clear_identity(self.TT) is None
assert self.crusher.list_identity_metadata() == []

def test_ci_logs_an_event(self):
iid = self.crusher.store_identity_info(self.TT, 'nothing-enforced', {'name': 'Crusher'})
self.crusher.clear_identity(self.TT)
self.assert_events( self.crusher.id
, [iid, iid]
, [self.TT, self.TT]
, ['insert identity', 'clear identity']
)

def test_ci_still_logs_an_event_when_noop(self):
self.crusher.clear_identity(self.TT)
self.assert_events(self.crusher.id, [None], [self.TT], ['clear identity'])


# fine - fail_if_no_email

def test_fine_fails_if_no_email(self):
Expand Down

0 comments on commit c3abaf4

Please sign in to comment.