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

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

## 25 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 from django.core.management.base import CommandParser

3 from jutil.command import SafeCommand

4 from jutil.format import format_xml_bytes, format_xml

5 from jbank.helpers import validate_xml

6 from jbank.models import WsEdiConnection

7

8

9 logger = logging.getLogger(__name__)

10

11

12 class Command(SafeCommand):

13 help = "Makes test application request"

14

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)

20

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())))