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

Take over clear balanced_account_uri on absorbed participant. #1903

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions gittip/models/_mixin_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ def take_over(self, account_elsewhere, have_confirmation=False):
cursor.run(ZERO_OUT_OLD_TIPS_RECEIVING, (other_username,))
cursor.run(ZERO_OUT_OLD_TIPS_GIVING, (other_username,))

# Clear payment info.
# ===================
cursor.run("UPDATE participants SET balanced_account_uri = null "
"WHERE username = %s", (self.username,))


# Archive the old participant.
# ============================
Expand Down
19 changes: 18 additions & 1 deletion tests/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import psycopg2
import pytz
import mock
from aspen.utils import utcnow
from gittip import NotSane
from gittip import NotSane, billing
from gittip.elsewhere.bitbucket import BitbucketAccount
from gittip.elsewhere.github import GitHubAccount
from gittip.elsewhere.twitter import TwitterAccount
Expand Down Expand Up @@ -175,6 +176,22 @@ def test_idempotent(self):
alice_participant.take_over(bob, have_confirmation=True)
self.db.self_check()

@mock.patch('gittip.billing.balanced.Account.query')
def test_clear_balanced_account_uri(self, query):
alice = TwitterAccount(self.db, 1, dict(screen_name='alice'))
bob = GitHubAccount(self.db, 2, dict(screen_name='bob'))
alice_participant = alice.opt_in('alice')[0].participant

# set query.filter().one().uri
query.filter.return_value.one.return_value.uri = 'aaa'
billing.get_balanced_account(self.db, 'alice', None)

alice_participant.set_attributes(balanced_account_uri='aaa')
alice_participant.take_over(bob, have_confirmation=True)

# reread from db
new_alice = Participant.from_username('alice')
assert new_alice.balanced_account_uri is None

class TestParticipant(Harness):
def setUp(self):
Expand Down