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

Commit

Permalink
Merge pull request #2106 from gittip/fix-delete-elsewhere
Browse files Browse the repository at this point in the history
Fix delete elsewhere
  • Loading branch information
Changaco committed Mar 1, 2014
2 parents bb66d3b + fb11512 commit 21d21ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions gittip/models/participant.py
Expand Up @@ -1020,17 +1020,15 @@ def delete_elsewhere(self, platform, user_id):
AND platform IN %s
""", (self.username, AccountElsewhere.signin_platforms_names))
assert len(accounts) > 0
if not [a for a in accounts if a == (platform, user_id)]:
raise NonexistingElsewhere()
if len(accounts) == 1:
if len(accounts) == 1 and accounts[0] == (platform, user_id):
raise LastElsewhere()
c.one("""
DELETE FROM elsewhere
WHERE participant=%s
AND platform=%s
AND user_id=%s
RETURNING participant
""", (self.username, platform, user_id))
""", (self.username, platform, user_id), default=NonexistingElsewhere)
add_event(c, 'participant', dict(id=self.id, action='disconnect', values=dict(platform=platform, user_id=user_id)))


Expand Down
16 changes: 16 additions & 0 deletions tests/test_participant.py
Expand Up @@ -243,6 +243,22 @@ def test_delete_elsewhere_last(self):
with pytest.raises(LastElsewhere):
alice.delete_elsewhere('twitter', 1)

def test_delete_elsewhere_last_signin(self):
alice = Participant.from_username('alice')
self.make_elsewhere('bountysource', alice.id, 'alice')
with pytest.raises(LastElsewhere):
alice.delete_elsewhere('twitter', 1)

def test_delete_elsewhere_nonsignin(self):
g = self.make_elsewhere('bountysource', 1, 'alice')
alice = Participant.from_username('alice')
alice.take_over(g)
accounts = alice.get_accounts_elsewhere()
assert accounts['twitter'] and accounts['bountysource']
alice.delete_elsewhere('bountysource', 1)
accounts = alice.get_accounts_elsewhere()
assert accounts['twitter'] and accounts.get('bountysource') is None

def test_delete_elsewhere_nonexisting(self):
alice = Participant.from_username('alice')
with pytest.raises(NonexistingElsewhere):
Expand Down

0 comments on commit 21d21ae

Please sign in to comment.