Coverage for jbank/management/commands/test_pain001.py: 47%

# Coverage for jbank/management/commands/test_pain001.py : 47%

## 32 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 import logging

2 import subprocess

3 from decimal import Decimal

4 from os.path import join

5 from django.conf import settings

6 from django.core.management.base import CommandParser

7 from jbank.sepa import Pain001

8 from jutil.command import SafeCommand

9 from jutil.format import format_xml, format_xml_bytes

10 from jutil.validators import iban_bic

11

12

13 logger = logging.getLogger(__name__)

14

15

16 class Command(SafeCommand):

17 help = """

18 Generates pain.001.001.03 compatible SEPA payment file.

19 """

20

21 def add_arguments(self, parser: CommandParser):

22 parser.add_argument('--verbose', action='store_true')

23 parser.add_argument('--validate', action='store_true')

24

25 def do(self, *args, **options):

26 debtor_acc = 'FI4947300010416310'

27 p = Pain001('201802071211XJANITEST', 'Kajala Group Oy', debtor_acc, iban_bic(debtor_acc), '020840699',

28 ['Koukkukankareentie 29', '20320 Turku'], 'FI')

29 creditor_acc = 'FI8847304720017517'

30 p.add_payment('201802071339A0001', 'Jani Kajala', creditor_acc, iban_bic(creditor_acc), Decimal('49.00'), 'vuokratilitys')

31 xml_str = format_xml_bytes(p.render_to_bytes()).decode()

32 print(xml_str)

33

34 filename = '/tmp/pain001.xml'

35 with open(filename, 'wt') as fp:

36 fp.write(xml_str)

37 print(filename, 'written')

38

39 if options['validate']:

40 # /usr/bin/xmllint --format --pretty 1 --load-trace --debug --schema $1 $2

41 res = subprocess.run([

42 '/usr/bin/xmllint',

43 '--format',

44 '--pretty', '1',

45 '--load-trace',

46 '--debug',

47 '--schema',

48 join(settings.BASE_DIR, 'data/pain001/pain.001.001.03.xsd'),

49 filename,

50 ])

51 if res.returncode == 0:

52 print('OK')

53 else:

54 print('FAIL')