Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#3374)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.9.1](astral-sh/ruff-pre-commit@v0.8.6...v0.9.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: pre-commit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Muhammad Anas <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and Anas12091101 authored Jan 14, 2025
1 parent 220ca7b commit dd75f2f
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:
- --exclude-files
- "_test.js$"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.6"
rev: "v0.9.1"
hooks:
- id: ruff-format
- id: ruff
Expand Down
4 changes: 2 additions & 2 deletions b2b_ecommerce/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def post(

base_url = request.build_absolute_uri("/")
receipt_url = (
f'{urljoin(base_url, reverse("bulk-enrollment-code-receipt"))}?'
f'{urlencode({"hash": str(order.unique_id)})}'
f"{urljoin(base_url, reverse('bulk-enrollment-code-receipt'))}?"
f"{urlencode({'hash': str(order.unique_id)})}"
)
cancel_url = urljoin(base_url, reverse("bulk-enrollment-code"))
if total_price == 0:
Expand Down
22 changes: 11 additions & 11 deletions b2b_ecommerce/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_create_order(client, mocker):
assert order.num_seats == num_seats
assert order.b2breceipt_set.count() == 0
base_url = "http://testserver/"
receipt_url = f'{urljoin(base_url, reverse("bulk-enrollment-code-receipt"))}?hash={str(order.unique_id)}' # noqa: RUF010
receipt_url = f"{urljoin(base_url, reverse('bulk-enrollment-code-receipt'))}?hash={str(order.unique_id)}" # noqa: RUF010
assert generate_mock.call_count == 1
assert generate_mock.call_args[0] == ()
assert generate_mock.call_args[1] == {
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_create_order_with_coupon(client, mocker):
assert order.num_seats == num_seats
assert order.b2breceipt_set.count() == 0
base_url = "http://testserver/"
receipt_url = f'{urljoin(base_url, reverse("bulk-enrollment-code-receipt"))}?hash={str(order.unique_id)}' # noqa: RUF010
receipt_url = f"{urljoin(base_url, reverse('bulk-enrollment-code-receipt'))}?hash={str(order.unique_id)}" # noqa: RUF010
assert generate_payload_mock.call_count == 1
assert generate_payload_mock.call_args[0] == ()
assert generate_payload_mock.call_args[1] == {
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_zero_price_checkout(client, mocker):
assert B2BOrder.objects.count() == 1
order = B2BOrder.objects.first()
base_url = "http://testserver"
receipt_url = f'{urljoin(base_url, reverse("bulk-enrollment-code-receipt"))}?hash={str(order.unique_id)}' # noqa: RUF010
receipt_url = f"{urljoin(base_url, reverse('bulk-enrollment-code-receipt'))}?hash={str(order.unique_id)}" # noqa: RUF010
assert resp.status_code == status.HTTP_200_OK
assert resp.json() == {"payload": {}, "url": receipt_url, "method": "GET"}

Expand Down Expand Up @@ -443,8 +443,8 @@ def test_coupon_view(client):
coupon = B2BCouponFactory.create(product=order.product_version.product)
B2BCouponRedemption.objects.create(coupon=coupon, order=order)
response = client.get(
f'{reverse("b2b-coupon-view")}?'
f'{urlencode({"code": coupon.coupon_code, "product_id": order.product_version.product_id})}'
f"{reverse('b2b-coupon-view')}?"
f"{urlencode({'code': coupon.coupon_code, 'product_id': order.product_version.product_id})}"
)
assert response.status_code == status.HTTP_200_OK
assert response.json() == {
Expand All @@ -460,8 +460,8 @@ def test_coupon_view_product_with_text_id(client):
coupon = B2BCouponFactory.create(product=order.product_version.product)
B2BCouponRedemption.objects.create(coupon=coupon, order=order)
response = client.get(
f'{reverse("b2b-coupon-view")}?'
f'{urlencode({"code": coupon.coupon_code, "product_id": order.product_version.text_id})}'
f"{reverse('b2b-coupon-view')}?"
f"{urlencode({'code': coupon.coupon_code, 'product_id': order.product_version.text_id})}"
)
assert response.status_code == status.HTTP_200_OK
assert response.json() == {
Expand All @@ -479,8 +479,8 @@ def test_reusable_coupon_order_fulfilled(client, reusable, order_status):
coupon = B2BCouponFactory.create(product=None, reusable=reusable)
B2BCouponRedemption.objects.create(coupon=coupon, order=order)
response = client.get(
f'{reverse("b2b-coupon-view")}?'
f'{urlencode({"code": coupon.coupon_code, "product_id": order.product_version.product_id})}'
f"{reverse('b2b-coupon-view')}?"
f"{urlencode({'code': coupon.coupon_code, 'product_id': order.product_version.product_id})}"
)

if reusable:
Expand All @@ -500,7 +500,7 @@ def test_coupon_view_invalid(client, mocker):
B2BCoupon.objects, "get_unexpired_coupon", side_effect=B2BCoupon.DoesNotExist
)
params = {"code": "x", "product_id": 3}
response = client.get(f'{reverse("b2b-coupon-view")}?' f"{urlencode(params)}")
response = client.get(f"{reverse('b2b-coupon-view')}?{urlencode(params)}")
assert response.status_code == status.HTTP_404_NOT_FOUND
patched.assert_called_once_with(
coupon_code=params["code"], product_id=params["product_id"]
Expand All @@ -512,6 +512,6 @@ def test_coupon_view_missing_param(client, key):
"""Information about a coupon should be returned"""
params = {"code": "code", "product_id": "product_id"}
del params[key]
response = client.get(f'{reverse("b2b-coupon-view")}?{urlencode(params)}')
response = client.get(f"{reverse('b2b-coupon-view')}?{urlencode(params)}")
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json() == {"errors": [f"Missing parameter {key}"]}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def migrate_external_courses(apps, schema_editor):
defaults={
"is_external": True,
"title": external_course.title,
"live" "": external_course.live,
"live": external_course.live,
},
)
# If already exists, Just set value for newly added field
Expand Down
4 changes: 3 additions & 1 deletion courses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ def get_receipt(self, enrollment):
def __init__(self, *args, **kwargs):
assert ( # noqa: PT018, S101
"context" in kwargs and "course_run_enrollments" in kwargs["context"]
), "An iterable of course run enrollments must be passed in the context (key: course_run_enrollments)"
), (
"An iterable of course run enrollments must be passed in the context (key: course_run_enrollments)"
)
super().__init__(*args, **kwargs)

def get_course_run_enrollments(self, instance):
Expand Down
4 changes: 2 additions & 2 deletions courses/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_course_view( # noqa: PLR0913
class_name = ""
if not is_anonymous:
if not is_enrolled and has_product and has_unexpired_run:
url = f'{reverse("checkout-page")}?product={product_id}'
url = f"{reverse('checkout-page')}?product={product_id}"
class_name = "enroll-now"
if is_enrolled and has_unexpired_run:
url = reverse("user-dashboard")
Expand Down Expand Up @@ -354,7 +354,7 @@ def test_program_view( # noqa: PLR0913
class_name = ""
if not is_anonymous:
if not is_enrolled and has_product and has_unexpired_run:
url = f'{reverse("checkout-page")}?product={product_id}'
url = f"{reverse('checkout-page')}?product={product_id}"
class_name = "enroll-now"
if is_enrolled:
url = reverse("user-dashboard")
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def test_get_valid_coupon_versions_full_discount(basket_and_coupons):
full_discount=True,
)
) == [basket_and_coupons.coupongroup_best.coupon_version]
assert basket_and_coupons.coupongroup_best.payment_version.amount == Decimal(1.0)
assert basket_and_coupons.coupongroup_best.payment_version.amount == Decimal("1.0")


def test_get_valid_coupon_versions_by_company(basket_and_coupons):
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/mail_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ def send_b2b_receipt_email(order):
date_range = ""

download_url = (
f'{urljoin(settings.SITE_BASE_URL, reverse("bulk-enrollment-code-receipt"))}?'
f'{urlencode({"hash": str(order.unique_id)})}'
f"{urljoin(settings.SITE_BASE_URL, reverse('bulk-enrollment-code-receipt'))}?"
f"{urlencode({'hash': str(order.unique_id)})}"
)
try:
api.send_message(
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/mail_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_send_b2b_receipt_email(mocker, settings, has_discount):
send_b2b_receipt_email(order)

run = order.product_version.product.content_object
download_url = f'{urljoin(settings.SITE_BASE_URL, reverse("bulk-enrollment-code-receipt"))}?hash={str(order.unique_id)}' # noqa: RUF010
download_url = f"{urljoin(settings.SITE_BASE_URL, reverse('bulk-enrollment-code-receipt'))}?hash={str(order.unique_id)}" # noqa: RUF010

patched_mail_api.context_for_user.assert_called_once_with(
user=None,
Expand Down
8 changes: 4 additions & 4 deletions ecommerce/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def calculate_discount_amount(self, product_version=None, price=None):
price = price or (product_version.price if product_version else None)

if not price:
return Decimal(0.00)
return Decimal("0.00")

price = Decimal(price)

Expand All @@ -643,7 +643,7 @@ def calculate_discount_amount(self, product_version=None, price=None):
elif self.discount_type == DISCOUNT_TYPE_DOLLARS_OFF:
return round_half_up(self.amount)
else:
return Decimal(0.00)
return Decimal("0.00")

def calculate_discount_percent(self, product_version=None, price=None):
"""
Expand All @@ -655,14 +655,14 @@ def calculate_discount_percent(self, product_version=None, price=None):
price = price or (product_version.price if product_version else None)

if not price:
return Decimal(0.00)
return Decimal("0.00")

if self.discount_type == DISCOUNT_TYPE_PERCENT_OFF:
return round_half_up(self.amount * 100)
elif self.discount_type == DISCOUNT_TYPE_DOLLARS_OFF:
return round_half_up((self.amount / price) * 100)
else:
return Decimal(0.00)
return Decimal("0.00")


class Coupon(TimestampedModel):
Expand Down
6 changes: 3 additions & 3 deletions hubspot_xpro/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def test_serialize_order(settings, hubspot_order, status):
@pytest.mark.parametrize(
"discount_type, amount", # noqa: PT006
[
[DISCOUNT_TYPE_PERCENT_OFF, Decimal(0.75)], # noqa: PT007
[DISCOUNT_TYPE_DOLLARS_OFF, Decimal(75)], # noqa: PT007
[DISCOUNT_TYPE_PERCENT_OFF, Decimal("0.75")], # noqa: PT007
[DISCOUNT_TYPE_DOLLARS_OFF, Decimal("75")], # noqa: PT007
],
)
def test_serialize_order_with_coupon(settings, hubspot_order, discount_type, amount):
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_serialize_b2b_order_with_coupon(settings, client, mocker):
return_value=payload,
)
coupon = B2BCouponFactory.create(
product=product_version.product, discount_percent=Decimal(0.8)
product=product_version.product, discount_percent=Decimal("0.8")
)
num_seats = 10
resp = client.post(
Expand Down
2 changes: 1 addition & 1 deletion hubspot_xpro/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_batch_upsert_associations_chunked(mocker):
for order in orders:
LineFactory.create(
order=order,
product_version=ProductVersionFactory.create(price=Decimal(200.00)),
product_version=ProductVersionFactory.create(price=Decimal("200.00")),
)
expected_line_associations = [
PublicAssociation(
Expand Down
2 changes: 1 addition & 1 deletion mitxpro/tests/js_interop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_js_settings(mocker, rf):

request = rf.get("/")
context = Context({"request": request})
template = Template("{% load js_interop %}" "{% js_settings %}")
template = Template("{% load js_interop %}{% js_settings %}")

rendered_template = template.render(context)
assert (
Expand Down
12 changes: 6 additions & 6 deletions sheets/coupon_request_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def test_full_sheet_process(
expected_processed_rows = {6, 8}
expected_failed_rows = {5, 7}
assert ResultType.PROCESSED.value in result
assert (
set(result[ResultType.PROCESSED.value]) == expected_processed_rows
), f"Rows {expected_processed_rows!s} as defined in coupon_requests.csv should be processed"
assert set(result[ResultType.PROCESSED.value]) == expected_processed_rows, (
f"Rows {expected_processed_rows!s} as defined in coupon_requests.csv should be processed"
)
assert ResultType.FAILED.value in result
assert (
set(result[ResultType.FAILED.value]) == expected_failed_rows
), f"Rows {expected_failed_rows!s} as defined in coupon_requests.csv should fail"
assert set(result[ResultType.FAILED.value]) == expected_failed_rows, (
f"Rows {expected_failed_rows!s} as defined in coupon_requests.csv should fail"
)
# A CouponGenerationRequest should be created for each row that wasn't ignored and did not fail full sheet
# validation (CSV has 1 row that should fail validation, hence the 1)
assert CouponGenerationRequest.objects.all().count() == (
Expand Down
2 changes: 1 addition & 1 deletion users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def validate_street_address(self, value):
raise serializers.ValidationError(
"street_address lines must be 60 characters or less" # noqa: EM101
)
return {f"street_address_{idx+1}": line for idx, line in enumerate(value)}
return {f"street_address_{idx + 1}": line for idx, line in enumerate(value)}

def get_street_address(self, instance):
"""Return the list of street address lines"""
Expand Down
4 changes: 1 addition & 3 deletions voucher/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ def read_pdf_domestic(pdf): # noqa: C901
try:
float(last_val)
column_values[settings.VOUCHER_DOMESTIC_COURSE_KEY] = (
column_values[
settings.VOUCHER_DOMESTIC_COURSE_KEY
][
column_values[settings.VOUCHER_DOMESTIC_COURSE_KEY][
0 : column_values[
settings.VOUCHER_DOMESTIC_COURSE_KEY
].index(last_val)
Expand Down

0 comments on commit dd75f2f

Please sign in to comment.