Coverage for jbank/management/commands/test_payment.py: 52%

1 import logging

2 from decimal import Decimal

3 from django.core.management.base import CommandParser

4 from jutil.command import SafeCommand

5 from jbank.helpers import make_msg_id

6 from jbank.models import Payout, PayoutParty

7

8 logger = logging.getLogger(__name__)

9

10

11 class Command(SafeCommand):

12 help = "Makes test payment"

13

14 def add_arguments(self, parser: CommandParser):

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

16 parser.add_argument("--recipient-id", type=int, default=2)

17 parser.add_argument("--messages", type=str, default="test payment")

18 parser.add_argument("--amount", type=Decimal, default=Decimal("1.23"))

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

20

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

22 payer = PayoutParty.objects.get(id=options["payer_id"])

23 p = Payout(

24 account=payer.payouts_account,

25 payer=payer,

26 recipient_id=options["recipient_id"],

27 messages=options["messages"],

28 msg_id=make_msg_id(),

29 amount=options["amount"],

30 connection_id=options["ws"],

31 )

32 p.full_clean()

33 p.save()

34 print("{} created".format(p))