Skip to content

Commit

Permalink
update set_tip_to() calls in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Oct 29, 2017
1 parent c0ded5c commit f6376ee
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 169 deletions.
3 changes: 0 additions & 3 deletions liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,9 +1561,6 @@ def set_tip_to(self, tippee, periodic_amount, period='weekly',
if self.id == tippee.id:
raise NoSelfTipping

if not isinstance(periodic_amount, Money):
# TODO drop this
periodic_amount = Money(periodic_amount, 'EUR')
amount = periodic_amount * PERIOD_CONVERSION_RATES[period]

if periodic_amount != 0:
Expand Down
5 changes: 5 additions & 0 deletions liberapay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from os.path import dirname, join, realpath

from aspen import resources
from mangopay.utils import Money
from pando.utils import utcnow
from pando.testing.client import Client
from psycopg2 import IntegrityError, InternalError
Expand All @@ -31,6 +32,10 @@
PROJECT_ROOT = str(TOP)


def EUR(amount):
return Money(amount, 'EUR')


class ClientWithAuth(Client):

def __init__(self, *a, **kw):
Expand Down
7 changes: 4 additions & 3 deletions tests/py/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from liberapay.billing.transactions import Money, record_exchange
from liberapay.models.exchange_route import ExchangeRoute
from liberapay.security.csrf import CSRF_TOKEN
from liberapay.testing import EUR
from liberapay.testing.emails import EmailHarness
from liberapay.testing.mangopay import fake_transfer, FakeTransfersHarness, MangopayHarness
from liberapay.utils import utcnow
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_dispute_callback_lost(self, save, get_payin, get_dispute):
payin = PayIn(tag=str(e_id))
get_payin.return_value = payin
# Transfer some of the money to homer
self.janet.set_tip_to(self.homer, D('3.68'))
self.janet.set_tip_to(self.homer, EUR('3.68'))
Payday.start().run()
# Withdraw some of the money
self.make_exchange('mango-ba', D('-2.68'), 0, self.homer)
Expand Down Expand Up @@ -100,7 +101,7 @@ def test_dispute_callback_won(self, save, get_payin, get_dispute):
payin = PayIn(tag=str(e_id))
get_payin.return_value = payin
# Transfer some of the money to homer
self.janet.set_tip_to(self.homer, D('3.68'))
self.janet.set_tip_to(self.homer, EUR('3.68'))
Payday.start().run()
# Withdraw some of the money
self.make_exchange('mango-ba', D('-2.68'), 0, self.homer)
Expand Down Expand Up @@ -267,7 +268,7 @@ def test_payin_bank_wire_callback_unexpected(self, Get):
)
for status, result_code, error, fee in cases:
status_up = status.upper()
homer.set_tip_to(self.janet, D('1.00'))
homer.set_tip_to(self.janet, EUR('1.00'))
homer.close('downstream')
assert homer.balance == 0
assert homer.status == 'closed'
Expand Down
19 changes: 10 additions & 9 deletions tests/py/test_charts_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pando.utils import utcnow

from liberapay.billing.payday import Payday
from liberapay.testing import EUR
from liberapay.testing.mangopay import FakeTransfersHarness


Expand All @@ -25,8 +26,8 @@ def setUp(self):
self.make_exchange('mango-cc', 10, 0, self.bob)
self.make_participant('notactive')

self.alice.set_tip_to(self.carl, '1.00')
self.bob.set_tip_to(self.carl, '2.00')
self.alice.set_tip_to(self.carl, EUR('1.00'))
self.bob.set_tip_to(self.carl, EUR('2.00'))

def run_payday(self):
Payday.start().run(recompute_stats=1)
Expand All @@ -46,8 +47,8 @@ def test_first_payday_comes_through(self):
def test_second_payday_comes_through(self):
self.run_payday() # first

self.alice.set_tip_to(self.carl, '5.00')
self.bob.set_tip_to(self.carl, '0.00')
self.alice.set_tip_to(self.carl, EUR('5.00'))
self.bob.set_tip_to(self.carl, EUR('0.00'))

self.run_payday() # second

Expand All @@ -63,12 +64,12 @@ def test_sandwiched_tipless_payday_comes_through(self):
self.run_payday() # first

# Oops! Sorry, Carl. :-(
self.alice.set_tip_to(self.carl, '0.00')
self.bob.set_tip_to(self.carl, '0.00')
self.alice.set_tip_to(self.carl, EUR('0.00'))
self.bob.set_tip_to(self.carl, EUR('0.00'))
self.run_payday() # second

