Skip to content

Commit

Permalink
test: fix tests for python upgrade and update python version for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mudassir-hafeez committed Aug 6, 2024
1 parent 8269d48 commit 9de8453
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9.15"
python-version: "3.12.4"
cache: "poetry"

- name: Install dependencies
Expand Down
3 changes: 2 additions & 1 deletion courses/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import factory
import pytest
import pytz
from django.contrib.auth.models import AnonymousUser

from cms.constants import FORMAT_ONLINE, FORMAT_OTHER
Expand Down Expand Up @@ -106,7 +107,7 @@ def test_serialize_program( # noqa: PLR0913

non_live_run = CourseRunFactory.create(
course=course1,
end_date=datetime.max.astimezone(timezone.utc),
end_date=datetime.max.replace(tzinfo=pytz.utc),
expiration_date=None,
live=False,
)
Expand Down
8 changes: 4 additions & 4 deletions ecommerce/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ def test_get_by_reference_number(
same_order = Order.objects.get_by_reference_number(order.reference_number)
assert same_order.id == order.id
if hubspot_api_key:
assert mock_hubspot_syncs.order.called_with(order.id) # noqa: PGH005
mock_hubspot_syncs.order.assert_called_with(order.id) # noqa: PGH005
else:
assert mock_hubspot_syncs.order.not_called() # noqa: PGH005
mock_hubspot_syncs.order.assert_not_called() # noqa: PGH005


def test_get_by_reference_number_missing(validated_basket):
Expand Down Expand Up @@ -771,9 +771,9 @@ def test_create_unfulfilled_order( # noqa: PLR0913
assert CouponRedemption.objects.count() == 0

if hubspot_api_key:
assert mock_hubspot_syncs.order.called_with(order.id) # noqa: PGH005
mock_hubspot_syncs.order.assert_called_with(order.id) # noqa: PGH005
else:
assert mock_hubspot_syncs.order.not_called() # noqa: PGH005
mock_hubspot_syncs.order.assert_not_called() # noqa: PGH005


@pytest.mark.parametrize("has_program_run", [True, False])
Expand Down
7 changes: 4 additions & 3 deletions ecommerce/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,12 @@ def test_product_version_save_text_id_badproduct(mocker):
"""ProductVersion.text_id should None if ProductVersion.product is invalid"""
mock_log = mocker.patch("ecommerce.models.log")
product_version = ProductVersionFactory.create(
product=ProductFactory.create(content_object=LineFactory())
product=ProductFactory.create(content_object=LineFactory()), id=1
)
assert product_version.text_id is None
assert mock_log.called_once_with( # noqa: PGH005
f"The content object for this ProductVersion ({product_version.id}) does not have a `text_id` property"
mock_log.error.assert_called_once_with(
"The content object for this ProductVersion (%s) does not have a `text_id` property",
str(product_version.id),
)


Expand Down
8 changes: 4 additions & 4 deletions ecommerce/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ def test_zero_price_checkout( # noqa: PLR0913
assert CourseRunSelection.objects.filter(basket__user=user).count() == 0
assert CouponSelection.objects.filter(basket__user=user).count() == 0
if hubspot_api_key:
assert mock_hubspot_syncs.order.called_with(order.id) # noqa: PGH005
mock_hubspot_syncs.order.assert_called_with(order.id) # noqa: PGH005
else:
assert mock_hubspot_syncs.order.not_called() # noqa: PGH005
mock_hubspot_syncs.order.assert_not_called() # noqa: PGH005


@pytest.mark.parametrize("hubspot_api_key", [None, "fake-key"])
Expand Down Expand Up @@ -287,9 +287,9 @@ def test_order_fulfilled( # noqa: PLR0913
assert CouponSelection.objects.filter(basket__user=user).count() == 0

if hubspot_api_key:
assert mock_hubspot_syncs.order.called_with(order.id) # noqa: PGH005
mock_hubspot_syncs.order.assert_called_with(order.id) # noqa: PGH005
else:
assert mock_hubspot_syncs.order.not_called() # noqa: PGH005
mock_hubspot_syncs.order.assert_not_called() # noqa: PGH005


def test_order_affiliate(basket_client, mocker, basket_and_coupons):
Expand Down
9 changes: 4 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ django-debug-toolbar = "*"
factory-boy = "3.3.0"
faker = "13.16.0"
freezegun = "0.3.15"
hypothesis = "4.23.4"
hypothesis = "4.24.6"
ipdb = "*"
nplusone = ">=0.8.1"
pdbpp = "*"
Expand Down
2 changes: 1 addition & 1 deletion users/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def state_or_territory(self):
if self.country not in {"US", "CA"}:
return ""
subdivisions = pycountry.subdivisions.get(country_code=self.country)
subdivision = random.randgen.sample(subdivisions, 1)[0]
subdivision = random.randgen.sample(list(subdivisions), 1)[0]
# Example: "US-MA" # noqa: ERA001
return subdivision.code

Expand Down

0 comments on commit 9de8453

Please sign in to comment.