class TestJoiner(unittest.TestCase): def setUp(self, session=None): self.parser = EPTRNParser() self.dummy_file_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'support/dummy_eptrn_raw') def test_left_outer_join_sections_joins_sections_on_requested_fields(self): parsed = self.parser.process(self.dummy_file_path) def join_condition(left_instance, right_instance): return left_instance['TLRR_PAYMENT_NUMBER'] == right_instance[ 'PAYMENT_NUMBER'] joined = Joiner.left_outer_join_sections( left_collection=parsed['RECORD_OF_CHARGE_DETAIL_RECORD'], right_collection=parsed['SUMMARY_RECORD'], join_condition=join_condition) self.assertEqual(2, len(joined)) self.assertEqual(datetime.datetime(2013, 3, 9), joined[0]['PAYMENT_DATE']) self.assertEqual(3491124567, joined[0]['AMEX_PAYEE_NUMBER']) self.assertEqual(joined[0]['PAYMENT_NUMBER'], joined[0]['TLRR_PAYMENT_NUMBER']) self.assertEqual(datetime.datetime(2013, 3, 11), joined[1]['PAYMENT_DATE']) self.assertEqual(2223334445, joined[1]['AMEX_PAYEE_NUMBER']) self.assertEqual(joined[1]['PAYMENT_NUMBER'], joined[1]['TLRR_PAYMENT_NUMBER'])
class TestEPTRNParser(unittest.TestCase): def setUp(self, session=None): self.parser = EPTRNParser() self.dummy_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'support/dummy_eptrn_raw') def test_process_parses_a_sample_file(self): parsed = self.parser.process(self.dummy_file_path) self.assertEqual(parsed['RECORD_OF_CHARGE_DETAIL_RECORD'][0]['TLRR_PAYMENT_NUMBER'], 'DUMT1234') self.assertEqual(parsed['RECORD_OF_CHARGE_DETAIL_RECORD'][0]['TLRR_CM_REF_NO'], '12345LMNA11') def test_process_has_types_casted_when_they_are_configured(self): parsed = self.parser.process(self.dummy_file_path) self.assertEqual(parsed['RECORD_OF_CHARGE_DETAIL_RECORD'][0]['TLRR_SOC_AMOUNT'], 373.05) self.assertEqual(parsed['RECORD_OF_CHARGE_DETAIL_RECORD'][0]['TLRR_TRAN_DATE'], datetime.datetime(2013, 3, 6)) self.assertEqual(parsed['SUMMARY_RECORD'][0]['DEBIT_BALANCE_AMOUNT'], 0.0)
class TestJoiner(unittest.TestCase): def setUp(self, session=None): self.parser = EPTRNParser() self.dummy_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'support/dummy_eptrn_raw') def test_left_outer_join_sections_joins_sections_on_requested_fields(self): parsed = self.parser.process(self.dummy_file_path) def join_condition(left_instance, right_instance): return left_instance['TLRR_PAYMENT_NUMBER'] == right_instance['PAYMENT_NUMBER'] joined = Joiner.left_outer_join_sections( left_collection=parsed['RECORD_OF_CHARGE_DETAIL_RECORD'], right_collection=parsed['SUMMARY_RECORD'], join_condition=join_condition ) self.assertEqual(joined[0]['PAYMENT_DATE'], datetime.datetime(2013, 3, 9)) self.assertEqual(joined[0]['AMEX_PAYEE_NUMBER'], 3491124567) self.assertEqual(joined[0]['PAYMENT_NUMBER'], joined[0]['TLRR_PAYMENT_NUMBER'])
def setUp(self, session=None): self.parser = EPTRNParser() self.dummy_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'support/dummy_eptrn_raw')
def setUp(self, session=None): self.parser = EPTRNParser() self.dummy_file_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'support/dummy_eptrn_raw')