Exemple #1
0
    def test_unknown_deposit_tc(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '99THISISANUNKNOWNCODE                                                           ',
            '7000000001000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            parser.parse(data)
    def test_unknown_deposit_tc(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '99THISISANUNKNOWNCODE                                                           ',
            '7000000001000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            parser.parse(data)
Exemple #3
0
    def test_missing_deposit(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '200000000000                  1500073000000000000000100214978502770700          ',
            '7000000001000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            parser.parse(data)
    def test_missing_deposit(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '200000000000                  1500073000000000000000100214978502770700          ',
            '7000000001000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            parser.parse(data)
    def test_single_payment(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '200000000000                  1500073000000000000000100214978502770700          ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.deposits), 1)
        self.assertEquals(len(f.payments), 1)

        d = f.deposits[0]
        self.assertIsInstance(d.bg, content.BgNo)
        self.assertEquals(str(d.bg), '991-2346')
        self.assertEquals(d.currency, 'SEK')
        self.assertIsNone(d.pg)
        self.assertEquals(len(d.payments), 1)
        self.assertEquals(d.payments[0], f.payments[0])

        p = f.payments[0]
        self.assertIsInstance(p.sender, content.PaymentSender)
        self.assertIsNone(p.sender.bg)
        self.assertEquals(p.amount, 1.0)
        self.assertIsInstance(p.ref, content.PaymentReference)
        self.assertEquals(str(p.ref), '1500073')
        self.assertEquals(p.ref.ref_type, pybgmax.REFTYPE_OCR)
        self.assertEquals(p.channel, pybgmax.CHANNEL_EBANK)
        self.assertEquals(p.serial, '497850277070')
        self.assertFalse(p.has_image)
Exemple #6
0
    def test_missing_header(self):
        data = (
            '7000000000000000000000000000000000                                              '
        )

        with self.assertRaises(errors.FormatError):
            f = parser.parse(data)
Exemple #7
0
    def test_single_payment(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '200000000000                  1500073000000000000000100214978502770700          ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.deposits), 1)
        self.assertEquals(len(f.payments), 1)

        d = f.deposits[0]
        self.assertIsInstance(d.bg, content.BgNo)
        self.assertEquals(str(d.bg), '991-2346')
        self.assertEquals(d.currency, 'SEK')
        self.assertEquals(d.payment_date, '20090603')
        self.assertIsNone(d.pg)
        self.assertEquals(len(d.payments), 1)
        self.assertEquals(d.payments[0], f.payments[0])

        p = f.payments[0]
        self.assertIsInstance(p.sender, content.PaymentSender)
        self.assertIsNone(p.sender.bg)
        self.assertEquals(p.amount, 1.0)
        self.assertIsInstance(p.references[0], content.PaymentReference)
        self.assertEquals(str(p.references[0]), '1500073')
        self.assertEquals(p.references[0].ref_type, pybgmax.REFTYPE_OCR)
        self.assertEquals(p.channel, pybgmax.CHANNEL_EBANK)
        self.assertEquals(p.serial, '497850277070')
        self.assertFalse(p.has_image)
Exemple #8
0
    def test_payment_reference(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '200000000000                  1500073000000000000000100214978502770700          ',
            '2200037835117495575                  000000000000100000530000000000301          ',
            '220003783511                   695668000000000000050000230000000000301          ',
            '2200037835118988777                  000000000000040000530000000000301          ',
            '230003783511                   744565000000000000050000230000000000301          ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 1)

        p = f.payments[0]
        self.assertEquals(len(p.references), 5)
        self.assertIsInstance(p.references[0], content.PaymentReference)
        self.assertEquals(str(p.references[0]), '1500073')
        self.assertEquals(p.references[0].ref_type, pybgmax.REFTYPE_OCR)
        self.assertIsInstance(p.references[1], content.PaymentReference)
        self.assertEquals(str(p.references[1]), '7495575')
        self.assertEquals(p.references[1].ref_type, pybgmax.REFTYPE_BAD)
        self.assertIsInstance(p.references[2], content.PaymentReference)
        self.assertEquals(str(p.references[2]), '695668')
        self.assertEquals(p.references[2].ref_type, pybgmax.REFTYPE_OCR)
        self.assertIsInstance(p.references[3], content.PaymentReference)
        self.assertEquals(str(p.references[3]), '8988777')
        self.assertEquals(p.references[3].ref_type, pybgmax.REFTYPE_BAD)
        self.assertIsInstance(p.references[4], content.PaymentReference)
        self.assertEquals(str(p.references[4]), '744565')
        self.assertEquals(p.references[4].ref_type, pybgmax.REFTYPE_OCR)
Exemple #9
0
    def test_malformed_header(self):
        data = '\n'.join((
            'This is not a real header                                                       ',
            '7000000000000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            f = parser.parse(data)
Exemple #10
0
    def test_malformed_timestamp(self):
        data = '\n'.join((
            '01BGMAX               01201508051XX822000100P                                   ',
            '7000000000000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            f = parser.parse(data)
Exemple #11
0
    def test_unknown_stage(self):
        data = '\n'.join((
            '01BGMAX               0120150805133822000100X                                   ',
            '7000000000000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            f = parser.parse(data)
Exemple #12
0
    def test_unknown_version(self):
        data = '\n'.join((
            '01BGMAX               0220150805133822900094P                                   ',
            '7000000000000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            f = parser.parse(data)
Exemple #13
0
    def test_unknown_format(self):
        data = '\n'.join((
            '01UNKNOWN             0120150805133822900094P                                   ',
            '7000000000000000000000000000000000                                              '
        ))

        with self.assertRaises(errors.FormatError):
            f = parser.parse(data)
Exemple #14
0
    def test_trailing(self):
        data = '\n'.join((
            '01BGMAX               0120150805133822000104P                                   ',
            '7000000000000000000000000000000000                                              ',
            'Trailing content should not be here                                             '
        ))

        with self.assertRaises(errors.FormatError):
            f = parser.parse(data)
Exemple #15
0
def load(txt_file):
    data = None
    if isinstance(txt_file, str):
        with open(txt_file, 'r', encoding='ISO-8859-1') as fp:
            data = fp.read()
    elif hasattr(txt_file, 'read'):
        data = txt_file.read()
    else:
        raise ValueError('txt_file must be file-like or path string')

    return parse(data)
Exemple #16
0
    def test_unknown_payment_tc(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '300000000000                  1500073000000000000000100214978502770700          ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 0)
Exemple #17
0
    def test_unknown_payment_tc(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '300000000000                  1500073000000000000000100214978502770700          ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 0)
Exemple #18
0
    def test_sender_bg(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '20000378351165598                    00000000000001000024                       ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000004000000000000000000000001                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(str(f.payments[0].sender.bg), '378-3511')
Exemple #19
0
    def test_sender_bg(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '20000378351165598                    00000000000001000024                       ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000004000000000000000000000001                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(str(f.payments[0].sender.bg), '378-3511')
Exemple #20
0
    def test_stage_test(self):
        data = '\n'.join((
            '01BGMAX               0120150805133822000100T                                   ',
            '7000000000000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(f.version, 1)
        self.assertEquals(f.timestamp, datetime(2015,8,5,13,38,22, 100))
        self.assertEquals(f.stage, 'T')
        self.assertTrue(f.is_test)
        self.assertEquals(len(f.payments), 0)
Exemple #21
0
    def test_correctly_formatted_empty(self):
        data = '\n'.join((
            '01BGMAX               0120150805133822000100P                                   ',
            '7000000000000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(f.version, 1)
        self.assertEquals(f.timestamp, datetime(2015,8,5,13,38,22, 100))
        self.assertEquals(f.stage, 'P')
        self.assertFalse(f.is_test)
        self.assertEquals(len(f.payments), 0)
Exemple #22
0
def load(txt_file):
    data = None
    if isinstance(txt_file, str):
        with open(txt_file, 'r', encoding='ISO-8859-1') as fp:
            data = fp.read()
    elif hasattr(txt_file, 'read'):
        data = txt_file.read()
        if isinstance(data, bytes):
            data = data.decode('utf-8')
    else:
        raise ValueError('txt_file must be file-like or path string')

    return parse(data)
Exemple #23
0
    def test_deduction(self):
        # Deductions are not implemented but should not fail
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '210000000000                  1500073000000000000000100214978502770700          ',
            '26JANE DOE                                                                      ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 0)
Exemple #24
0
    def test_deduction(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '210000000000                  1500073000000000000000100214978502770700          ',
            '25Betalning med extra refnr 65test                                              ',
            '26JANE DOE                                                                      ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.deductions), 1)
Exemple #25
0
    def test_sender_org_no(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '20000378351165598                    00000000000001000024                       ',
            '29005500001234                                                                  ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000004000000000000000000000001                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 1)

        p = f.payments[0]
        self.assertEquals(str(p.sender.org_no), '550000-1234')
Exemple #26
0
    def test_sender_org_no(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '20000378351165598                    00000000000001000024                       ',
            '29005500001234                                                                  ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000004000000000000000000000001                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 1)

        p = f.payments[0]
        self.assertEquals(str(p.sender.org_no), '550000-1234')
Exemple #27
0
    def test_payment_description(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '200000000000                  1500073000000000000000100214978502770700          ',
            '25Betalning med extra refnr 65test                                              ',
            '26JANE DOE                                                                      ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        p = f.payments[0]

        self.assertEquals(str(p.information_text[0]),
                          'Betalning med extra refnr 65test')
Exemple #28
0
    def test_sender_address(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '20000378351165598                    00000000000001000024                       ',
            '26Kalles Plat AB                                                                ',
            '27Storgatan 2                        12345                                      ',
            '28Storaker                                                                      ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000004000000000000000000000001                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 1)

        p = f.payments[0]
        self.assertEquals(p.sender.name, 'Kalles Plat AB')
        self.assertEquals(p.sender.address[0], 'Storgatan 2 12345')
        self.assertEquals(p.sender.address[1], 'Storaker')
Exemple #29
0
    def test_sender_address(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '20000378351165598                    00000000000001000024                       ',
            '26Kalles Plat AB                                                                ',
            '27Storgatan 2                        12345                                      ',
            '28Storaker                                                                      ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000004000000000000000000000001                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 1)

        p = f.payments[0]
        self.assertEquals(p.sender.name, 'Kalles Plat AB')
        self.assertEquals(p.sender.address.address, 'Storgatan 2')
        self.assertEquals(p.sender.address.post_code, '12345')
        self.assertEquals(p.sender.address.town, 'Storaker')
Exemple #30
0
    def test_payment_sender_address(self):
        data = '\n'.join((
            '01BGMAX               0120120914173035010331P                                   ',
            '050009912346          SEK                                                       ',
            '200000000000                  1500073000000000000000100214978502770700          ',
            '27Storozhenka 14 Storozhenka 14      80000                                      ',
            '28Kyiv                                                                  UA      ',
            '15000000000000000000058410000010098232009060300036000000000000070000SEK00000004 ',
            '7000000001000000000000000000000000                                              '
        ))

        f = parser.parse(data)
        self.assertEquals(len(f.payments), 1)

        p = f.payments[0]
        self.assertEquals(p.sender.address.address,
                          'Storozhenka 14 Storozhenka 14')
        self.assertEquals(p.sender.address.post_code, '80000')
        self.assertEquals(p.sender.address.town, 'Kyiv')
        self.assertEquals(p.sender.address.country, '')
        self.assertEquals(p.sender.address.country_code, 'UA')
Exemple #31
0
 def test_none(self):
     with self.assertRaises(TypeError):
         f = parser.parse(None)
Exemple #32
0
 def test_empty(self):
     with self.assertRaises(ValueError):
         f = parser.parse('')