File: test_homebank.py

package info (click to toggle)
python-csb43 0.9.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 560 kB
  • sloc: python: 6,233; sh: 9; makefile: 6
file content (106 lines) | stat: -rw-r--r-- 2,831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import unittest

from .. import homebank
from .. import utils
import datetime
import decimal


class TestHomebankTransaction(unittest.TestCase):

    def setUp(self):
        self.tDate = datetime.date(2002, 3, 4)
        self.value = [
            # date
            self.tDate.strftime("%d-%m-%y"),
            # mode
            '2',
            # info
            '3',
            # payee
            '4',
            # description
            '5',
            # amount
            '1.10'
        ]

    def test_init(self):
        try:
            homebank.Transaction()
        except utils.Csb43Exception:
            self.fail("exception not expected")

    def test_init_record(self):

        with self.assertRaises(utils.Csb43Exception):
            homebank.Transaction("1;2")

        with self.assertRaises(utils.Csb43Exception):
            homebank.Transaction(",".join(self.value))

        homebank.Transaction(";".join(self.value))

    def test_properties(self):
        t = homebank.Transaction(";".join(self.value))

        self.assertEqual(self.tDate.year, t.date.year)
        self.assertEqual(self.tDate.month, t.date.month)
        self.assertEqual(self.tDate.day, t.date.day)

        self.assertEqual(2, t.mode)
        self.assertEqual('3', t.info)
        self.assertEqual('4', t.payee)
        self.assertEqual('5', t.description)
        self.assertEqual(decimal.Decimal('1.1'), t.amount)
        self.assertIsNone(t.category)

        value = list(self.value)
        value.append('7')

        t = homebank.Transaction(";".join(value))

        self.assertEqual(self.tDate.year, t.date.year)
        self.assertEqual(self.tDate.month, t.date.month)
        self.assertEqual(self.tDate.day, t.date.day)

        self.assertEqual(2, t.mode)
        self.assertEqual('3', t.info)
        self.assertEqual('4', t.payee)
        self.assertEqual('5', t.description)
        self.assertEqual(decimal.Decimal('1.1'), t.amount)
        self.assertEqual('7', t.category)

        t.mode = '23'
        self.assertEqual(23, t.mode)
        t.mode = 23
        self.assertEqual(23, t.mode)

        t.info = '55'
        self.assertEqual('55', t.info)

        t.payee = 'payee'
        self.assertEqual('payee', t.payee)

        t.description = 'description'
        self.assertEqual('description', t.description)

        with self.assertRaises(decimal.InvalidOperation):
            t.amount = 'amount'

        with self.assertRaises(utils.Csb43Exception):
            t.date = '43'

        try:
            t.date = self.tDate
        except Exception:
            self.fail("exception not expected")

    def test_str(self):
        value = list(self.value)
        value.append('7')
        value = ";".join(value)

        t = homebank.Transaction(value)

        self.assertEqual(value, str(t))