Esempio n. 1
0
    def test_register(self):
        expense = Expense()
        expense.setUp({"test": True})

        proj1 = ConsumingProject(9999, date(2012, 1, 1), 3333)
        proj2 = ConsumingProject(256, date(2012, 1, 1), 3333)
        proj3 = ConsumingProject(999, date(2012, 1, 1), 3333, "type", u"Food & Drinks")
        proj4 = ConsumingProject(300, date(2012, 1, 1), 3333, "tag", u"Like")
        expense.addProject("proj1", proj1)
        expense.addProject("proj2", proj2)
        expense.addProject("proj3", proj3)
        expense.addProject("proj4", proj4)
        addSampleRecords(expense)

        # test proj1
        self.assertEqual(proj1.p_accumt_amount, 2320.0)
        self.assertEqual(proj1.p_recs_amount, 21)
        self.assertEqual(proj1.p_accomplish_date, "")
        self.assertFalse(proj1.p_statdict["hasQuarter"])
        self.assertFalse(proj1.p_statdict["hasHalf"])
        self.assertFalse(proj1.p_statdict["hasThreeQuarters"])
        self.assertEqual(len(proj1.p_progress_info), 6)

        # test proj2
        self.assertEqual(proj2.p_accumt_amount, 2320.0)
        self.assertEqual(proj2.p_recs_amount, 21)
        self.assertEqual(proj2.p_accomplish_date, date.today().isoformat())
        self.assertTrue(proj2.p_statdict["hasQuarter"])
        self.assertTrue(proj2.p_statdict["hasHalf"])
        self.assertTrue(proj2.p_statdict["hasThreeQuarters"])
        self.assertEqual(proj2.p_statdict["DateOfQuarter"], date.today().isoformat())
        self.assertEqual(proj2.p_statdict["DateOfHalf"], date.today().isoformat())
        self.assertEqual(proj2.p_statdict["DateOfThreeQuarters"], date.today().isoformat())
        self.assertEqual(len(proj2.p_progress_info), 7)

        # test proj3
        self.assertEqual(proj3.p_accumt_amount, 322.0)
        self.assertEqual(proj3.p_recs_amount, 16)
        self.assertEqual(proj3.p_accomplish_date, "")
        self.assertTrue(proj3.p_statdict["hasQuarter"])
        self.assertFalse(proj3.p_statdict["hasHalf"])
        self.assertFalse(proj3.p_statdict["hasThreeQuarters"])
        self.assertEqual(proj3.p_statdict["DateOfQuarter"], date.today().isoformat())
        self.assertEqual(len(proj3.p_progress_info), 7)

        # test proj4
        self.assertEqual(proj4.p_accumt_amount, 154.0)
        self.assertEqual(proj4.p_recs_amount, 2)
        self.assertEqual(proj4.p_accomplish_date, "")
        self.assertTrue(proj4.p_statdict["hasQuarter"])
        self.assertTrue(proj4.p_statdict["hasHalf"])
        self.assertFalse(proj4.p_statdict["hasThreeQuarters"])
        self.assertEqual(proj4.p_statdict["DateOfQuarter"], date.today().isoformat())
        self.assertEqual(proj4.p_statdict["DateOfHalf"], date.today().isoformat())
        self.assertEqual(len(proj4.p_progress_info), 7)
    def test_Expense_mutable_operation(self):
        expense = Expense()
        expense.setUp()
        addSampleRecords(expense)

        expense.updatePassword(DEFAULT_PASSWORD, 'JL')
        expense.save()

        exp2 = Expense()
        exp2.setUp({'pwd':'JL'})
        self.assertEqual(
            sum(len(cont._storage) for cont in expense.rec_m.impl._reclist),
            sum(len(cont._storage) for cont in exp2.rec_m.impl._reclist),
        )
        self.assertEqual(
            expense.rec_m.impl._pwd,
            exp2.rec_m.impl._pwd,
        )
        self.assertEqual(
            expense.rec_m.impl._len,
            exp2.rec_m.impl._len,
        )

        exp2.resetAll()