1 from decimal import Decimal
3 from unittest import TestCase
4 from bluechips import model
5 from bluechips.model import meta
6 from bluechips.model.types import Currency
8 class TestExpenditure(TestCase):
10 self.u = model.User(u'chaz', u'Charles Root', False)
11 self.e = model.Expenditure(self.u, Currency('444.88'),
13 meta.Session.add(self.u)
14 meta.Session.add(self.e)
17 def test_constructor(self):
18 assert self.e.spender == self.u
19 assert self.e.amount == Currency('444.88')
20 assert self.e.description == u'chaz buys lunch'
23 assert (repr(self.e) ==
24 '<Expenditure: spender: Charles Root spent: $444.88>')
26 def test_even_split(self):
29 for sp in self.e.splits:
30 assert sp.share == Currency('111.22')
32 def test_split_change_to_zero(self):
36 split_dict[self.u] = Decimal(1)
37 self.e.split(split_dict)
39 def _two_way_split_test(self, amount, min, max):
40 e2 = model.Expenditure(self.u, amount,
42 u2 = model.User(u'bo', u'Bo Jangles', False)
47 split_dict[self.u] = Decimal(1)
48 split_dict[u2] = Decimal(1)
50 assert min <= e2.share(u2) <= max
51 meta.Session.delete(e2)
52 meta.Session.delete(u2)
55 def test_split_rounds_down(self):
56 self._two_way_split_test(Currency('40.01'),
60 def test_split_rounds_up(self):
61 self._two_way_split_test(Currency('39.99'),
65 def test_split_small(self):
66 self._two_way_split_test(Currency('0.01'),
70 def test_split_small_negative(self):
71 self._two_way_split_test(Currency('-0.01'),
76 meta.Session.delete(self.e)
77 meta.Session.delete(self.u)