Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 14, 2024
1 parent 74200df commit 71c022a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
4 changes: 3 additions & 1 deletion payments/paypal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ def process_data(self, payment, request):
payment.attrs.payer_info = executed_payment["payer"]["payer_info"]
if self._capture:
payment.captured_amount = payment.total
payment.objects.filter(pk=payment.pk).update(captured_amount=payment.captured_amount)
payment.objects.filter(pk=payment.pk).update(
captured_amount=payment.captured_amount
)
payment.change_status(PaymentStatus.CONFIRMED)
else:
payment.change_status(PaymentStatus.PREAUTH)
Expand Down
44 changes: 37 additions & 7 deletions payments/paypal/test_paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get(self, *args, **kwargs):
if args or kwargs:
return self.filter(*args, **kwargs).get()
payment = Payment()
payment_fields, = self.__payments.values()
(payment_fields,) = self.__payments.values()
for payment_field_name, payment_field_value in payment_fields.items():
setattr(payment, payment_field_name, deepcopy(payment_field_value))
return payment
Expand All @@ -60,14 +60,23 @@ def filter(self, *args, pk=None, **kwargs):
if args or kwargs:
raise NotImplementedError(f"arguments not supported yet: {args}, {kwargs}")
if pk is not None:
return PaymentQuerySet({pk_: payment for pk_, payment in self.__payments.items() if pk_ == pk})
return PaymentQuerySet(
{pk_: payment for pk_, payment in self.__payments.items() if pk_ == pk}
)
return self

def update(self, **kwargs):
for payment in self.__payments.values():
for field_name, field_value in kwargs.items():
if not any(field.name == field_name for field in Payment._meta.get_fields(include_parents=True, include_hidden=True)):
raise NotImplementedError(f"updating unknown field not supported yet: {field_name}")
if not any(
field.name == field_name
for field in Payment._meta.get_fields(
include_parents=True, include_hidden=True
)
):
raise NotImplementedError(
f"updating unknown field not supported yet: {field_name}"
)
payment[field_name] = deepcopy(field_value)

def delete(self):
Expand Down Expand Up @@ -129,8 +138,15 @@ def save(self, *args, update_fields=None, **kwargs):
if args or kwargs:
raise NotImplementedError(f"arguments not supported yet: {args}, {kwargs}")
if update_fields is None:
update_fields = {field.name for field in self._meta.get_fields(include_parents=True, include_hidden=True)}
Payment.objects.filter(pk=self.pk).update(**{field: getattr(self, field) for field in update_fields})
update_fields = {
field.name
for field in self._meta.get_fields(
include_parents=True, include_hidden=True
)
}
Payment.objects.filter(pk=self.pk).update(
**{field: getattr(self, field) for field in update_fields}
)

def refresh_from_db(self, *args, **kwargs):
if args or kwargs:
Expand All @@ -143,7 +159,21 @@ def refresh_from_db(self, *args, **kwargs):
class Meta(Mock):
def get_fields(self, include_parents=True, include_hidden=False):
fields = []
for field_name in {"id", "description", "currency", "delivery", "status", "tax", "token", "total", "captured_amount", "variant", "transaction_id", "message", "extra_data"}:
for field_name in {
"id",
"description",
"currency",
"delivery",
"status",
"tax",
"token",
"total",
"captured_amount",
"variant",
"transaction_id",
"message",
"extra_data",
}:
field = Mock()
field.name = field_name
fields.append(field)
Expand Down

0 comments on commit 71c022a

Please sign in to comment.