Esempio n. 1
0
 def test_multi_statemets_parsing(self):
     parser = Parser()
     with open(os.path.join(BASEPATH, "Coda_v2_3_multi_statements.txt")) as f:
         content = f.read()
     statements = parser.parse(content)
     assert len(statements) == 2
     self._test_first_statement(statements[0])
Esempio n. 2
0
 def test_globalisation(self):
     """Test that a globalisation line with details is considerd as
     Globalisation and its details as Normal
     """
     parser = Parser()
     with open(os.path.join(
             BASEPATH, "Coda_v2_3_globalisation.txt"), 'rb') as f:
         content = f.read()
     statements = parser.parse(content)
     eq_(len(statements), 1)
     statement = statements[0]
     eq_(len(statement.movements), 5)
     for idx, mv in enumerate(statement.movements):
         if idx == 2:
             eq_(mv.type, MovementRecordType.GLOBALISATION)
         else:
             eq_(mv.type, MovementRecordType.NORMAL)
     with open(os.path.join(BASEPATH,
                            "Coda_v2_3_globalisation_2.txt"), 'rb') as f:
         content = f.read()
     statements = parser.parse(content)
     assert len(statements) == 1
     statement = statements[0]
     eq_(len(statement.movements), 4)
     for mv in statement.movements:
         eq_(mv.type, MovementRecordType.NORMAL)
Esempio n. 3
0
 def test_globalisation(self):
     """Test that a globalisation line with details is considerd as
     Globalisation and its details as Normal
     """
     parser = Parser()
     with open(os.path.join(BASEPATH, "Coda_v2_3_globalisation.txt")) as f:
         content = f.read()
     statements = parser.parse(content)
     eq_(len(statements), 1)
     statement = statements[0]
     eq_(len(statement.movements), 5)
     for idx, mv in enumerate(statement.movements):
         if idx == 2:
             eq_(mv.type, MovementRecordType.GLOBALISATION)
         else:
             eq_(mv.type, MovementRecordType.NORMAL)
     with open(os.path.join(BASEPATH,
                            "Coda_v2_3_globalisation_2.txt")) as f:
         content = f.read()
     statements = parser.parse(content)
     assert len(statements) == 1
     statement = statements[0]
     eq_(len(statement.movements), 4)
     for mv in statement.movements:
         eq_(mv.type, MovementRecordType.NORMAL)
Esempio n. 4
0
 def test_foreign_account(self):
     parser = Parser()
     file_name = os.path.join(BASEPATH, "Coda_foreign_account.txt")
     statements = parser.parse_file(file_name)
     eq_(len(statements), 1)
     st = statements[0]
     eq_(st.acc_number, 'FR1234567890240924002304825')
     eq_(st.currency, 'EUR')
Esempio n. 5
0
 def test_unsupported_version(self):
     parser = Parser()
     with open(os.path.join(BASEPATH, "Coda_faulty_version.txt")) as f:
         content = f.read()
     with assert_raises(CodaParserException) as cm:
         parser.parse(content)
     eq_(cm.exception.code, ' R001')
     eq_(cm.exception.msg, 'CODA V5 statements are not supported, please contact your bank')
Esempio n. 6
0
 def test_multi_statemets_parsing(self):
     parser = Parser()
     with open(os.path.join(BASEPATH,
                            "Coda_v2_3_multi_statements.txt")) as f:
         content = f.read()
     statements = parser.parse(content)
     assert len(statements) == 2
     self._test_first_statement(statements[0])
Esempio n. 7
0
 def test_foreign_account(self):
     parser = Parser()
     file_name = os.path.join(BASEPATH, "Coda_foreign_account.txt")
     statements = parser.parse_file(file_name)
     eq_(len(statements), 1)
     st = statements[0]
     eq_(st.acc_number, 'FR1234567890240924002304825')
     eq_(st.currency, 'EUR')
Esempio n. 8
0
 def test_single_statemet_parsing(self):
     parser = Parser()
     with open(os.path.join(BASEPATH, "Coda_v2_3_single_statement.txt")) as f:
         content = f.read()
     statements = parser.parse(content)
     assert len(statements) == 1
     # the first statement is the same for single and multi-statements file
     statement = statements[0]
     self._test_first_statement(statement)
Esempio n. 9
0
 def test_unsupported_version(self):
     parser = Parser()
     with open(os.path.join(BASEPATH, "Coda_faulty_version.txt")) as f:
         content = f.read()
     with assert_raises(CodaParserException) as cm:
         parser.parse(content)
     eq_(cm.exception.code, ' R001')
     eq_(cm.exception.msg,
         'CODA V5 statements are not supported, please contact your bank')
