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)
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)
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')
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])
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)
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), 'rb'): statements = parser.parse_file(file_name) eq_(len(statements), 1) # test parsing an invalid content with assert_raises(ValueError) as cm: parser.parse(b'invalid_coda_content') ex = cm.exception eq_(str(ex), 'The given value is not a valid coda content')
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')
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) assert len(statements) == 1 statement = statements[0] eq_(len(statement.movements), 11) for mv in statement.movements: eq_(mv.type, MovementRecordType.NORMAL)
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"), 'rb') 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)
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)
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)
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