diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f35fafde..7d788f4d 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 @@ -40,7 +40,7 @@ repos: - .secrets.baseline - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.5.7' + rev: 'v0.9.3' hooks: - id: ruff-format - id: ruff @@ -64,7 +64,7 @@ repos: hooks: - id: shellcheck - repo: https://github.com/rhysd/actionlint - rev: v1.7.1 + rev: v1.7.7 hooks: - id: actionlint name: actionlint diff --git a/src/common/mitol/common/models.py b/src/common/mitol/common/models.py index c2486fd7..5de51534 100644 --- a/src/common/mitol/common/models.py +++ b/src/common/mitol/common/models.py @@ -31,7 +31,7 @@ def update(self, **kwargs): Automatically update updated_on timestamp when .update(). This is because .update() does not go through .save(), thus will not auto_now, because it happens on the database level without loading objects into memory. - """ # noqa: E501, D402 + """ # noqa: E501 if "updated_on" not in kwargs: kwargs["updated_on"] = now_in_utc() return super().update(**kwargs) diff --git a/src/google_sheets_deferrals/mitol/google_sheets_deferrals/management/commands/process_deferral_requests.py b/src/google_sheets_deferrals/mitol/google_sheets_deferrals/management/commands/process_deferral_requests.py index 31afdc0a..73558200 100644 --- a/src/google_sheets_deferrals/mitol/google_sheets_deferrals/management/commands/process_deferral_requests.py +++ b/src/google_sheets_deferrals/mitol/google_sheets_deferrals/management/commands/process_deferral_requests.py @@ -24,7 +24,7 @@ def handle(self, *args, **options): # noqa: ARG002 deferral_request_handler = DeferralRequestHandler() self.stdout.write("Handling refunds and updating spreadsheet...") results = deferral_request_handler.process_sheet( - limit_row_index=options.get("row", None) + limit_row_index=options.get("row") ) self.stdout.write( self.style.SUCCESS(f"Deferral sheet successfully processed.\n{results}") diff --git a/src/google_sheets_refunds/mitol/google_sheets_refunds/management/commands/process_refund_requests.py b/src/google_sheets_refunds/mitol/google_sheets_refunds/management/commands/process_refund_requests.py index 3abdc39f..d2756ba9 100644 --- a/src/google_sheets_refunds/mitol/google_sheets_refunds/management/commands/process_refund_requests.py +++ b/src/google_sheets_refunds/mitol/google_sheets_refunds/management/commands/process_refund_requests.py @@ -24,7 +24,7 @@ def handle(self, *args, **options): # noqa: ARG002 refund_request_handler = RefundRequestHandler() self.stdout.write("Handling refunds and updating spreadsheet...") results = refund_request_handler.process_sheet( - limit_row_index=options.get("row", None) + limit_row_index=options.get("row") ) self.stdout.write( self.style.SUCCESS(f"Refund sheet successfully processed.\n{results}") diff --git a/tests/conftest.py b/tests/conftest.py index 75951738..8170692d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,7 @@ @pytest.fixture(scope="session") -def django_db_modify_db_settings_pants_suffix() -> None: # noqa: PT004 +def django_db_modify_db_settings_pants_suffix() -> None: skip_if_no_django() slot_id = environ.get("PANTS_EXECUTION_SLOT", None) @@ -20,13 +20,13 @@ def django_db_modify_db_settings_pants_suffix() -> None: # noqa: PT004 @pytest.fixture(scope="session") -def django_db_modify_db_settings_parallel_suffix( # noqa: PT004 +def django_db_modify_db_settings_parallel_suffix( django_db_modify_db_settings_pants_suffix, # noqa: ARG001 ) -> None: skip_if_no_django() -@pytest.fixture() +@pytest.fixture def learner_drf_client(learner): """DRF API test client that is authenticated with the user""" # import is here to avoid trying to load django before settings are initialized @@ -37,7 +37,7 @@ def learner_drf_client(learner): return client -@pytest.fixture() +@pytest.fixture def learner(db): # noqa: ARG001 """Fixture for a default learner""" # import is here to avoid trying to load django before settings are initialized @@ -46,7 +46,7 @@ def learner(db): # noqa: ARG001 return UserFactory.create() -@pytest.fixture() +@pytest.fixture def learner_and_oauth2(learner): """Fixture for a default learner and oauth2 records""" # import is here to avoid trying to load django before settings are initialized @@ -72,7 +72,7 @@ def learner_and_oauth2(learner): ) -@pytest.fixture() +@pytest.fixture def staff_user(db): # noqa: ARG001 """Staff user fixture""" from mitol.common.factories import UserFactory @@ -80,7 +80,7 @@ def staff_user(db): # noqa: ARG001 return UserFactory.create(is_staff=True) -@pytest.fixture() +@pytest.fixture def user_client(learner): """Django test client that is authenticated with the user""" client = Client() @@ -88,7 +88,7 @@ def user_client(learner): return client -@pytest.fixture() +@pytest.fixture def staff_client(staff_user): """Django test client that is authenticated with the staff user""" client = Client() @@ -96,7 +96,7 @@ def staff_client(staff_user): return client -@pytest.fixture() +@pytest.fixture def google_sheets_base_settings(settings): """Fixture for base google sheets settings""" settings.MITOL_GOOGLE_SHEETS_ENROLLMENT_CHANGE_SHEET_ID = "1" @@ -106,14 +106,14 @@ def google_sheets_base_settings(settings): return settings -@pytest.fixture() +@pytest.fixture def google_sheets_service_creds_settings(settings): """Fixture for google sheets settings configured for a service account""" settings.MITOL_GOOGLE_SHEETS_DRIVE_SERVICE_ACCOUNT_CREDS = '{"credentials": "json"}' return settings -@pytest.fixture() +@pytest.fixture def google_sheets_client_creds_settings(settings): """Fixture gor google sheets settings configured with OAuth""" settings.MITOL_GOOGLE_SHEETS_DRIVE_CLIENT_ID = "nhijg1i.apps.googleusercontent.com" diff --git a/tests/mitol/authentication/views/test_djoser.py b/tests/mitol/authentication/views/test_djoser.py index 6acd178d..20a02e8b 100644 --- a/tests/mitol/authentication/views/test_djoser.py +++ b/tests/mitol/authentication/views/test_djoser.py @@ -9,7 +9,7 @@ EMAIL = "email@example.com" -@pytest.fixture() +@pytest.fixture def user(): from mitol.common.factories import UserFactory diff --git a/tests/mitol/common/templates/test_render_bundle.py b/tests/mitol/common/templates/test_render_bundle.py index fdba41f0..6411adf3 100644 --- a/tests/mitol/common/templates/test_render_bundle.py +++ b/tests/mitol/common/templates/test_render_bundle.py @@ -25,7 +25,7 @@ @pytest.fixture(autouse=True) -def dont_disable_webpack(settings): # noqa: PT004 +def dont_disable_webpack(settings): """Re-enable webpack loader stats for these tests.""" settings.WEBPACK_DISABLE_LOADER_STATS = False diff --git a/tests/mitol/common/test_envs.py b/tests/mitol/common/test_envs.py index e0fc2d8c..fa0c1039 100644 --- a/tests/mitol/common/test_envs.py +++ b/tests/mitol/common/test_envs.py @@ -31,7 +31,7 @@ @pytest.fixture(autouse=True) -def clean_env(mocker): # noqa: PT004 +def clean_env(mocker): """Clean the configured environment variables before a test""" mocker.patch.dict("os.environ", FAKE_ENVIRONS, clear=True) envs.env.reload() diff --git a/tests/mitol/common/utils/test_collections.py b/tests/mitol/common/utils/test_collections.py index 9cc8948a..f0d4d3f0 100644 --- a/tests/mitol/common/utils/test_collections.py +++ b/tests/mitol/common/utils/test_collections.py @@ -230,7 +230,7 @@ def __init__(self, make, model): def test_chunks(): """ - test for chunks + Test for chunks """ input_list = list(range(113)) output_list = [] @@ -251,7 +251,7 @@ def test_chunks(): def test_chunks_iterable(): """ - test that chunks works on non-list iterables too + Test that chunks works on non-list iterables too """ count = 113 input_range = range(count) diff --git a/tests/mitol/digitalcredentials/test_backend.py b/tests/mitol/digitalcredentials/test_backend.py index 42121eec..9c4cbc5a 100644 --- a/tests/mitol/digitalcredentials/test_backend.py +++ b/tests/mitol/digitalcredentials/test_backend.py @@ -30,7 +30,7 @@ def test_build_api_url_invalid(settings): build_api_url("/path") -@pytest.mark.django_db() +@pytest.mark.django_db def test_create_deep_link_url(settings): """Test create_deep_link_url()""" settings.MITOL_DIGITAL_CREDENTIALS_AUTH_TYPE = "test_auth_type" diff --git a/tests/mitol/geoip/test_api.py b/tests/mitol/geoip/test_api.py index 5c4f21b2..0317fb32 100644 --- a/tests/mitol/geoip/test_api.py +++ b/tests/mitol/geoip/test_api.py @@ -12,7 +12,7 @@ fake = faker.Factory.create() -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( "v4,in_block", # noqa: PT006 [ diff --git a/tests/mitol/google_sheets/test_api.py b/tests/mitol/google_sheets/test_api.py index 055cd03e..10496ce6 100644 --- a/tests/mitol/google_sheets/test_api.py +++ b/tests/mitol/google_sheets/test_api.py @@ -8,7 +8,7 @@ from mitol.google_sheets.factories import GoogleApiAuthFactory -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_credentials_service_account(mocker, settings): """ get_credentials should construct a valid Credentials object from app settings using Service Account auth @@ -35,7 +35,7 @@ def test_get_credentials_service_account(mocker, settings): assert creds == patched_svc_account_creds.from_service_account_info.return_value -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_credentials_personal_auth(settings): """ get_credentials should construct a valid Credentials object from data and app settings using personal diff --git a/tests/mitol/google_sheets/test_views.py b/tests/mitol/google_sheets/test_views.py index 792cc73d..bfd08c56 100644 --- a/tests/mitol/google_sheets/test_views.py +++ b/tests/mitol/google_sheets/test_views.py @@ -13,7 +13,7 @@ lazy = lazy_fixture -@pytest.fixture() +@pytest.fixture def google_api_auth(learner): """Fixture that creates a google auth object""" return GoogleApiAuthFactory.create(requesting_user=learner) @@ -53,7 +53,7 @@ def test_request_auth(mocker, settings, staff_client): @pytest.mark.parametrize("existing_auth", [lazy("google_api_auth"), None]) -@pytest.mark.django_db() +@pytest.mark.django_db def test_complete_auth(mocker, settings, learner, existing_auth): # noqa: ARG001 """ View that handles Google auth completion should fetch a token and save/update a diff --git a/tests/mitol/google_sheets_deferrals/test_api.py b/tests/mitol/google_sheets_deferrals/test_api.py index 7cfb5abe..25fa3b36 100644 --- a/tests/mitol/google_sheets_deferrals/test_api.py +++ b/tests/mitol/google_sheets_deferrals/test_api.py @@ -14,7 +14,7 @@ from pytest_lazy_fixtures import lf as lazy_fixture -@pytest.fixture() +@pytest.fixture def request_csv_rows(settings): """Fake deferral request spreadsheet data rows (loaded from CSV)""" fake_request_csv_filepath = os.path.join( # noqa: PTH118 @@ -25,7 +25,7 @@ def request_csv_rows(settings): return [line.split(",") for i, line in enumerate(f.readlines()) if i > 0] -@pytest.fixture() +@pytest.fixture def pygsheets_fixtures(mocker, db, request_csv_rows): # noqa: ARG001 """Patched functions for pygsheets client functionality""" Mock = mocker.Mock @@ -60,7 +60,7 @@ def pygsheets_fixtures(mocker, db, request_csv_rows): # noqa: ARG001 ) -@pytest.fixture() +@pytest.fixture def google_sheets_deferral_settings(settings): settings.MITOL_GOOGLE_SHEETS_DEFERRALS_REQUEST_WORKSHEET_ID = "1" settings.MITOL_GOOGLE_SHEETS_DEFERRALS_PLUGINS = "app.plugins.DeferralPlugin" diff --git a/tests/mitol/google_sheets_refunds/test_api.py b/tests/mitol/google_sheets_refunds/test_api.py index 798beb1e..41d7c75f 100644 --- a/tests/mitol/google_sheets_refunds/test_api.py +++ b/tests/mitol/google_sheets_refunds/test_api.py @@ -14,7 +14,7 @@ from pytest_lazy_fixtures import lf as lazy_fixture -@pytest.fixture() +@pytest.fixture def request_csv_rows(settings): """Fake refund request spreadsheet data rows (loaded from CSV)""" fake_request_csv_filepath = os.path.join( # noqa: PTH118 @@ -25,7 +25,7 @@ def request_csv_rows(settings): return [line.split(",") for i, line in enumerate(f.readlines()) if i > 0] -@pytest.fixture() +@pytest.fixture def pygsheets_fixtures(mocker, db, request_csv_rows): # noqa: ARG001 """Patched functions for pygsheets client functionality""" Mock = mocker.Mock @@ -60,7 +60,7 @@ def pygsheets_fixtures(mocker, db, request_csv_rows): # noqa: ARG001 ) -@pytest.fixture() +@pytest.fixture def google_sheets_refunds_settings(settings): settings.MITOL_GOOGLE_SHEETS_REFUNDS_REQUEST_WORKSHEET_ID = "1" settings.MITOL_GOOGLE_SHEETS_REFUNDS_PLUGINS = "app.plugins.RefundPlugin" diff --git a/tests/mitol/hubspot_api/test_api.py b/tests/mitol/hubspot_api/test_api.py index 6971101e..29bdf7b5 100644 --- a/tests/mitol/hubspot_api/test_api.py +++ b/tests/mitol/hubspot_api/test_api.py @@ -27,25 +27,25 @@ test_object_type = "deals" -@pytest.fixture() +@pytest.fixture def property_group(): """Return sample group JSON""" return {"name": "group_name", "label": "Group Label"} -@pytest.fixture() +@pytest.fixture def content_type_obj(): """Return a sample ContentType""" return ContentType.objects.get_for_model(Group) -@pytest.fixture() +@pytest.fixture def mock_hubspot_api(mocker): """Mock the send hubspot request method""" return mocker.patch("mitol.hubspot_api.api.HubspotApi") -@pytest.fixture() +@pytest.fixture def mock_search_object(mocker): """Return a mocked PublicObjectSearchRequest""" return mocker.patch("mitol.hubspot_api.api.PublicObjectSearchRequest") @@ -196,7 +196,7 @@ def test_delete_object_property(mock_hubspot_api, property_group): assert result == 204 # noqa: PLR2004 -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_hubspot_id(): """Return the hubspot id if any for the specified content type and object ID""" hubspot_obj = HubspotObjectFactory.create() @@ -214,7 +214,7 @@ def test_format_app_id(settings, prefix): assert api.format_app_id(object_id) == f"{prefix}-{object_id}" -@pytest.mark.django_db() +@pytest.mark.django_db def test_upsert_object_request_new(mock_hubspot_api, content_type_obj): """A HubspotObject should be created after an object is synced for the first time""" hubspot_id = "123456789" @@ -234,7 +234,7 @@ def test_upsert_object_request_new(mock_hubspot_api, content_type_obj): ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_upsert_object_request_exists(mock_hubspot_api): """upsert_object_request should try a patch hubspot API call if there's an existing Hubspot object""" # noqa: E501 hs_obj = HubspotObjectFactory.create() @@ -264,7 +264,7 @@ def test_upsert_object_request_exists(mock_hubspot_api): api.HubspotObjectType.CONTACTS.value, ], ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_upsert_object_request_missing_id( # noqa: PLR0913 mocker, mock_hubspot_api, content_type_obj, status, message, hs_type ): @@ -303,7 +303,7 @@ def test_upsert_object_request_missing_id( # noqa: PLR0913 ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_upsert_object_request_other_error(mocker, mock_hubspot_api, content_type_obj): """If a non-dupe ApIException happens, raise it""" object_id = 123 @@ -330,7 +330,7 @@ def test_upsert_object_request_other_error(mocker, mock_hubspot_api, content_typ @pytest.mark.parametrize("is_primary_email", [True, False]) -@pytest.mark.django_db() +@pytest.mark.django_db def test_upsert_object_contact_dupe_email(mocker, mock_hubspot_api, is_primary_email): """If single hubspot contact has multiple emails matching 2+ django users, delete the other email""" # noqa: E501 dupe_hubspot_id = "123456789" diff --git a/tests/mitol/mail/test_api.py b/tests/mitol/mail/test_api.py index 3293f238..66733c21 100644 --- a/tests/mitol/mail/test_api.py +++ b/tests/mitol/mail/test_api.py @@ -19,8 +19,8 @@ User = get_user_model() -@pytest.fixture() -def email_settings(settings): # noqa: PT004 +@pytest.fixture +def email_settings(settings): """Default settings for email tests""" # noqa: D401 settings.MITOL_MAIL_RECIPIENT_OVERRIDE = None diff --git a/tests/mitol/mail/test_messages.py b/tests/mitol/mail/test_messages.py index 4613b993..58c2a617 100644 --- a/tests/mitol/mail/test_messages.py +++ b/tests/mitol/mail/test_messages.py @@ -17,7 +17,7 @@ class NoTemplateNameMessage(TemplatedMessage): @pytest.fixture(autouse=True) -def default_settings(settings): # noqa: PT004 +def default_settings(settings): """Default settings for tests""" # noqa: D401 settings.SITE_BASE_URL = "http://mit.edu/" settings.SITE_NAME = "MIT" diff --git a/tests/mitol/payment_gateway/api/test_cybersource.py b/tests/mitol/payment_gateway/api/test_cybersource.py index 6c3c91b0..b4250f55 100644 --- a/tests/mitol/payment_gateway/api/test_cybersource.py +++ b/tests/mitol/payment_gateway/api/test_cybersource.py @@ -30,22 +30,22 @@ ISO_8601_FORMAT = "%Y-%m-%dT%H:%M:%SZ" -@pytest.fixture() +@pytest.fixture def order(): return OrderFactory() -@pytest.fixture() +@pytest.fixture def refund(): return RefundFactory() -@pytest.fixture() +@pytest.fixture def cartitems(): return CartItemFactory.create_batch(5) -@pytest.fixture() +@pytest.fixture def response_payload(request): """Fixture to return dictionary of a specific JSON file with provided name in request param""" # noqa: E501 @@ -501,7 +501,7 @@ def create_transaction_detail_record(): "name": "ics_auth", "r_code": "1", "r_flag": "SOK", - "r_message": "Request was " "processed " "successfully.", + "r_message": "Request was processed successfully.", "reason_code": "100", "reconciliation_id": fake_recon_id, "return_code": 1010000, @@ -513,7 +513,7 @@ def create_transaction_detail_record(): "name": "ics_bill", "r_code": "1", "r_flag": "SOK", - "r_message": "Request was " "processed " "successfully.", + "r_message": "Request was processed successfully.", "reason_code": "100", "reconciliation_id": fake_recon_id, "return_code": 1260000, @@ -535,7 +535,7 @@ def create_transaction_detail_record(): ), "client_reference_information": cs_models.TssV2TransactionsGet200ResponseClientReferenceInformation( # noqa: E501 **{ - "application_name": "Secure Acceptance " "Web/Mobile", + "application_name": "Secure Acceptance Web/Mobile", "application_user": None, "application_version": None, "code": "mitxonline-dev-4",