diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fbf85c61..09594878 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -35,7 +35,7 @@ repos: sh, ] - repo: https://github.com/scop/pre-commit-shfmt - rev: v3.10.0-1 + rev: v3.11.0-1 hooks: - id: shfmt - repo: https://github.com/adrienverge/yamllint.git @@ -67,7 +67,7 @@ repos: - --exclude-files - ".*/generated/" - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.10" + rev: "v0.9.10" hooks: - id: ruff-format - id: ruff diff --git a/conftest.py b/conftest.py index d645c0ea..6d0bb09c 100644 --- a/conftest.py +++ b/conftest.py @@ -33,7 +33,7 @@ def mock_requests_get(): @pytest.fixture(autouse=True) -def prevent_requests(mocker, request): # noqa: PT004 +def prevent_requests(mocker, request): """Patch requests to error on request by default""" if "mocked_responses" in request.fixturenames: return diff --git a/fixtures/common.py b/fixtures/common.py index 5e039639..354eb258 100644 --- a/fixtures/common.py +++ b/fixtures/common.py @@ -14,13 +14,13 @@ @pytest.fixture(autouse=True) -def silence_factory_logging(): # noqa: PT004 +def silence_factory_logging(): """Only show factory errors""" logging.getLogger("factory").setLevel(logging.ERROR) @pytest.fixture(autouse=True) -def warnings_as_errors(): # noqa: PT004 +def warnings_as_errors(): """ Convert warnings to errors. This should only affect unit tests, letting pylint and other plugins raise DeprecationWarnings without erroring. @@ -49,13 +49,13 @@ def warnings_as_errors(): # noqa: PT004 warnings.resetwarnings() -@pytest.fixture() -def randomness(): # noqa: PT004 +@pytest.fixture +def randomness(): """Ensure a fixed seed for factoryboy""" factory.fuzzy.reseed_random("happy little clouds") -@pytest.fixture() +@pytest.fixture def mocked_celery(mocker): """Mock object that patches certain celery functions""" exception_class = TabError @@ -73,20 +73,20 @@ def mocked_celery(mocker): ) -@pytest.fixture() +@pytest.fixture def mock_context(mocker, user): """Mock context for serializers""" return {"request": mocker.Mock(user=user)} -@pytest.fixture() +@pytest.fixture def mocked_responses(): """Mock responses fixture""" with responses.RequestsMock() as rsps: yield rsps -@pytest.fixture() +@pytest.fixture def admin_drf_client(admin_user): """DRF API test client with admin user""" client = APIClient() diff --git a/fixtures/users.py b/fixtures/users.py index 373ae84c..688898b5 100644 --- a/fixtures/users.py +++ b/fixtures/users.py @@ -11,26 +11,26 @@ from unified_ecommerce.factories import UserFactory -@pytest.fixture() +@pytest.fixture def user(db): # noqa: ARG001 """Create a user""" return UserFactory.create() -@pytest.fixture() +@pytest.fixture def staff_user(db): # noqa: ARG001 """Create a staff user""" return UserFactory.create(is_staff=True) -@pytest.fixture() +@pytest.fixture def logged_in_user(client, user): """Log the user in and yield the user object""" client.force_login(user) return user -@pytest.fixture() +@pytest.fixture def logged_in_profile(client): """Add a Profile and logged-in User""" user = UserFactory.create(username="george") @@ -38,7 +38,7 @@ def logged_in_profile(client): return user.profile -@pytest.fixture() +@pytest.fixture def jwt_token(db, user, client, rf, settings): # noqa: ARG001 """Creates a JWT token for a regular user""" # noqa: D401 jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER @@ -50,7 +50,7 @@ def jwt_token(db, user, client, rf, settings): # noqa: ARG001 return token -@pytest.fixture() +@pytest.fixture def client(db): # noqa: ARG001 """ Similar to the builtin client but this provides the DRF client instead of the Django test client. @@ -58,7 +58,7 @@ def client(db): # noqa: ARG001 return APIClient() -@pytest.fixture() +@pytest.fixture def user_client(user): """Version of the client that is authenticated with the user""" client = APIClient() @@ -66,7 +66,7 @@ def user_client(user): return client -@pytest.fixture() +@pytest.fixture def staff_client(staff_user): """Version of the client that is authenticated with the staff_user""" client = APIClient() @@ -74,7 +74,7 @@ def staff_client(staff_user): return client -@pytest.fixture() +@pytest.fixture def profile_image(): """Create a PNG image""" image_file = BytesIO() diff --git a/payments/api_test.py b/payments/api_test.py index b5f5e818..c3e80fc3 100644 --- a/payments/api_test.py +++ b/payments/api_test.py @@ -91,13 +91,13 @@ pytestmark = [pytest.mark.django_db] -@pytest.fixture() +@pytest.fixture def fulfilled_order(): """Fixture for creating a fulfilled order""" return OrderFactory.create(state=Order.STATE.FULFILLED) -@pytest.fixture() +@pytest.fixture def fulfilled_transaction(fulfilled_order): """Fixture to creating a fulfilled transaction""" payment_amount = 10.00 @@ -115,7 +115,7 @@ def fulfilled_transaction(fulfilled_order): ) -@pytest.fixture() +@pytest.fixture def fulfilled_paypal_transaction(fulfilled_order): """Fixture to creating a fulfilled transaction""" payment_amount = 10.00 @@ -141,7 +141,7 @@ def fulfilled_paypal_transaction(fulfilled_order): ) -@pytest.fixture() +@pytest.fixture def fulfilled_complete_order(): """Create a fulfilled order with line items.""" @@ -160,14 +160,14 @@ def fulfilled_complete_order(): return order -@pytest.fixture() +@pytest.fixture def products(): """Create products""" with reversion.create_revision(): return ProductFactory.create_batch(5) -@pytest.fixture() +@pytest.fixture def user(db): """Create a user""" return UserFactory.create() diff --git a/payments/hooks/basket_add_test.py b/payments/hooks/basket_add_test.py index fa1903e8..f7f84143 100644 --- a/payments/hooks/basket_add_test.py +++ b/payments/hooks/basket_add_test.py @@ -21,13 +21,13 @@ FAKE = faker.Faker() -@pytest.fixture() +@pytest.fixture def basket(): """Create a basket.""" return BasketFactory.create() -@pytest.fixture() +@pytest.fixture def maxmimd_resolvable_ip(): """Create an IP, and then make sure there are mappings for it.""" @@ -43,7 +43,7 @@ def maxmimd_resolvable_ip(): ) -@pytest.fixture() +@pytest.fixture def user_client_and_basket(): """Create a basket, and a user client with the basket's user.""" @@ -79,7 +79,7 @@ def mock_basket_add_hook_steps(mocker, exceptfor: str | None = None): } -@pytest.fixture() +@pytest.fixture def basket_add_hook_steps(mocker): """Mock the steps in the basket_add hook.""" diff --git a/payments/hooks/post_sale_test.py b/payments/hooks/post_sale_test.py index dee27c5a..5728e0a9 100644 --- a/payments/hooks/post_sale_test.py +++ b/payments/hooks/post_sale_test.py @@ -11,7 +11,7 @@ pytestmark = [pytest.mark.django_db] -@pytest.fixture() +@pytest.fixture def pending_complete_order(): """Create a pending order with line items.""" diff --git a/payments/models.py b/payments/models.py index cd03a4e0..5e46e6f8 100644 --- a/payments/models.py +++ b/payments/models.py @@ -890,10 +890,7 @@ def _process_basket_products(self, basket): if len(product_versions) == 0: log.error( - ( - "PendingOrder._get_or_create: %s products are there " - "but no versions?" - ), + ("PendingOrder._get_or_create: %s products are there but no versions?"), len(products), ) msg = "No product versions found" diff --git a/payments/tasks.py b/payments/tasks.py index f92cddcc..6b58d4f4 100644 --- a/payments/tasks.py +++ b/payments/tasks.py @@ -53,10 +53,7 @@ def dispatch_webhook(system_webhook_url, webhook_data, attempt_count=0): if attempt_count == settings.MITOL_UE_WEBHOOK_RETRY_MAX: log.exception( - ( - "Hit the retry max (%s) for webhook URL %s for event %s, " - "giving up" - ), + ("Hit the retry max (%s) for webhook URL %s for event %s, giving up"), attempt_count, webhook_dataclass, exc_info=e, diff --git a/payments/views/v0/__init__.py b/payments/views/v0/__init__.py index cd386c62..fe3ab732 100644 --- a/payments/views/v0/__init__.py +++ b/payments/views/v0/__init__.py @@ -199,8 +199,7 @@ def _create_basket_from_product( @extend_schema( description=( - "Creates or updates a basket for the current user, " - "adding the selected product." + "Creates or updates a basket for the current user, adding the selected product." ), methods=["POST"], request=None, @@ -251,8 +250,7 @@ def create_basket_from_product_with_discount( @extend_schema( description=( - "Creates or updates a basket for the current user, " - "adding the selected product." + "Creates or updates a basket for the current user, adding the selected product." ), methods=["POST"], responses=BasketWithProductSerializer, diff --git a/refunds/fixtures.py b/refunds/fixtures.py index 8d1463b9..2d65587c 100644 --- a/refunds/fixtures.py +++ b/refunds/fixtures.py @@ -13,7 +13,7 @@ FAKE = faker.Faker() -@pytest.fixture() +@pytest.fixture def completed_order(user, integrated_system): """Create a completed order.""" diff --git a/system_meta/fixtures.py b/system_meta/fixtures.py index d93d330a..0eabccd7 100644 --- a/system_meta/fixtures.py +++ b/system_meta/fixtures.py @@ -5,7 +5,7 @@ from system_meta.factories import IntegratedSystemFactory -@pytest.fixture() +@pytest.fixture def integrated_system(): """Create an integrated system.""" return IntegratedSystemFactory() diff --git a/system_meta/management/commands/generate_test_data.py b/system_meta/management/commands/generate_test_data.py index 99c16b66..4407fe71 100644 --- a/system_meta/management/commands/generate_test_data.py +++ b/system_meta/management/commands/generate_test_data.py @@ -59,7 +59,7 @@ def fake_courseware_id(courseware_type: str, **kwargs) -> str: courseware_type = courseware_type.lower() optional_third_digit = random.randint(0, 9) if fake.boolean() else "" optional_run_tag = ( - f"+{random.randint(1,3)}T{fake.date_this_decade().year}" + f"+{random.randint(1, 3)}T{fake.date_this_decade().year}" if kwargs.get("include_run_tag", False) else "" ) diff --git a/unified_ecommerce/utils_test.py b/unified_ecommerce/utils_test.py index 0c9ef5db..69cc726d 100644 --- a/unified_ecommerce/utils_test.py +++ b/unified_ecommerce/utils_test.py @@ -102,7 +102,7 @@ def test_markdown_to_plain_text(): assert html_to_plain_text(normal_text) == normal_text -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize("chunk_size", [2, 3, 5, 7, 9, 10]) def test_prefetched_iterator(chunk_size): """