Example #1
0
 def test_format_money_without_trailing_zeroes(self):
     result = LOCALE_EN.format_money(Money(16, 'USD'),
                                     trailing_zeroes=False)
     assert result == '$16'
     result = LOCALE_EN.format_money(Money(5555, 'KRW'),
                                     trailing_zeroes=False)
     assert result == '₩5,555'
Example #2
0
def get_money_amount(d, k, currency, default=NO_DEFAULT):
    try:
        r = d[k]
    except (KeyError, Response):
        if default is NO_DEFAULT:
            raise
        return default
    return LOCALE_EN.parse_money_amount(r, currency)
Example #3
0
 def test_parse_money_amount_rejects_ambiguous_numbers(self):
     with self.assertRaises(AmbiguousNumber):
         LOCALE_EN.parse_money_amount("10,00", 'EUR')
Example #4
0
 def test_parse_money_amount_rejects_irregular_numbers(self):
     with self.assertRaises(AmbiguousNumber):
         LOCALE_EN.parse_money_amount(",100,100", 'USD')
Example #5
0
 def test_parse_money_amount_rejects_overly_precise_numbers(self):
     with self.assertRaises(InvalidNumber):
         LOCALE_EN.parse_money_amount("100.00001", 'EUR')
Example #6
0
 def test_format_money_defaults_to_trailing_zeroes(self):
     result = LOCALE_EN.format_money(Money(16, 'USD'))
     assert result == '$16.00'
     result = LOCALE_EN.format_money(Money(5555, 'KRW'))
     assert result == '₩5,555'
Example #7
0
 def test_format_currency_defaults_to_trailing_zeroes(self):
     expected = '$16.00'
     actual = LOCALE_EN.format_money(Money(16, 'USD'))
     assert actual == expected
Example #8
0
 def test_schedule_renewals_finds_partial_matches(self):
     """
     This test is designed to hit the `find_partial_match` function inside
     `Participant.schedule_renewals`.
     """
     alice = self.make_participant('alice', email='*****@*****.**')
     bob = self.make_participant('bob', email='*****@*****.**')
     team = self.make_participant('team',
                                  kind='group',
                                  email='*****@*****.**')
     team.add_member(bob)
     alice.set_tip_to(bob, EUR('1.00'), renewal_mode=2)
     alice.set_tip_to(team, EUR('1.50'), renewal_mode=2)
     alice_card = self.upsert_route(alice,
                                    'stripe-card',
                                    address='pm_card_visa')
     self.make_payin_and_transfer(alice_card, bob, EUR('2.00'))
     self.make_payin_and_transfer(alice_card, team, EUR('3.00'))
     new_schedule = alice.schedule_renewals()
     next_payday = compute_next_payday_date()
     expected_transfers = [{
         'tippee_id': bob.id,
         'tippee_username': '******',
         'amount': EUR('2.00'),
     }, {
         'tippee_id': team.id,
         'tippee_username': '******',
         'amount': EUR('3.00'),
     }]
     assert len(new_schedule) == 1
     assert new_schedule[0].amount == EUR('5.00')
     assert new_schedule[0].transfers == expected_transfers
     expected_renewal_date = next_payday + timedelta(weeks=1)
     assert new_schedule[0].execution_date == expected_renewal_date
     assert new_schedule[0].automatic is True
     # Trigger the initial "upcoming charge" notification
     self.db.run(
         "UPDATE scheduled_payins SET ctime = ctime - interval '12 hours'")
     send_upcoming_debit_notifications()
     emails = self.get_emails()
     assert len(emails) == 1
     assert emails[0]['to'][0] == 'alice <*****@*****.**>'
     assert emails[0][
         'subject'] == 'Liberapay donation renewal: upcoming debit of €5.00'
     sp = self.db.one("SELECT * FROM scheduled_payins WHERE payin IS NULL")
     assert sp.notifs_count == 1
     # Tweak the amount of the first donation. The renewal shouldn't be
     # pushed back and the payer shouldn't be notified.
     alice.set_tip_to(bob, EUR('0.50'))
     new_schedule = alice.schedule_renewals()
     assert len(new_schedule) == 1
     assert new_schedule[0].amount == EUR('5.00')
     assert new_schedule[0].transfers == expected_transfers
     assert new_schedule[0].execution_date == expected_renewal_date
     assert new_schedule[0].automatic is True
     emails = self.get_emails()
     assert not emails
     # Stop the second donation. The renewal should be rescheduled and the
     # payer should be notified of that change.
     alice.stop_tip_to(team)
     new_schedule = alice.schedule_renewals()
     assert len(new_schedule) == 1
     assert new_schedule[0].amount == EUR('2.00')
     assert new_schedule[0].transfers == [expected_transfers[0]]
     previous_renewal_date = expected_renewal_date
     expected_renewal_date = next_payday + timedelta(weeks=3)
     assert new_schedule[0].execution_date == expected_renewal_date
     assert new_schedule[0].automatic is True
     emails = self.get_emails()
     assert len(emails) == 1
     assert emails[0]['to'][0] == 'alice <*****@*****.**>'
     assert emails[0][
         'subject'] == 'Liberapay donation renewal: your upcoming payment has changed'
     expected_sentence = LOCALE_EN.format(
         "The payment of €5.00 scheduled for {old_date} has been replaced by "
         "a payment of €2.00 on {new_date}.",
         old_date=previous_renewal_date,
         new_date=expected_renewal_date)
     assert expected_sentence in emails[0]['text']
Example #9
0
 def test_format_currency_without_trailing_zeroes(self):
     expected = '$16'
     actual = LOCALE_EN.format_money(Money(16, 'USD'), trailing_zeroes=False)
     assert actual == expected
Example #10
0
 def test_parse_money_amount_rejects_ambiguous_numbers(self):
     with self.assertRaises(AmbiguousNumber):
         LOCALE_EN.parse_money_amount("10,00", 'EUR')
Example #11
0
 def test_parse_money_amount_rejects_irregular_numbers(self):
     with self.assertRaises(AmbiguousNumber):
         LOCALE_EN.parse_money_amount(",100,100", 'USD')
Example #12
0
 def test_parse_money_amount_rejects_overly_precise_numbers(self):
     with self.assertRaises(InvalidNumber):
         LOCALE_EN.parse_money_amount("100.00001", 'EUR')
Example #13
0
 def test_format_currency_defaults_to_trailing_zeroes(self):
     expected = '$16.00'
     actual = LOCALE_EN.format_money(Money(16, 'USD'))
     assert actual == expected
Example #14
0
 def test_format_currency_without_trailing_zeroes(self):
     expected = '$16'
     actual = LOCALE_EN.format_money(Money(16, 'USD'), trailing_zeroes=False)
     assert actual == expected