Beispiel #1
0
 def setUp(self):
     testbase.TestCaseWithController.setUp(self)
     self.basePlot = BasePlot()
Beispiel #2
0
class SummaryTests(testbase.TestCaseWithController):
    
    def setUp(self):
        testbase.TestCaseWithController.setUp(self)
        self.basePlot = BasePlot()
    
    def get(self, transactionsData, numPoints, *args):
        # Remove all existing accounts, it is assumed that none exist
        for account in self.Model.Accounts:
            self.Model.RemoveAccount(account.Name)

        a = self.Model.CreateAccount("A")
        for (date, amount) in transactionsData:
            a.AddTransaction(amount=amount, date=date)
        
        return self.basePlot.getPoints(self.Model.GetXTotals(*args), numPoints)

    def testGetTenPointsWithNoTransactions(self):
        result = self.get([], 10)
        self.assertEqual(result[0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        self.assertEqual(result[1], datetime.date.today())
        # Make sure it is close to zero but not zero.
        self.assertNotEqual(result[2], 0)
        self.assertAlmostEqual(result[2], 0)

    def testGetPointsWithOneTransaction(self):
        result = self.get([("2008/1/6", 1)], 3)
        self.assertEqual(result[0], [1.0, 1.0, 1.0])

        result = self.get([(today, 1)], 2)
        self.assertEqual(result[0], [1.0, 1.0])
        self.assertEqual(result[1], today)
        self.assertNotEqual(result[2], 0)

    def testGetOnePointWithTwoTransactionsYesterdayAndToday(self):
        result = self.get([(today-one, 1), (today, 2)], 1)
        self.assertEqual(result[0], [3.0])
        self.assertEqual(result[1], today - one)
        self.assertEqual(result[2], 1.0)

    def testGetPointsWithTwoSequentialDays(self):
        self.assertEqual(self.get([(today-one, 1), (today, 2)], 4)[0], [1.0, 1.0, 1.0, 3.0])
        self.assertEqual(self.get([(today, 1), (today+one, 2)], 2)[0], [1.0, 3.0])
        self.assertEqual(self.get([(today, 1), (today+one, 2)], 3)[0], [1.0, 1.0, 3.0])

    def testGetPointsWithNonSequentialDays(self):
        self.assertEqual(self.get([(today-one*9, 1), (today, 2)], 10)[0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0])
        self.assertEqual(self.get([(today, 1), (today+one*2, 2), (today+one*9, 3)], 10)[0], [1.0, 1.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 6.0])

    def testGetPointsWithRange(self):
        daterange = (today+one, today+one*2)
        points, start, dpp = self.get([(today, 3), (today+one, 5), (today+one*2, 7), (today+one*3, 11)], 2, None, daterange)
        self.assertEqual(points, [8.0, 15.0])
        self.assertEqual(start, today+one)
        self.assertEqual(dpp, 0.5)

    def testGetPointsWithRangeNoTransactions(self):
        result = self.get([], 10, None, (today-one, today+one))
        self.assertEqual(result[0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        self.assertEqual(result[1], datetime.date.today())
        # Make sure it is close to zero but not zero.
        self.assertNotEqual(result[2], 0)
        self.assertAlmostEqual(result[2], 0)

    def testOutOfBoundsDateRangeIsRespected(self):
        amounts, start, delta = self.get([(today, 1)], 4, None, (today-one*2, today+one))
        self.assertEqual(amounts, [0.0, 0.0, 1.0, 1.0])
        self.assertEqual(start, today-one*2)
        self.assertEqual(delta, .75)
        
    def testTransactionsBeforeRangeAreCounted(self):
        amounts, start, delta = self.get([(today-one, 3), (today, 2), (today+one, 1)], 3, None, (today, today+one))
        self.assertEqual(amounts, [5.0, 5.0, 6.0])
        
    def testDateRangeEndingBeforeTodayWorks(self):
        amounts, start, delta = self.get([(today-one*2, 3), (today-one, 2), (today, 1)], 2, None, (today-one*2, today-one))
        # Make sure 'today' isn't counted as it isn't in our date range.
        self.assertEqual(amounts, [3.0, 5.0])