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

Commit

Permalink
Create migrate_tips function
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed May 14, 2015
1 parent 746fde1 commit 60da70d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions gratipay/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ def create_new(cls, owner, fields):
fields['product_or_service'], fields['getting_involved'], fields['getting_paid'],
owner.username))

def migrate_tips(self):
self.db.run("""
INSERT INTO subscriptions
(ctime, mtime, subscriber, team, amount, is_funded)
SELECT ctime
, mtime
, tipper
, %(slug)s
, amount
, is_funded
FROM current_tips
WHERE tippee=%(owner)s
""", {'slug': self.slug, 'owner': self.owner})

9 changes: 7 additions & 2 deletions tests/py/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_error_message_for_slug_collision(self):
def test_migrate_tips_to_subscriptions(self):
alice = self.make_participant('alice', claimed_time='now')
bob = self.make_participant('bob', claimed_time='now')
old_team = self.make_participant('old_team')
self.make_participant('old_team')
alice.set_tip_to('old_team', '1.00')
bob.set_tip_to('old_team', '2.00')
new_team = self.make_team('new_team', owner='old_team')
Expand All @@ -96,7 +96,12 @@ def test_migrate_tips_to_subscriptions(self):

subscriptions = self.db.all("SELECT * FROM subscriptions")
assert len(subscriptions) == 2
# Check for details
assert subscriptions[0].subscriber == 'alice'
assert subscriptions[0].team == 'new_team'
assert subscriptions[0].amount == 1
assert subscriptions[1].subscriber == 'bob'
assert subscriptions[1].team == 'new_team'
assert subscriptions[1].amount == 2


class TestOldTeams(Harness):
Expand Down

0 comments on commit 60da70d

Please sign in to comment.