From 60da70d9041ff56b8850666d230df2bfd6b33c81 Mon Sep 17 00:00:00 2001 From: Rohit Paul Kuruvilla Date: Thu, 14 May 2015 23:48:37 +0530 Subject: [PATCH] Create migrate_tips function --- gratipay/models/team.py | 16 ++++++++++++++++ tests/py/test_teams.py | 9 +++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gratipay/models/team.py b/gratipay/models/team.py index 63b7b40aa0..24f9906d5d 100644 --- a/gratipay/models/team.py +++ b/gratipay/models/team.py @@ -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}) + diff --git a/tests/py/test_teams.py b/tests/py/test_teams.py index 37fb2a6b6a..23626c3d07 100644 --- a/tests/py/test_teams.py +++ b/tests/py/test_teams.py @@ -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') @@ -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):