Coverage for jbank/management/commands/wspki_exec.py: 0%

# Coverage for jbank/management/commands/wspki_exec.py : 0%

## 34 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 jbank.models import WsEdiConnection, WsEdiSoapCall, PayoutParty

5 from jbank.wspki import wspki_execute, process_wspki_response

6 from jutil.format import format_xml_bytes

7

8 logger = logging.getLogger(__name__)

9

10

11 class Command(SafeCommand):

12 help = """

13 Executes WS-PKI command using direct bank connection.

14 """

15

16 def add_arguments(self, parser: CommandParser):

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

18 parser.add_argument("--cmd", type=str, required=True)

19 parser.add_argument("--payout-party-id", type=int, required=True)

20 parser.add_argument("--process-response", type=int)

21

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

23 if options["process_response"]:

24 soap_call = WsEdiSoapCall.objects.get(id=options["process_response"])

25 assert isinstance(soap_call, WsEdiSoapCall)

26 if not soap_call.debug_response_full_path:

27 raise Exception("SOAP call response not available")

28 content = open(soap_call.debug_response_full_path, "rb").read()

29 process_wspki_response(content, soap_call)

30 return

31

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

33 assert isinstance(ws, WsEdiConnection)

34 if ws and not ws.enabled:

35 logger.info("WS connection %s not enabled, exiting", ws)

36 return

37

38 cmd = options["cmd"]

39 payout_party_id = options["payout_party_id"]

40 payout_party = PayoutParty.objects.get(id=payout_party_id)

41 assert isinstance(payout_party, PayoutParty)

42 response = wspki_execute(ws, payout_party=payout_party, command=cmd, verbose=True)

43 print(format_xml_bytes(response).decode())