Пример #1
0
 def setUp(self):
     self.u = model.User(u'chaz', u'Charles Root', False)
     self.e = model.Expenditure(self.u, Currency('444.88'),
                                u'chaz buys lunch')
     meta.Session.add(self.u)
     meta.Session.add(self.e)
     meta.Session.commit()
Пример #2
0
 def test_split_irrational_rounding(self):
     e2 = model.Expenditure(self.u, Decimal('2375.00'), u'rounding test')
     u2 = model.User(u'rat', u'Irrational Rat', False)
     meta.Session.add(u2)
     meta.Session.add(e2)
     meta.Session.commit()
     split_dict = {}
     split_dict[u2] = Decimal('750.00')
     split_dict[self.u] = Decimal('4000.00')
     e2.split(split_dict)
     assert e2.share(u2) == Decimal('375.00')
     meta.Session.delete(e2)
     meta.Session.delete(u2)
     meta.Session.commit()
Пример #3
0
 def _two_way_split_test(self, amount, min, max):
     e2 = model.Expenditure(self.u, amount, u'testing splits')
     u2 = model.User(u'bo', u'Bo Jangles', False)
     meta.Session.add(u2)
     meta.Session.add(e2)
     meta.Session.commit()
     split_dict = {}
     split_dict[self.u] = Decimal(1)
     split_dict[u2] = Decimal(1)
     e2.split(split_dict)
     assert min <= e2.share(u2) <= max
     meta.Session.delete(e2)
     meta.Session.delete(u2)
     meta.Session.commit()
Пример #4
0
    def test_simpleSplit(self):
        """
        Test simply splitting a $100 expenditure amongst 4 people
        """
        createUsers(4)

        e = model.Expenditure(
            meta.Session.query(model.User).first(), Currency("100"))
        meta.Session.add(e)
        e.even_split()
        meta.Session.commit()

        for s in meta.Session.query(model.Split).\
                filter(model.Split.expenditure==e):
            self.assertEqual(s.share, Currency("25.00"))

        deleteExpenditures()
        deleteUsers()
Пример #5
0
    def test_edit_zero_value(self):
        user = meta.Session.query(model.User).\
                filter_by(name=u'Charlie Root').one()
        e = model.Expenditure(user, 0, u'A zero value expenditure', None)
        e.even_split()
        meta.Session.add(e)
        meta.Session.commit()

        response = self.app.get(url_for(controller='spend',
                                        action='edit',
                                        id=e.id))
        response.mustcontain('Edit an Expenditure')
        form = response.form

        assert int(form['spender_id'].value) == user.id
        assert form['amount'].value == '0.00'
        assert form['date'].value == date.today().strftime('%m/%d/%Y')
        assert form['description'].value == u'A zero value expenditure'
        for ii in range(4):
            assert form['shares-%d.amount' % ii].value == '0'
Пример #6
0
    def test_negativeExpenditure(self):
        """
        Test that negative expenditures get split correctly
        """
        createUsers(2)

        users = meta.Session.query(model.User).all()

        e = model.Expenditure(users[0], Currency("100.00"))
        meta.Session.add(e)

        # Force a split that will result in needing to distribute
        # pennies
        split_dict = {users[0]: Decimal(1), users[1]: Decimal(2)}
        e.split(split_dict)
        meta.Session.commit()

        self.assertEqual(e.amount,
                         sum(s.share for s in meta.Session.query(model.Split)))

        deleteExpenditures()
        deleteUsers()
Пример #7
0
    def test_uneven(self):
        """
        Test that expenditures can be split non-evenly
        """
        createUsers(2)

        users = meta.Session.query(model.User).all()

        e = model.Expenditure(users[0], Currency("100"))
        meta.Session.add(e)

        split_dict = {users[0]: Decimal("20"), users[1]: Decimal("80")}

        amount_dict = {users[0]: Currency("20"), users[1]: Currency("80")}

        e.split(split_dict)
        meta.Session.commit()

        for s in meta.Session.query(model.Split):
            self.assertEqual(s.share, amount_dict[s.user])

        deleteExpenditures()
        deleteUsers()
Пример #8
0
    def test_sevenPeople(self):
        """
        Test that expenses are split as evenly as possible with lots of people
        """
        createUsers(7)

        users = meta.Session.query(model.User).all()

        e = model.Expenditure(users[0], Currency("24.00"))
        meta.Session.add(e)
        e.even_split()
        meta.Session.commit()

        splits = meta.Session.query(model.Split).all()
        self.assertEqual(e.amount, sum(s.share for s in splits))

        max_split = max(s.share for s in splits)
        min_split = min(s.share for s in splits)

        self.assertTrue(max_split - min_split <= Currency(1))

        deleteExpenditures()
        deleteUsers()
Пример #9
0
    def test_unevenBadTotal(self):
        """
        Test that transactions get split up properly when the uneven
        split shares don't add to 100%
        """
        createUsers(2)

        users = meta.Session.query(model.User).all()

        e = model.Expenditure(users[0], Currency("100.00"))
        meta.Session.add(e)

        split_dict = {users[0]: Decimal(10), users[1]: Decimal(15)}

        amount_dict = {users[0]: Currency("40"), users[1]: Currency("60")}

        e.split(split_dict)
        meta.Session.commit()

        for s in meta.Session.query(model.Split):
            self.assertEqual(s.share, amount_dict[s.user])

        deleteExpenditures()
        deleteUsers()
Пример #10
0
    def test_edit_and_delete(self):
        user = meta.Session.query(model.User).\
                filter_by(name=u'Charlie Root').one()
        e = model.Expenditure(user, 53812, u'Lemon bundt cake', None)
        e.even_split()
        meta.Session.add(e)
        meta.Session.commit()

        response = self.app.get(url_for(controller='spend',
                                        action='edit',
                                        id=e.id))
        response.mustcontain('Edit an Expenditure')
        form = response.form

        assert int(form['spender_id'].value) == user.id
        assert form['amount'].value == '538.12'
        assert form['date'].value == date.today().strftime('%m/%d/%Y')
        assert form['description'].value == u'Lemon bundt cake'

        form['description'] = u'Updated bundt cake'

        # Update the split too.

        response = form.submit()
        response = response.follow()
        response.mustcontain('Expenditure', 'updated.')

        e = meta.Session.query(model.Expenditure).\
                order_by(model.Expenditure.id.desc()).first()
        assert e.description == u'Updated bundt cake'

        response = self.app.get(url_for(controller='spend',
                                        action='delete',
                                        id=e.id))
        response = response.form.submit('delete').follow()
        response.mustcontain('Expenditure', 'deleted')
Пример #11
0
 def setUp(self):
     self.u = model.User('chaz', u'Charles Root', False)
     self.e = model.Expenditure(self.u, Currency('12.34'),
                                u'A test expenditure')
     self.sp = model.Split(self.e, self.u, Currency('5.55'))