Skip to content

Commit

Permalink
fix(bankstatementparser): 🐛 fixed flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Nov 8, 2023
1 parent d3a079c commit 36742ae
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
67 changes: 51 additions & 16 deletions tests/test_ pain001_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,77 @@
import os
from bankstatementparser.pain001_parser import Pain001Parser


# Define additional test cases
class TestPain001Parser(unittest.TestCase):
"""Tests for Pain001Parser"""

def setUp(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(current_dir, 'test_data', 'pain.001.001.03.xml')
file_path = os.path.join(
current_dir, 'test_data', 'pain.001.001.03.xml'
)
self.parser = Pain001Parser(file_path)

def testMessageIdentification(self):
# Test to ensure the parser correctly retrieves the message identification from the XML data
# Test to ensure the parser correctly retrieves the message
# identification from the XML data
group_header = self.parser.tree.find('.//GrpHdr')
message_id = group_header.find('MsgId').text if group_header.find('MsgId') is not None else None
self.assertEqual(message_id, '1', "Message identification not retrieved correctly")
message_id = group_header.find(
'MsgId'
).text if group_header.find('MsgId') is not None else None
self.assertEqual(
message_id, '1', "Message identification not retrieved correctly"
)

def testCreationDateTime(self):
# Test to ensure the parser correctly retrieves the creation date and time from the XML data
# Test to ensure the parser correctly retrieves the creation date and
# time from the XML data
group_header = self.parser.tree.find('.//GrpHdr')
creation_date_time = group_header.find('CreDtTm').text if group_header.find('CreDtTm') is not None else None
self.assertEqual(creation_date_time, '2023-03-10T15:30:47.000Z', "Creation date and time not retrieved correctly")
creation_date_time = group_header.find(
'CreDtTm'
).text if group_header.find('CreDtTm') is not None else None
self.assertEqual(
creation_date_time,
'2023-03-10T15:30:47.000Z',
"Creation date and time not retrieved correctly"
)

def testNumberOfTransactions(self):
# Test to ensure the parser correctly retrieves the number of transactions from the XML data
# Test to ensure the parser correctly retrieves the number of
# transactions from the XML data
group_header = self.parser.tree.find('.//GrpHdr')
number_of_transactions = group_header.find('NbOfTxs').text if group_header.find('NbOfTxs') is not None else None
self.assertEqual(number_of_transactions, '2', "Number of transactions not retrieved correctly")
number_of_transactions = group_header.find(
'NbOfTxs'
).text if group_header.find('NbOfTxs') is not None else None
self.assertEqual(
number_of_transactions,
'2',
"Number of transactions not retrieved correctly"
)

def testInitiatingParty(self):
# Test to ensure the parser correctly retrieves the initiating party information from the XML data
initiating_party = self.parser.tree.find('.//InitgPty/Nm').text if self.parser.tree.find('.//InitgPty/Nm') is not None else None
self.assertEqual(initiating_party, 'John Doe', "Initiating party not retrieved correctly")
# Test to ensure the parser correctly retrieves the initiating party
# information from the XML data
initiating_party = self.parser.tree.find(
'.//InitgPty/Nm'
).text if self.parser.tree.find('.//InitgPty/Nm') is not None else None
self.assertEqual(
initiating_party,
'John Doe',
"Initiating party not retrieved correctly"
)

def testPaymentInformationParsing(self):
# Test scenarios to ensure that the parser correctly parses and processes different payment information records
# Test scenarios to ensure that the parser correctly parses and
# processes different payment information records
payment_info_records = self.parser.tree.findall('.//PmtInf')
self.assertGreaterEqual(len(payment_info_records), 1, "Insufficient payment information records")
self.assertGreaterEqual(
len(payment_info_records),
1,
"Insufficient payment information records"
)


if __name__ == '__main__':
unittest.main()
unittest.main()
12 changes: 10 additions & 2 deletions tests/test_bank_statement_parsers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import unittest
from bankstatementparser.bank_statement_parsers import FileParserError, Pain001Parser
from bankstatementparser.bank_statement_parsers import FileParserError
from bankstatementparser.bank_statement_parsers import Pain001Parser
import os


class TestFileParserError(unittest.TestCase):
def test_file_parser_error(self):
with self.assertRaises(FileParserError):
raise FileParserError("This is a file parser error")


class TestPain001Parser(unittest.TestCase):
def setUp(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(current_dir, 'test_data', 'pain.001.001.03.xml')
file_path = os.path.join(
current_dir,
'test_data',
'pain.001.001.03.xml'
)
self.parser = Pain001Parser(file_path)

def test_init(self):
Expand All @@ -32,5 +39,6 @@ def test_init(self):
self.assertEqual(first_payment['Amount'], 150.0)
self.assertEqual(first_payment['Currency'], 'EUR')


if __name__ == '__main__':
unittest.main()
8 changes: 6 additions & 2 deletions tests/test_camt_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
from bankstatementparser.camt_parser import CamtParser
import os


class TestCamtParser(unittest.TestCase):
def setUp(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(current_dir, 'test_data', 'camt.053.001.02.xml')
file_path = os.path.join(
current_dir,
'test_data',
'camt.053.001.02.xml'
)
self.parser = CamtParser(file_path)

def test_init(self):
self.assertIsNotNone(self.parser)
self.assertIsNotNone(self.parser.tree)
self.assertIsInstance(self.parser.definitions, dict)

# Add more tests for other methods of CamtParser here

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
from bankstatementparser.cli import BankStatementCLI


class TestBankStatementCLI(unittest.TestCase):
def setUp(self):
self.cli = BankStatementCLI()
Expand All @@ -10,7 +11,6 @@ def test_init(self):
self.assertIsNotNone(self.cli)
self.assertIsNotNone(self.cli.parser)

# Add more tests for other methods of BankStatementCLI here

if __name__ == '__main__':
unittest.main()

0 comments on commit 36742ae

Please sign in to comment.