from decimal import Decimal as D

import gittip
from gittip.testing import Harness


class Tests(Harness):

    def make_team(self, name="Team"):
        team = self.make_participant(name)
        team.number = "plural"

        warbucks = self.make_participant('Daddy Warbucks')
        warbucks.last_bill_result = ''
        warbucks.set_tip_to('Team', '100')

        self.session.commit()
        return team

    def make_participant(self, username, *arg, **kw):
        participant = Harness.make_participant(self, username)
        if username == 'alice':
            take_last_week = kw.get('take_last_week', '40')
            gittip.db.run("INSERT INTO paydays DEFAULT VALUES")
            gittip.db.run( "INSERT INTO transfers "
                           "(timestamp, tipper, tippee, amount) "
                           "VALUES (now(), 'Team', 'alice', %s)"
                         , (take_last_week,)
                          )
        return participant

    def test_we_can_make_a_team(self):
        team = self.make_team()
        assert team.IS_PLURAL

    def test_random_schmoe_is_not_member_of_team(self):
        team = self.make_team('Team')
        schmoe = self.make_participant('schmoe')
        assert not schmoe.member_of(team)

    def test_team_member_is_team_member(self):
        team = self.make_team('Team')
        alice = self.make_participant('alice')
        team.add_member(alice)
        assert alice.member_of(team)

    def test_cant_grow_tip_a_lot(self):
        team = self.make_team('Team')
        alice = self.make_participant('alice')
        team._Participant__set_take_for(alice, D('40.00'), team)
        assert team.set_take_for(alice, D('100.00'), alice) == 80

    def test_take_can_double(self):
        team = self.make_team('Team')
        alice = self.make_participant('alice')
        team._Participant__set_take_for(alice, D('40.00'), team)
        team.set_take_for(alice, D('80.00'), alice)
        assert team.get_take_for(alice) == 80

    def test_take_can_double_but_not_a_penny_more(self):
        team = self.make_team('Team')
        alice = self.make_participant('alice')
        team._Participant__set_take_for(alice, D('40.00'), team)
        actual = team.set_take_for(alice, D('80.01'), alice)
        assert actual == 80, actual

    def test_increase_is_based_on_actual_take_last_week(self):
        team = self.make_team('Team')
        alice = self.make_participant('alice', take_last_week='20.00')
        team._Participant__set_take_for(alice, D('35.00'), team)
        assert team.set_take_for(alice, D('42.00'), alice) == 40

    def test_if_last_week_is_less_than_a_dollar_can_increase_to_a_dollar(self):
        team = self.make_team('Team')
        alice = self.make_participant('alice', take_last_week='0.01')
        team.add_member(alice)
        actual = team.set_take_for(alice, D('42.00'), team)
        assert actual == 1, actual

@@ -1,12 +1,53 @@
+from __future__ import unicode_literals%0A%0A
 from decimal
@@ -225,40 +225,26 @@
 name
-)%0A        team.
+, 
 number
- = %22
+='
 plural
-%22
+')
 %0A%0A  
@@ -282,16 +282,17 @@
 icipant(
+ 
 'Daddy W
@@ -299,17 +299,16 @@
 arbucks'
-)
 %0A       
@@ -312,38 +312,104 @@
     
-warbucks.last_bill_result = ''
+                                , last_bill_result=''%0A                                         )
 %0A   
@@ -453,38 +453,8 @@
 ')%0A%0A
-        self.session.commit()%0A
     
@@ -524,16 +524,72 @@
  **kw):%0A
+        take_last_week = kw.pop('take_last_week', '40')%0A
         
@@ -641,16 +641,22 @@
 username
+, **kw
 )%0A      
@@ -685,68 +685,8 @@
 e':%0A
-            take_last_week = kw.get('take_last_week', '40')%0A
     
@@ -1653,35 +1653,33 @@
       team._
-Participant
+MixinTeam
 __set_take_f
@@ -1904,35 +1904,33 @@
       team._
-Participant
+MixinTeam
 __set_take_f
@@ -2208,35 +2208,33 @@
       team._
-Participant
+MixinTeam
 __set_take_f
@@ -2549,19 +2549,17 @@
 am._
-Participant
+MixinTeam
 __se

Fix tests for take