Exemple #1
0
 def test_format_payee(self):
     with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
         run([
             os.path.join('fixtures', 'paypal.csv'), '-a', 'Assets:Foo',
             '--payee-format', 'GROSS:{Gross}'
         ])
         self.assertRegexpMatches(mock_stdout.getvalue(), r"GROSS:-20\.00")
Exemple #2
0
 def test_run_csv_file(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     run([
         '-a', 'Paypal', '-l',
         os.path.join('fixtures', 'empty.lgr'),
         os.path.join('fixtures', 'paypal.csv')
     ], config)
Exemple #3
0
 def test_run(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     acct = config.accounts()[0]
     acct.download = Mock(side_effect=lambda *args, **kwargs: file(
         os.path.join('fixtures', 'checking.ofx')))
     config.accounts = Mock(return_value=[acct])
     run(['-l', os.path.join('fixtures', 'empty.lgr')], config)
     acct.download.assert_has_calls([call(days=7), call(days=14)])
     self.assertEqual(config.accounts.call_count, 1)
Exemple #4
0
 def test_run(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     acct = config.accounts()[0]
     acct.download = Mock(side_effect=lambda *args, **kwargs:
                          open(os.path.join('fixtures', 'checking.ofx')))
     config.accounts = Mock(return_value=[acct])
     run(['-l', os.path.join('fixtures', 'empty.lgr')], config)
     acct.download.assert_has_calls([call(days=7), call(days=14)])
     self.assertEqual(config.accounts.call_count, 1)
Exemple #5
0
def test_run():
    config = OfxConfig(os.path.join("fixtures", "ofxclient.ini"))
    acct = config.accounts()[0]
    acct.download = Mock(side_effect=lambda *args, **kwargs: open(
        os.path.join("fixtures", "checking.ofx"), "rb"))
    config.accounts = Mock(return_value=[acct])
    run(["-l", os.path.join("fixtures", "empty.lgr")], config)
    acct.download.assert_has_calls([call(days=7), call(days=14)])
    assert config.accounts.call_count == 1
Exemple #6
0
 def test_no_ledger(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     acct = config.accounts()[0]
     acct.download = Mock(side_effect=lambda *args, **kwargs:
                          file(os.path.join('fixtures', 'checking.ofx')))
     config.accounts = Mock(return_value=[acct])
     with patch('ledgerautosync.cli.find_ledger_file', return_value=None):
         with patch('sys.stderr', new_callable=StringIO) as mock_stdout:
             run([], config)
             self.assertEquals(mock_stdout.getvalue(), 'LEDGER_FILE environment variable not set, and no .ledgerrc file found, and -l argument was not supplied: running with deduplication disabled. All transactions will be printed!')
Exemple #7
0
def test_format_payee():
    with patch("sys.stdout", new_callable=StringIO) as mock_stdout:
        run([
            os.path.join("fixtures", "paypal.csv"),
            "-a",
            "Assets:Foo",
            "--payee-format",
            "GROSS:{Gross}",
            "-L",
        ])
        assert re.search(r"GROSS:-20\.00", mock_stdout.getvalue())
Exemple #8
0
def test_run_csv_file():
    config = OfxConfig(os.path.join("fixtures", "ofxclient.ini"))
    run(
        [
            "-a",
            "Paypal",
            "-l",
            os.path.join("fixtures", "empty.lgr"),
            os.path.join("fixtures", "paypal.csv"),
        ],
        config,
    )
Exemple #9
0
 def test_no_ledger(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     acct = config.accounts()[0]
     acct.download = Mock(side_effect=lambda *args, **kwargs:
                          open(os.path.join('fixtures', 'checking.ofx')))
     config.accounts = Mock(return_value=[acct])
     with patch('ledgerautosync.cli.find_ledger_file', return_value=None):
         with patch('sys.stderr', new_callable=StringIO) as mock_stdout:
             run([], config)
             self.assertEqual(
                 mock_stdout.getvalue(),
                 'LEDGER_FILE environment variable not set, and no .ledgerrc file found, and -l argument was not supplied: running with deduplication disabled. All transactions will be printed!\n')
Exemple #10
0
def test_no_ledger():
    config = OfxConfig(os.path.join("fixtures", "ofxclient.ini"))
    acct = config.accounts()[0]
    acct.download = Mock(side_effect=lambda *args, **kwargs: open(
        os.path.join("fixtures", "checking.ofx"), "rb"))
    config.accounts = Mock(return_value=[acct])
    with patch("ledgerautosync.cli.find_ledger_file", return_value=None):
        with patch("sys.stderr", new_callable=StringIO) as mock_stdout:
            run([], config)
            assert (
                mock_stdout.getvalue() ==
                "LEDGER_FILE environment variable not set, and no .ledgerrc file found, and -l argument was not supplied: running with deduplication disabled. All transactions will be printed!\n"
            )
Exemple #11
0
def test_no_institution_no_fid(ledger):
    with pytest.raises(EmptyInstitutionException):
        config = OfxConfig(os.path.join("fixtures", "ofxclient.ini"))
        run(
            [
                os.path.join("fixtures", "no-institution.ofx"),
                "-l",
                os.path.join("fixtures", "empty.lgr"),
                "-a",
                "Assets:Savings:Foo",
            ],
            config,
        )
Exemple #12
0
 def test_filter_account(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     foo = next(acct for acct in config.accounts()
                if acct.description == 'Assets:Savings:Foo')
     bar = next(acct for acct in config.accounts()
                if acct.description == 'Assets:Checking:Bar')
     foo.download = Mock(side_effect=lambda *args, **kwargs:
                         open(os.path.join('fixtures', 'checking.ofx')))
     bar.download = Mock()
     config.accounts = Mock(return_value=[foo, bar])
     run(['-l', os.path.join('fixtures', 'checking.lgr'),
          '-a', 'Assets:Savings:Foo'], config)
     foo.download.assert_has_calls([call(days=7)])
     bar.download.assert_not_called()
Exemple #13
0
 def test_filter_account(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     foo = next(acct for acct in config.accounts()
                if acct.description == 'Assets:Savings:Foo')
     bar = next(acct for acct in config.accounts()
                if acct.description == 'Assets:Checking:Bar')
     foo.download = Mock(side_effect=lambda *args, **kwargs:
                         open(os.path.join('fixtures', 'checking.ofx'), 'rb'))
     bar.download = Mock()
     config.accounts = Mock(return_value=[foo, bar])
     run(['-l', os.path.join('fixtures', 'checking.lgr'),
          '-a', 'Assets:Savings:Foo'], config)
     foo.download.assert_has_calls([call(days=7)])
     bar.download.assert_not_called()
Exemple #14
0
def test_filter_account():
    config = OfxConfig(os.path.join("fixtures", "ofxclient.ini"))
    foo = next(acct for acct in config.accounts()
               if acct.description == "Assets:Savings:Foo")
    bar = next(acct for acct in config.accounts()
               if acct.description == "Assets:Checking:Bar")
    foo.download = Mock(side_effect=lambda *args, **kwargs: open(
        os.path.join("fixtures", "checking.ofx"), "rb"))
    bar.download = Mock()
    config.accounts = Mock(return_value=[foo, bar])
    run(
        [
            "-l",
            os.path.join("fixtures", "checking.lgr"),
            "-a",
            "Assets:Savings:Foo",
        ],
        config,
    )
    foo.download.assert_has_calls([call(days=7)])
    bar.download.assert_not_called()
Exemple #15
0
 def test_no_institution_no_fid(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     run([os.path.join('fixtures', 'no-institution.ofx'),
          '-l', os.path.join('fixtures', 'empty.lgr'),
          '-a', 'Assets:Savings:Foo'], config)
Exemple #16
0
 def test_format_payee(self):
     with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
         run([os.path.join('fixtures', 'paypal.csv'), '-a',
              'Assets:Foo', '--payee-format', 'GROSS:{Gross}', '-L'])
         self.assertRegex(mock_stdout.getvalue(), r"GROSS:-20\.00")
Exemple #17
0
 def test_no_ledger_arg(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     run(['-l', os.path.join('fixtures', 'checking.lgr'),
          '-L'], config)
Exemple #18
0
 def test_run_csv_file(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     run(['-a', 'Paypal', '-l', os.path.join('fixtures', 'empty.lgr'),
          os.path.join('fixtures', 'paypal.csv')], config)
Exemple #19
0
 def test_no_ledger_arg(self):
     config = OfxConfig(os.path.join('fixtures', 'ofxclient.ini'))
     run(['-l', os.path.join('fixtures', 'checking.lgr'), '-L'], config)
Exemple #20
0
def test_no_ledger_arg():
    with pytest.raises(LedgerAutosyncException):
        config = OfxConfig(os.path.join("fixtures", "ofxclient.ini"))
        run(["-l", os.path.join("fixtures", "checking.lgr"), "-L"], config)