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

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 logger = logging.getLogger(__name__)

9

10

11 class Command(SafeCommand):

12 help = "Makes test application request"

13

14 def add_arguments(self, parser: CommandParser):

15 parser.add_argument("--ws", type=int, default=1)

16 parser.add_argument("--xsd", type=str)

17 parser.add_argument("--command", type=str, default="DownloadFileList")

18 parser.add_argument("--file", type=str)

19

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

21 ws = WsEdiConnection.objects.get(id=options["ws"])

22 if options["file"]:

23 content = open(options["file"], "rb").read() # noqa

24 else:

25 content = ws.get_application_request(options["command"]).encode()

26 print("------------------------------------------------- Application request")

27 print(format_xml_bytes(content).decode())

28 if options["xsd"]:

29 validate_xml(content, options["xsd"])

30 print("------------------------------------------------- Signed request")

31 print(format_xml(ws.sign_application_request(content.decode())))