# Path: bankcsvtoqif/transaction.py
# class TransactionFactory(object):
#     """ Creates Transactions from an account_config. """
# 
#     def __init__(self, account_config):
#         self.account_config = account_config
# 
#     def create_from_line(self, line):
#         return Transaction(
#             date=self.account_config.get_date(line),
#             description=self.account_config.get_description(line),
#             debit=self.account_config.get_debit(line),
#             credit=self.account_config.get_credit(line),
#             target_account=self.account_config.get_target_account(line),
#             source_account=self.account_config.get_source_account(line)
#         )
# 
#     def read_from_file(self, f, messenger):
#         csv.register_dialect(
#             'bank_csv',
#             self.account_config.get_csv_dialect()
#         )
#         c = csv.reader(f, 'bank_csv')
#         consume(c, self.account_config.dropped_lines)  # ignore first lines
#         transactions = []
#         for line in c:
#             try:
#                 transaction = self.create_from_line(line)
#                 transactions.append(transaction)
#                 messenger.send_message("parsed: " + transaction.__str__())
#             except IndexError:
#                 messenger.send_message('skipped: %s' % line)
#                 continue
#         return transactions
# 
# Path: bankcsvtoqif/banks/vrbank.py
# class VRBank(BankAccountConfig):
#     """ VR-Bank Girokonto """
# 
#     def get_date(self, line):
#         (day, month, year) = map(int, line[1].split('.'))
#         return datetime(year, month, day)
# 
#     def get_description(self, line):
#         return ' '.join(line[3:19])
# 
#     def get_debit(self, line):
#         val = self.get_amount(line[19])
#         return -val if val < 0 else 0
# 
#     def get_credit(self, line):
#         val = self.get_amount(line[19])
#         return val if val >= 0 else 0


import unittest
from bankcsvtoqif.transaction import TransactionFactory
from bankcsvtoqif.banks.vrbank import VRBank
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.




class TestVRBank(unittest.TestCase):
    def setUp(self):
        self.d = VRBank()

    def test_can_instanciate(self):
        pass

    def test_extract_correct_fields(self):
        transaction = (TransactionFactory(self.d)).create_from_line(self.get_fixture_line())

        self.assertIsNotNone(transaction.date)
        self.assertEqual('2015-05-22T00:00:00', transaction.date.isoformat())

        self.assertGreater(transaction.debit, 0)
        self.assertGreater(transaction.debit, 8.2)
        self.assertLess(transaction.debit, 9)
        self.assertEqual(transaction.credit, 0)

        self.assertTrue('AMAZON' in transaction.description)
        self.assertTrue('32132131321' in transaction.description)

# Path: bankcsvtoqif/transaction.py
# class TransactionFactory(object):
#     """ Creates Transactions from an account_config. """
# 
#     def __init__(self, account_config):
#         self.account_config = account_config
# 
#     def create_from_line(self, line):
#         return Transaction(
#             date=self.account_config.get_date(line),
#             description=self.account_config.get_description(line),
#             debit=self.account_config.get_debit(line),
#             credit=self.account_config.get_credit(line),
#             target_account=self.account_config.get_target_account(line),
#             source_account=self.account_config.get_source_account(line)
#         )
# 
#     def read_from_file(self, f, messenger):
#         csv.register_dialect(
#             'bank_csv',
#             self.account_config.get_csv_dialect()
#         )
#         c = csv.reader(f, 'bank_csv')
#         consume(c, self.account_config.dropped_lines)  # ignore first lines
#         transactions = []
#         for line in c:
#             try:
#                 transaction = self.create_from_line(line)
#                 transactions.append(transaction)
#                 messenger.send_message("parsed: " + transaction.__str__())
#             except IndexError:
#                 messenger.send_message('skipped: %s' % line)
#                 continue
#         return transactions
# 
# Path: bankcsvtoqif/banks/vrbank.py
# class VRBank(BankAccountConfig):
#     """ VR-Bank Girokonto """
# 
#     def get_date(self, line):
#         (day, month, year) = map(int, line[1].split('.'))
#         return datetime(year, month, day)
# 
#     def get_description(self, line):
#         return ' '.join(line[3:19])
# 
#     def get_debit(self, line):
#         val = self.get_amount(line[19])
#         return -val if val < 0 else 0
# 
#     def get_credit(self, line):
#         val = self.get_amount(line[19])
#         return val if val >= 0 else 0


# Path: bankcsvtoqif/tests/banks/test_vrbank.py
import unittest
from bankcsvtoqif.transaction import TransactionFactory
from bankcsvtoqif.banks.vrbank import VRBank

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.




class TestVRBank(unittest.TestCase):
    def setUp(self):
        self.d = VRBank()

    def test_can_instanciate(self):
        pass

    def test_extract_correct_fields(self):
        transaction = (TransactionFactory(self.d)).create_from_line(self.get_fixture_line())

        self.assertIsNotNone(transaction.date)
        self.assertEqual('2015-05-22T00:00:00', transaction.date.isoformat())

        self.assertGreater(transaction.debit, 0)
        self.assertGreater(transaction.debit, 8.2)
        self.assertLess(transaction.debit, 9)
        self.assertEqual(transaction.credit, 0)

        self.assertTrue('AMAZON' in transaction.description)
        self.assertTrue('32132131321' in transaction.description)

        self.assertTrue('-8,21' not in transaction.description)