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

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 = "Executes WS-PKI command using direct bank connection."

13

14 def add_arguments(self, parser: CommandParser):

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

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

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

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

19 parser.add_argument("--soap-action-header", action="store_true")

20 parser.add_argument("--xml-sig", action="store_true")

21 parser.add_argument("--lowercase-env", action="store_true")

22

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

24 if options["process_response"]:

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

26 assert isinstance(soap_call, WsEdiSoapCall)

27 if not soap_call.debug_response_full_path:

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

29 content = open(soap_call.debug_response_full_path, "rb").read() # noqa

30 process_wspki_response(content, soap_call)

31 return

32

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

34 assert isinstance(ws, WsEdiConnection)

35 if ws and not ws.enabled:

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

37 return

38

39 cmd = options["cmd"]

40 payout_party_id = options["payout_party_id"]

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

42 assert isinstance(payout_party, PayoutParty)

43 response = wspki_execute(

44 ws,

45 payout_party=payout_party,

46 command=cmd,

47 soap_action_header=options["soap_action_header"],

48 xml_sig=options["xml_sig"],

49 lowercase_environment=options["lowercase_env"],

50 verbose=True,

51 )

52 print(format_xml_bytes(response).decode())