Coverage for jbank/management/commands/test_app_req.py : 44%

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
1import logging
2from django.core.management.base import CommandParser
3from jutil.command import SafeCommand
4from jutil.format import format_xml_bytes, format_xml
5from jbank.helpers import validate_xml
6from jbank.models import WsEdiConnection
9logger = logging.getLogger(__name__)
12class Command(SafeCommand):
13 help = 'Makes test application request'
15 def add_arguments(self, parser: CommandParser):
16 parser.add_argument('--ws', type=int, default=1)
17 parser.add_argument('--xsd', type=str)
18 parser.add_argument('--command', type=str, default='DownloadFileList')
19 parser.add_argument('--file', type=str)
21 def do(self, *args, **options):
22 ws = WsEdiConnection.objects.get(id=options['ws'])
23 if options['file']:
24 content = open(options['file'], 'rb').read()
25 else:
26 content = ws.get_application_request(options['command']).encode()
27 print('------------------------------------------------- Application request')
28 print(format_xml_bytes(content).decode())
29 if options['xsd']:
30 validate_xml(content, options['xsd'])
31 print('------------------------------------------------- Signed request')
32 print(format_xml(ws.sign_application_request(content.decode())))