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

Fix delete elsewhere #2106

Merged
merged 3 commits into from
Mar 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions gittip/models/participant.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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