Esempio n. 10
0
 def test_single_statemet_parsing(self):
     parser = Parser()
     with open(os.path.join(BASEPATH,
                            "Coda_v2_3_single_statement.txt")) as f:
         content = f.read()
     statements = parser.parse(content)
     assert len(statements) == 1
     # the first statement is the same for single and multi-statements file
     statement = statements[0]
     self._test_first_statement(statement)
Esempio n. 11
0
    def test_wrong_globalisation(self):
        """Test wrong globalisation

        Check that a globalisation line without the corresponding
        'end globalisation' is considered as Normal
        """
        parser = Parser()
        with open(os.path.join(BASEPATH,
                               "Coda_v2_3_faulty_globalisation.txt")) as f:
            content = f.read()
        statements = parser.parse(content)
        eq_(len(statements), 1)
        statement = statements[0]
        eq_(len(statement.movements), 11)
        for mv in statement.movements:
            eq_(mv.type, MovementRecordType.NORMAL)
Esempio n. 12
0
    def test_wrong_globalisation_2(self):
        """Test wrong globalisation

        Check that a globalisation line without details
        is considered as Normal (file contains only globalisation statemnts)
        """
        parser = Parser()
        with open(
                os.path.join(BASEPATH,
                             "Coda_v2_3_faulty_globalisation_2.txt")) as f:
            content = f.read()
        statements = parser.parse(content)
        eq_(len(statements), 1)
        statement = statements[0]
        eq_(len(statement.movements), 2)
        for mv in statement.movements:
            eq_(mv.type, MovementRecordType.NORMAL)
Esempio n. 13
0
    def _parse_file(self, data_file):
        parser = Parser()
        try:
            statements = parser.parse(data_file)
        except CodaParserException:
            return super(CodaBankStatementImport, self)._parse_file(data_file)
        currency_code = False
        account_number = False

        stmts_vals = []
        for statement in statements:
            account_number = statement.acc_number
            currency_code = statement.currency
            statement_data = self._get_statement_data(statement)
            stmts_vals.append(statement_data)
            for move in statement.movements:
                statement_data['transactions'].append(
                    self._get_move_value(
                        move, statement,
                        len(statement_data['transactions']) + 1))

        return currency_code, self._get_acc_number(account_number), stmts_vals
Esempio n. 14
0
 def _parse_file(self, data_file):
     if not self._check_coda(data_file):
         return super(AccountBankStatementImport,
                      self)._parse_file(data_file)
     vals_bank_statements = []
     try:
         statements = Parser().parse(data_file)
         for statement in statements:
             vals_bank_statements.append(self.get_st_vals(statement))
     except Exception, e:
         _logger.exception('Error when parsing coda file')
         raise UserError(
             _("The following problem occurred during import. "
               "The file might not be valid.\n\n %s" % e.message))
Esempio n. 15
0
    def _parse_file(self, data_file):
        if not self._check_coda(data_file):
            return super()._parse_file(data_file)
        vals_bank_statements = []
        try:
            statements = Parser().parse(data_file)
            for statement in statements:
                vals_bank_statements.append(self.get_st_vals(statement))
        except Exception as e:
            _logger.exception('Error when parsing coda file')
            raise UserError(
                _("The following problem occurred during import. "
                  "The file might not be valid.\n\n %s" % e.message))

        acc_number = None
        currency = None
        if statements:
            acc_number = statements[0].acc_number
            currency = statement.currency
        return currency, acc_number, vals_bank_statements
Esempio n. 16
0
    def test_parse_methods(self):
        parser = Parser()
        # test a invalid file name
        with assert_raises(ValueError):
            parser.parse_file('invalid_file_name')
        # test parsing from a path to a file
        parser = Parser()
        file_name = os.path.join(BASEPATH, "Coda_v2_3_single_statement.txt")
        statements = parser.parse_file(file_name)
        eq_(len(statements), 1)

        # test parsing from a file-like object
        parser = Parser()
        with open(os.path.join(file_name)):
            statements = parser.parse_file(file_name)
            eq_(len(statements), 1)

        # test parsing an invalid content
        with assert_raises(ValueError) as cm:
            parser.parse('invalid_coda_content')
        ex = cm.exception
        eq_(ex.message, 'The given value is not a valid coda content')