# Bouncing back ...
self.alice.set_tip_to(self.carl, '5.00')
self.alice.set_tip_to(self.carl, EUR('5.00'))
self.run_payday() # third

expected = [
Expand Down Expand Up @@ -124,8 +125,8 @@ def test_charts_work_for_teams(self):
team = self.make_participant('team', kind='group')
team.set_take_for(self.bob, 0.1, team)
team.set_take_for(self.carl, 1, team)
self.alice.set_tip_to(team, '0.30')
self.bob.set_tip_to(team, '0.59')
self.alice.set_tip_to(team, EUR('0.30'))
self.bob.set_tip_to(team, EUR('0.59'))

self.run_payday()

Expand Down
65 changes: 33 additions & 32 deletions tests/py/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from liberapay.billing.payday import Payday
from liberapay.models.community import Community
from liberapay.models.participant import Participant
from liberapay.testing import EUR
from liberapay.testing.mangopay import FakeTransfersHarness


Expand All @@ -21,8 +22,8 @@ def test_close_closes(self):
bob = self.make_participant('bob')
carl = self.make_participant('carl')

alice.set_tip_to(bob, D('3.00'))
carl.set_tip_to(alice, D('2.00'))
alice.set_tip_to(bob, EUR('3.00'))
carl.set_tip_to(alice, EUR('2.00'))

team.add_member(alice)
team.add_member(bob)
Expand Down Expand Up @@ -54,7 +55,7 @@ def test_close_page_is_not_available_during_payday(self):
def test_can_post_to_close_page(self):
alice = self.make_participant('alice', balance=7)
bob = self.make_participant('bob')
alice.set_tip_to(bob, D('10.00'))
alice.set_tip_to(bob, EUR('10.00'))

data = {'disburse_to': 'downstream'}
response = self.client.PxST('/alice/settings/close', auth_as=alice, data=data)
Expand All @@ -76,8 +77,8 @@ def test_dbafg_distributes_balance_as_final_gift(self):
alice = self.make_participant('alice', balance=D('10.00'))
bob = self.make_participant('bob')
carl = self.make_participant('carl')
alice.set_tip_to(bob, D('3.00'))
alice.set_tip_to(carl, D('2.00'))
alice.set_tip_to(bob, EUR('3.00'))
alice.set_tip_to(carl, EUR('2.00'))
with self.db.get_cursor() as cursor:
alice.distribute_balance_as_final_gift(cursor)
assert Participant.from_username('bob').balance == D('6.00')
Expand All @@ -88,8 +89,8 @@ def test_dbafg_needs_claimed_tips(self):
alice = self.make_participant('alice', balance=D('10.00'))
bob = self.make_stub()
carl = self.make_stub()
alice.set_tip_to(bob, D('3.00'))
alice.set_tip_to(carl, D('2.00'))
alice.set_tip_to(bob, EUR('3.00'))
alice.set_tip_to(carl, EUR('2.00'))
with self.db.get_cursor() as cursor:
with pytest.raises(alice.NoOneToGiveFinalGiftTo):
alice.distribute_balance_as_final_gift(cursor)
Expand All @@ -101,8 +102,8 @@ def test_dbafg_gives_all_to_claimed(self):
alice = self.make_participant('alice', balance=D('10.00'))
bob = self.make_participant('bob')
carl = self.make_stub()
alice.set_tip_to(bob, D('3.00'))
alice.set_tip_to(carl, D('2.00'))
alice.set_tip_to(bob, EUR('3.00'))
alice.set_tip_to(carl, EUR('2.00'))
with self.db.get_cursor() as cursor:
alice.distribute_balance_as_final_gift(cursor)
assert Participant.from_id(bob.id).balance == D('10.00')
Expand All @@ -113,8 +114,8 @@ def test_dbafg_skips_zero_tips(self):
alice = self.make_participant('alice', balance=D('10.00'))
bob = self.make_participant('bob')
carl = self.make_participant('carl')
alice.set_tip_to(bob, D('0.00'))
alice.set_tip_to(carl, D('2.00'))
alice.set_tip_to(bob, EUR('0.00'))
alice.set_tip_to(carl, EUR('2.00'))
with self.db.get_cursor() as cursor:
alice.distribute_balance_as_final_gift(cursor)
assert self.db.one("SELECT count(*) FROM tips WHERE tippee=%s", (bob.id,)) == 1
Expand All @@ -126,8 +127,8 @@ def test_dbafg_favors_highest_tippee_in_rounding_errors(self):
alice = self.make_participant('alice', balance=D('10.00'))
bob = self.make_participant('bob')
carl = self.make_participant('carl')
alice.set_tip_to(bob, D('3.00'))
alice.set_tip_to(carl, D('6.00'))
alice.set_tip_to(bob, EUR('3.00'))
alice.set_tip_to(carl, EUR('6.00'))
with self.db.get_cursor() as cursor:
alice.distribute_balance_as_final_gift(cursor)
assert Participant.from_username('bob').balance == D('3.33')
Expand All @@ -138,8 +139,8 @@ def test_dbafg_with_zero_balance_is_a_noop(self):
alice = self.make_participant('alice', balance=D('0.00'))
bob = self.make_participant('bob')
carl = self.make_participant('carl')
alice.set_tip_to(bob, D('3.00'))
alice.set_tip_to(carl, D('6.00'))
alice.set_tip_to(bob, EUR('3.00'))
alice.set_tip_to(carl, EUR('6.00'))
with self.db.get_cursor() as cursor:
alice.distribute_balance_as_final_gift(cursor)
assert self.db.one("SELECT count(*) FROM tips") == 2
Expand All @@ -152,7 +153,7 @@ def test_dbafg_distributes_to_team(self):
alice = self.make_participant('alice', balance=D('0.01'))
bob = self.make_participant('bob')
carl = self.make_participant('carl')
alice.set_tip_to(team, D('3.00'))
alice.set_tip_to(team, EUR('3.00'))
team.set_take_for(alice, 1, team)
team.set_take_for(bob, 1, team)
team.set_take_for(carl, D('0.01'), team)
Expand All @@ -167,7 +168,7 @@ def test_dbafg_distributes_to_team(self):

def test_ctg_clears_tips_giving(self):
alice = self.make_participant('alice')
alice.set_tip_to(self.make_participant('bob'), D('1.00'))
alice.set_tip_to(self.make_participant('bob'), EUR('1.00'))
ntips = lambda: self.db.one("SELECT count(*) FROM current_tips "
"WHERE tipper=%s AND amount > 0",
(alice.id,))
Expand All @@ -179,8 +180,8 @@ def test_ctg_clears_tips_giving(self):
def test_ctg_doesnt_duplicate_zero_tips(self):
alice = self.make_participant('alice')
bob = self.make_stub()
alice.set_tip_to(bob, D('1.00'))
alice.set_tip_to(bob, D('0.00'))
alice.set_tip_to(bob, EUR('1.00'))
alice.set_tip_to(bob, EUR('0.00'))
ntips = lambda: self.db.one("SELECT count(*) FROM tips WHERE tipper=%s", (alice.id,))
assert ntips() == 2
with self.db.get_cursor() as cursor:
Expand All @@ -197,11 +198,11 @@ def test_ctg_doesnt_zero_when_theres_no_tip(self):

def test_ctg_clears_multiple_tips_giving(self):
alice = self.make_participant('alice')
alice.set_tip_to(self.make_participant('bob'), D('1.00'))
alice.set_tip_to(self.make_participant('carl'), D('1.00'))
alice.set_tip_to(self.make_participant('darcy'), D('1.00'))
alice.set_tip_to(self.make_participant('evelyn'), D('1.00'))
alice.set_tip_to(self.make_participant('francis'), D('1.00'))
alice.set_tip_to(self.make_participant('bob'), EUR('1.00'))
alice.set_tip_to(self.make_participant('carl'), EUR('1.00'))
alice.set_tip_to(self.make_participant('darcy'), EUR('1.00'))
alice.set_tip_to(self.make_participant('evelyn'), EUR('1.00'))
alice.set_tip_to(self.make_participant('francis'), EUR('1.00'))
ntips = lambda: self.db.one("SELECT count(*) FROM current_tips "
"WHERE tipper=%s AND amount > 0",
(alice.id,))
Expand All @@ -215,7 +216,7 @@ def test_ctg_clears_multiple_tips_giving(self):

def test_ctr_clears_tips_receiving(self):
alice = self.make_participant('alice')
self.make_participant('bob').set_tip_to(alice, D('1.00'))
self.make_participant('bob').set_tip_to(alice, EUR('1.00'))
ntips = lambda: self.db.one("SELECT count(*) FROM current_tips "
"WHERE tippee=%s AND amount > 0",
(alice.id,))
Expand All @@ -227,8 +228,8 @@ def test_ctr_clears_tips_receiving(self):
def test_ctr_doesnt_duplicate_zero_tips(self):
alice = self.make_participant('alice')
bob = self.make_participant('bob')
bob.set_tip_to(alice, D('1.00'))
bob.set_tip_to(alice, D('0.00'))
bob.set_tip_to(alice, EUR('1.00'))
bob.set_tip_to(alice, EUR('0.00'))
ntips = lambda: self.db.one("SELECT count(*) FROM tips WHERE tippee=%s", (alice.id,))
assert ntips() == 2
with self.db.get_cursor() as cursor:
Expand All @@ -245,11 +246,11 @@ def test_ctr_doesnt_zero_when_theres_no_tip(self):

def test_ctr_clears_multiple_tips_receiving(self):
alice = self.make_stub()
self.make_participant('bob').set_tip_to(alice, D('1.00'))
self.make_participant('carl').set_tip_to(alice, D('2.00'))
self.make_participant('darcy').set_tip_to(alice, D('3.00'))
self.make_participant('evelyn').set_tip_to(alice, D('4.00'))
self.make_participant('francis').set_tip_to(alice, D('5.00'))
self.make_participant('bob').set_tip_to(alice, EUR('1.00'))
self.make_participant('carl').set_tip_to(alice, EUR('2.00'))
self.make_participant('darcy').set_tip_to(alice, EUR('3.00'))
self.make_participant('evelyn').set_tip_to(alice, EUR('4.00'))
self.make_participant('francis').set_tip_to(alice, EUR('5.00'))
ntips = lambda: self.db.one("SELECT count(*) FROM current_tips "
"WHERE tippee=%s AND amount > 0",
(alice.id,))
Expand Down
4 changes: 2 additions & 2 deletions tests/py/test_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from liberapay.elsewhere._base import UserInfo
from liberapay.models.account_elsewhere import AccountElsewhere
from liberapay.testing import Harness
from liberapay.testing import EUR, Harness
import liberapay.testing.elsewhere as user_info_examples
from liberapay.utils import b64encode_s

Expand Down Expand Up @@ -117,7 +117,7 @@ def test_user_page_shows_pledges(self, get_user_info):
alice = self.make_elsewhere('github', 1, 'alice').participant
bob = self.make_participant('bob', balance=100)
amount = D('14.97')
bob.set_tip_to(alice, amount)
bob.set_tip_to(alice, EUR(amount))
assert alice.receiving == amount
r = self.client.GET('/on/github/alice/')
assert str(amount) in r.text, r.text
Expand Down
5 changes: 3 additions & 2 deletions tests/py/test_email_notifs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from liberapay.models.participant import Participant
from liberapay.testing import EUR
from liberapay.testing.emails import EmailHarness


Expand All @@ -13,8 +14,8 @@ def setUp(self):
def test_take_over_sends_notifications_to_patrons(self):
dan_twitter = self.make_elsewhere('twitter', 1, 'dan')

self.alice.set_tip_to(self.dan, '100') # Alice shouldn't receive an email.
self.bob.set_tip_to(dan_twitter, '100') # Bob should receive an email.
self.alice.set_tip_to(self.dan, EUR('100')) # Alice shouldn't receive an email.
self.bob.set_tip_to(dan_twitter, EUR('100')) # Bob should receive an email.

self.dan.take_over(dan_twitter, have_confirmation=True)

Expand Down
6 changes: 3 additions & 3 deletions tests/py/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from liberapay.billing.payday import Payday
from liberapay.models.participant import Participant
from liberapay.testing import Harness
from liberapay.testing import EUR, Harness
from liberapay.testing.mangopay import FakeTransfersHarness
from liberapay.utils.history import get_end_of_year_balance, iter_payday_events

Expand Down Expand Up @@ -53,9 +53,9 @@ def test_iter_payday_events(self):
carl = self.make_participant('carl')
david = self.make_participant('david')
self.make_exchange('mango-cc', 10000, 0, david)
david.set_tip_to(team, Decimal('1.00'))
david.set_tip_to(team, EUR('1.00'))
team.set_take_for(bob, Decimal('1.00'), team)
alice.set_tip_to(bob, Decimal('5.00'))
alice.set_tip_to(bob, EUR('5.00'))

assert bob.balance == 0
for i in range(2):
Expand Down
Loading

0 comments on commit f6376ee

Please sign in to comment.