Example #1
0
    def test_finish_balancing_with_errors(self):
        """Verify things don't change when there are errors"""
        with FileTester.temp_input(testdata) as tempfilename:
            recon = Reconciler(LedgerFile(tempfilename, 'cash'))

            recon.finish_balancing()

            payees = {
                thing.payee for thing in recon.open_transactions
                }
            self.assertEqual(
                ({'two', 'two pt five', 'three', 'four'}),
                payees
            )
            payees = {
                thing.payee for k, thing in
                recon.current_listing.iteritems()
                }
            # future items included only if pending ('three')
            self.assertEqual(
                ({'two', 'two pt five', 'three'}),
                payees
            )

            recon.ending_balance = -1234.56
            recon.finish_balancing()

            self.assertEqual(-1234.56, recon.ending_balance)
            payees = {
                thing.payee for thing in recon.open_transactions
                }
            self.assertEqual(
                ({'two', 'two pt five', 'three', 'four'}),
                payees
            )
            payees = {
                thing.payee for k, thing in
                recon.current_listing.iteritems()
                }
            # future items included only if pending ('three')
            self.assertEqual(
                ({'two', 'two pt five', 'three'}),
                payees
            )
Example #2
0
    def test_finish_balancing_errors(self):

        with FileTester.temp_input(testdata) as tempfilename:
            recon = Reconciler(LedgerFile(tempfilename, 'cash'))

            self.reset_redirect()
            recon.finish_balancing()
            self.assertEqual(
                '*** Ending balance must be set in order to finish',
                self.redirect.getvalue().rstrip()
            )

            self.reset_redirect()
            recon.ending_balance = -1234.56
            recon.finish_balancing()
            self.assertEqual(
                '"To zero" must be zero in order to finish',
                self.redirect.getvalue().rstrip()
            )
            # confirms it didn't revert to None as on success
            self.assertEqual(-1234.56, recon.ending_balance)
Example #3
0
    def test_cache(self):

        with FileTester.temp_input(self.testcache) as tempfilename:
            recon = Reconciler(LedgerFile(tempfilename, 'cash'))

        # saving cache with ending balance "None" causes cache entry to
        # be removed; first let's make sure it works w/o existing entry
        assert not os.path.exists(FileTester.CACHE_FILE_TEST)
        assert recon.ending_balance is None
        recon.save_statement_info_to_cache()
        key, cache = recon.get_key_and_cache()
        self.assertEqual({}, cache)

        # add entry
        recon.ending_balance = 100
        recon.ending_date = date(2020, 10, 20)
        recon.save_statement_info_to_cache()
        key, cache = recon.get_key_and_cache()
        self.assertEqual(
            {u'a: cash': {
                u'ending_balance': 100,
                u'ending_date': u'2020/10/20'
            }},
            cache
        )

        # remove entry
        recon.ending_balance = None
        recon.save_statement_info_to_cache()
        key, cache = recon.get_key_and_cache()
        self.assertEqual({}, cache)

        # multiple entries
        recon.ending_balance = 111
        recon.ending_date = date(2111, 11, 11)
        recon.save_statement_info_to_cache()

        with FileTester.temp_input(self.testcache) as tempfilename:
            recon = Reconciler(LedgerFile(tempfilename, 'credit'))

        recon.ending_balance = 222
        recon.ending_date = date(2222, 2, 22)
        recon.save_statement_info_to_cache()
        key, cache = recon.get_key_and_cache()
        self.assertEqual(
            {u'a: credit': {
                u'ending_balance': 222,
                u'ending_date': u'2222/02/22'
            }, u'a: cash': {
                u'ending_balance': 111,
                u'ending_date': u'2111/11/11'
            }},
            cache
        )

        # remove credit
        recon.ending_balance = None
        recon.save_statement_info_to_cache()
        key, cache = recon.get_key_and_cache()
        self.assertEqual(
            {u'a: cash': {
                u'ending_balance': 111,
                u'ending_date': u'2111/11/11'
            }},
            cache
        )

        # indirectly verify get_statement_info_from_cache
        with FileTester.temp_input(self.testcache) as tempfilename:
            recon = Reconciler(LedgerFile(tempfilename, 'cash'))

        # get_statement_info_from_cache will have been called in init
        self.assertEqual(111, recon.ending_balance)
        self.assertEqual(date(2111, 11, 11), recon.ending_date)