From eb04b2be34b5bd7a4b016396fa29f84e76e0a341 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:25:01 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conftest.py | 16 +++++++-------- content_sync/api_test.py | 2 +- content_sync/apis/github_test.py | 14 ++++++------- content_sync/backends/base_test.py | 2 +- content_sync/backends/github_test.py | 4 ++-- content_sync/conftest.py | 8 ++++---- content_sync/pipelines/concourse_test.py | 6 +++--- .../definitions/concourse/common/steps.py | 2 +- .../concourse/theme_assets_pipeline.py | 2 +- content_sync/serializers_test.py | 20 +++++++++---------- content_sync/tasks_test.py | 4 ++-- external_resources/signals_test.py | 2 +- external_resources/tasks_test.py | 14 ++++++------- fixtures/common.py | 4 ++-- gdrive_sync/api_test.py | 14 ++++++------- .../commands/backfill_gdrive_folder_test.py | 4 ++-- gdrive_sync/models_test.py | 6 +++--- gdrive_sync/signals_test.py | 2 +- gdrive_sync/tasks_test.py | 4 ++-- localdev/configs/api_test.py | 1 - main/middleware_test.py | 8 ++++---- news/util_test.py | 2 +- news/views.py | 2 +- ocw_import/api_test.py | 2 +- repl.py | 2 +- videos/conftest.py | 6 +++--- videos/signals_test.py | 6 +++--- videos/tasks_test.py | 4 ++-- videos/views_test.py | 2 +- videos/youtube_test.py | 6 +++--- websites/conftest.py | 16 +++++++-------- .../commands/markdown_cleaning/__init__.py | 2 +- .../commands/markdown_cleaning/cleaner.py | 2 +- .../rules/link_resolveuid_test.py | 6 +++--- .../rules/link_to_external_resource_test.py | 2 +- .../rules/link_wrapped_images.py | 2 +- .../rules/rootrelative_urls.py | 2 +- .../commands/update_content_fields.py | 2 +- websites/serializers_test.py | 2 +- websites/signals_test.py | 2 +- websites/views_test.py | 4 ++-- 41 files changed, 106 insertions(+), 107 deletions(-) diff --git a/conftest.py b/conftest.py index 5c1e009aa..7034a3712 100644 --- a/conftest.py +++ b/conftest.py @@ -13,12 +13,12 @@ @pytest.fixture(autouse=True) -def default_settings(settings): # noqa: PT004 +def default_settings(settings): """Set default settings for all tests""" settings.DISABLE_WEBPACK_LOADER_STATS = True -@pytest.fixture() +@pytest.fixture def mocked_celery(mocker): """Mock object that patches certain celery functions""" exception_class = TabError @@ -36,22 +36,22 @@ def mocked_celery(mocker): ) -@pytest.fixture() -@pytest.mark.django_db() +@pytest.fixture +@pytest.mark.django_db def course_starter(settings): """Returns the 'course'-type WebsiteStarter that is seeded in a data migration""" # noqa: D401 return WebsiteStarter.objects.get(slug=settings.OCW_COURSE_STARTER_SLUG) -@pytest.fixture() -@pytest.mark.django_db() +@pytest.fixture +@pytest.mark.django_db def omnibus_starter(): """Returns the omnibus WebsiteStarter that is seeded in a data migration""" # noqa: D401 return WebsiteStarter.objects.get(slug=OMNIBUS_STARTER_SLUG) -@pytest.fixture() -@pytest.mark.django_db() +@pytest.fixture +@pytest.mark.django_db def omnibus_config(settings): """Returns the omnibus site config""" # noqa: D401 with open( # noqa: PTH123 diff --git a/content_sync/api_test.py b/content_sync/api_test.py index d184a411e..a5a837f21 100644 --- a/content_sync/api_test.py +++ b/content_sync/api_test.py @@ -16,7 +16,7 @@ # pylint:disable=redefined-outer-name -@pytest.fixture() +@pytest.fixture def mock_api_funcs(settings, mocker): """Mock functions used in publish_websites""" settings.CONTENT_SYNC_BACKEND = "content_sync.backends.TestBackend" diff --git a/content_sync/apis/github_test.py b/content_sync/apis/github_test.py index fc332bb3b..708fdff35 100644 --- a/content_sync/apis/github_test.py +++ b/content_sync/apis/github_test.py @@ -77,7 +77,7 @@ @pytest.fixture(autouse=True) -def mock_github_integration(mocker): # noqa: PT004 +def mock_github_integration(mocker): """Mock the github app request""" mock_get = mocker.patch("content_sync.apis.github.requests.get") mock_get.return_value.status_code = 200 @@ -86,7 +86,7 @@ def mock_github_integration(mocker): # noqa: PT004 mock_integration.return_value.get_access_token.return_value.token = "gh_token" # noqa: S105 -@pytest.fixture() +@pytest.fixture def db_data(): """Fixture that seeds the database with data needed for this test suite""" users = UserFactory.create_batch(2) @@ -106,7 +106,7 @@ def db_data(): ) -@pytest.fixture() +@pytest.fixture def mock_rsa_key(): """Generate a test key""" private_key = rsa.generate_private_key( @@ -119,7 +119,7 @@ def mock_rsa_key(): ) -@pytest.fixture() +@pytest.fixture def mock_api_wrapper(settings, mocker, db_data): """Create a GithubApiWrapper with a mock Github object""" settings.GIT_TOKEN = "faketoken" # noqa: S105 @@ -132,13 +132,13 @@ def mock_api_wrapper(settings, mocker, db_data): ) -@pytest.fixture() +@pytest.fixture def mock_github(mocker): """Return a mock Github class""" return mocker.patch("content_sync.apis.github.Github") -@pytest.fixture() +@pytest.fixture def patched_file_serialize(mocker): """Patches function that serializes website content to file contents""" return mocker.patch( @@ -151,7 +151,7 @@ def fake_destination_filepath(website_content: WebsiteContent, *args) -> str: return f"path/to/{website_content.filename}.md" -@pytest.fixture() +@pytest.fixture def patched_destination_filepath(mocker): """Patches the get_destination_filepath API function""" return mocker.patch( diff --git a/content_sync/backends/base_test.py b/content_sync/backends/base_test.py index 8b291e9c0..d6b1c4f8a 100644 --- a/content_sync/backends/base_test.py +++ b/content_sync/backends/base_test.py @@ -97,7 +97,7 @@ def test_sync_content_to_backend_delete(mocker): mock_delete_content_in_backend.assert_called_once_with(state) -@pytest.mark.django_db() +@pytest.mark.django_db def test_sync_all_content_to_backend(mocker): """Verify that sync_all_content_to_backend calls sync_content_to_backend for each piece of content""" mock_sync_content_to_backend = mocker.patch.object( diff --git a/content_sync/backends/github_test.py b/content_sync/backends/github_test.py index 2e3c83fb8..cd4e76ec8 100644 --- a/content_sync/backends/github_test.py +++ b/content_sync/backends/github_test.py @@ -19,7 +19,7 @@ # pylint:disable=redefined-outer-name -@pytest.fixture() +@pytest.fixture def github(settings, mocker, mock_branches): """Create a github backend for a website""" settings.GIT_TOKEN = "faketoken" # noqa: S105 @@ -40,7 +40,7 @@ def github(settings, mocker, mock_branches): ) -@pytest.fixture() +@pytest.fixture def patched_file_deserialize(mocker): """Patches function that deserializes file contents to website content""" return mocker.patch( diff --git a/content_sync/conftest.py b/content_sync/conftest.py index d67431da3..3c15d84cf 100644 --- a/content_sync/conftest.py +++ b/content_sync/conftest.py @@ -19,7 +19,7 @@ def pytest_keyboard_interrupt(excinfo): # noqa: ARG001 @pytest.fixture(params=["dev", "not_dev"]) -def mock_environments(settings, request): # noqa: PT004 +def mock_environments(settings, request): """Fixture that tests with dev vs non-dev environment""" settings.OCW_STUDIO_ENVIRONMENT = request.param settings.ENV_NAME = request.param @@ -27,12 +27,12 @@ def mock_environments(settings, request): # noqa: PT004 @pytest.fixture(params=[True, False]) -def mock_concourse_hard_purge(settings, request): # noqa: PT004 +def mock_concourse_hard_purge(settings, request): """Fixture that tests with True and False for settings.CONCOURSE_HARD_PURGE""" settings.CONCOURSE_HARD_PURGE = request.param -@pytest.fixture() +@pytest.fixture def mock_branches(settings, mocker): """Return mock github branches with names""" mocked_branches = [] @@ -47,7 +47,7 @@ def mock_branches(settings, mocker): return mocked_branches -@pytest.fixture() +@pytest.fixture def github_content_file(mocker): """Fixture that returns a mocked Github ContentFile object with some related properties""" # noqa: E501 content_str = "my file content" diff --git a/content_sync/pipelines/concourse_test.py b/content_sync/pipelines/concourse_test.py index 30b440892..25e459a1d 100644 --- a/content_sync/pipelines/concourse_test.py +++ b/content_sync/pipelines/concourse_test.py @@ -105,14 +105,14 @@ ] -@pytest.fixture() -def mock_auth(mocker): # noqa: PT004 +@pytest.fixture +def mock_auth(mocker): """Mock the concourse api auth method""" mocker.patch("content_sync.pipelines.concourse.PipelineApi.auth") @pytest.fixture(params=["test", "dev"]) -def pipeline_settings(settings, request): # noqa: PT004 +def pipeline_settings(settings, request): """Default settings for pipelines""" # noqa: D401 env = request.param settings.ENVIRONMENT = env diff --git a/content_sync/pipelines/definitions/concourse/common/steps.py b/content_sync/pipelines/definitions/concourse/common/steps.py index c8a82b814..debbf65f5 100644 --- a/content_sync/pipelines/definitions/concourse/common/steps.py +++ b/content_sync/pipelines/definitions/concourse/common/steps.py @@ -91,7 +91,7 @@ class ErrorHandlingStep(TryStep): Extends TryStep and sets error handling steps """ - def __init__( # noqa: PLR0913 + def __init__( self, pipeline_name: str, status: str, diff --git a/content_sync/pipelines/definitions/concourse/theme_assets_pipeline.py b/content_sync/pipelines/definitions/concourse/theme_assets_pipeline.py index 6fbcc4a2e..14337090d 100644 --- a/content_sync/pipelines/definitions/concourse/theme_assets_pipeline.py +++ b/content_sync/pipelines/definitions/concourse/theme_assets_pipeline.py @@ -61,7 +61,7 @@ class ThemeAssetsPipelineDefinition(Pipeline): _clear_live_cdn_cache_identifier = Identifier("clear-live-cdn-cache-task").root _slack_resource = SlackAlertResource() - def __init__( # noqa: PLR0913 + def __init__( self, artifacts_bucket: str, preview_bucket: str, diff --git a/content_sync/serializers_test.py b/content_sync/serializers_test.py index 01b317f2d..3e95507f2 100644 --- a/content_sync/serializers_test.py +++ b/content_sync/serializers_test.py @@ -104,7 +104,7 @@ def get_example_menu_data(): @mock_s3 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("markdown", "exp_sections"), [["# Some markdown...\n- and\n- a\n- list", 2], [None, 1]], # noqa: PT007 @@ -153,7 +153,7 @@ def test_hugo_file_serialize(settings, markdown, exp_sections): assert md_file_sections[1] == markdown -@pytest.mark.django_db() +@pytest.mark.django_db def test_hugo_file_deserialize(mocker): """HugoMarkdownFileSerializer.deserialize should create the expected content object from some file contents""" dest_directory, dest_filename = "path/to", "myfile" @@ -193,7 +193,7 @@ def test_hugo_file_deserialize(mocker): assert website_content.markdown is None -@pytest.mark.django_db() +@pytest.mark.django_db def test_hugo_menu_yaml_serialize(omnibus_config): """HugoMenuYamlFileSerializer.serialize should create the expected file contents""" nav_menu_config_item = omnibus_config.find_item_by_name("navmenu") @@ -222,7 +222,7 @@ def test_hugo_menu_yaml_serialize(omnibus_config): } -@pytest.mark.django_db() +@pytest.mark.django_db def test_hugo_menu_yaml_deserialize(omnibus_config): """HugoMenuYamlFileSerializer.deserialize should create the expected content object from some file contents""" nav_menu_config_item = omnibus_config.find_item_by_name("navmenu") @@ -241,7 +241,7 @@ def test_hugo_menu_yaml_deserialize(omnibus_config): @mock_s3 -@pytest.mark.django_db() +@pytest.mark.django_db def test_hugo_file_deserialize_with_file(settings): """HugoMarkdownFileSerializer.deserialize should create the expected content object from some file contents""" settings.DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" @@ -262,7 +262,7 @@ def test_hugo_file_deserialize_with_file(settings): ) -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("config_dirpath", "file_dirpath", "exp_content_dirpath"), [ @@ -295,7 +295,7 @@ def test_hugo_file_deserialize_dirpath( patched_find_item.assert_any_call("page") -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize("serializer_cls", [JsonFileSerializer, YamlFileSerializer]) def test_data_file_serialize(serializer_cls): """JsonFileSerializer and YamlFileSerializer.serialize should create the expected data file contents""" @@ -316,7 +316,7 @@ def test_data_file_serialize(serializer_cls): assert parsed_file_content == {**metadata, "title": "Content Title"} -@pytest.mark.django_db() +@pytest.mark.django_db def test_metadata_file_serialize(): """JsonFileSerializer should create the expected data file contents for sitemetadata files""" metadata = {"metadata1": "dummy value 1", "metadata2": "dummy value 2"} @@ -337,7 +337,7 @@ def test_metadata_file_serialize(): } -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("serializer_cls", "file_content"), [ @@ -429,7 +429,7 @@ def test_factory_for_content_hugo_markdown(): ) -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("file_value", "exp_serializer_cls"), [ diff --git a/content_sync/tasks_test.py b/content_sync/tasks_test.py index 804967440..03cd26f53 100644 --- a/content_sync/tasks_test.py +++ b/content_sync/tasks_test.py @@ -38,7 +38,7 @@ # pylint:disable=redefined-outer-name -@fixture() +@fixture def api_mock(mocker, settings): """Return a mocked content_sync.tasks.api, and set the backend""" settings.CONTENT_SYNC_BACKEND = "content_sync.backends.TestBackend" @@ -46,7 +46,7 @@ def api_mock(mocker, settings): return mocker.patch("content_sync.tasks.api") -@fixture() +@fixture def log_mock(mocker): """Return a mocked log object""" return mocker.patch("content_sync.tasks.log") diff --git a/external_resources/signals_test.py b/external_resources/signals_test.py index a18e3f121..ca3d06352 100644 --- a/external_resources/signals_test.py +++ b/external_resources/signals_test.py @@ -7,7 +7,7 @@ from websites.factories import WebsiteContentFactory -@pytest.mark.django_db() +@pytest.mark.django_db def test_upsert_external_resource_state(mocker): """Test that the upsert_external_resource_state signal makes the correct call""" mock_update_or_create = mocker.patch( diff --git a/external_resources/tasks_test.py b/external_resources/tasks_test.py index cce024c10..df15771cd 100644 --- a/external_resources/tasks_test.py +++ b/external_resources/tasks_test.py @@ -82,7 +82,7 @@ def test_check_external_resources_for_breakages_zero_websites( assert mocked_celery.replace.call_count == 0 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ( "url_status", @@ -121,7 +121,7 @@ def test_check_external_resources( assert updated_state.external_url_response_code == url_status_code -@pytest.mark.django_db() +@pytest.mark.django_db def test_check_external_resources_failed(mocker): """Test for failed api check""" external_resource_state = ExternalResourceStateFactory() @@ -138,7 +138,7 @@ def test_check_external_resources_failed(mocker): assert updated_state.status == ExternalResourceState.Status.CHECK_FAILED -@pytest.mark.django_db() +@pytest.mark.django_db def test_submit_url_to_wayback_task_success(mocker): """ Test that submit_url_to_wayback_task successfully submits a URL to the Wayback Machine @@ -171,7 +171,7 @@ def test_submit_url_to_wayback_task_success(mocker): assert updated_state.wayback_http_status is None -@pytest.mark.django_db() +@pytest.mark.django_db def test_submit_url_to_wayback_task_skipped_due_to_recent_submission(mocker, settings): """ Test that submit_url_to_wayback_task skips submission when the URL was recently submitted. @@ -211,7 +211,7 @@ def test_submit_url_to_wayback_task_skipped_due_to_recent_submission(mocker, set assert updated_state.wayback_job_id == external_resource_state.wayback_job_id -@pytest.mark.django_db() +@pytest.mark.django_db def test_submit_url_to_wayback_task_http_error_429(mocker): """ Test that submit_url_to_wayback_task retries on HTTPError 429 (Too Many Requests). @@ -248,7 +248,7 @@ def test_submit_url_to_wayback_task_http_error_429(mocker): mock_retry.assert_called_once_with(exc=http_error_429, countdown=30) -@pytest.mark.django_db() +@pytest.mark.django_db def test_update_wayback_jobs_status_batch_success(mocker): """ Test that update_wayback_jobs_status_batch updates statuses of pending jobs successfully. @@ -312,7 +312,7 @@ def test_update_wayback_jobs_status_batch_success(mocker): assert updated_state2.wayback_http_status == 404 -@pytest.mark.django_db() +@pytest.mark.django_db def test_update_wayback_jobs_status_batch_no_pending_jobs(mocker): """ Test that update_wayback_jobs_status_batch handles no pending jobs gracefully. diff --git a/fixtures/common.py b/fixtures/common.py index 3247dca78..9fb32ee7e 100644 --- a/fixtures/common.py +++ b/fixtures/common.py @@ -4,13 +4,13 @@ from rest_framework.test import APIClient -@pytest.fixture() +@pytest.fixture def drf_client(): """DRF API anonymous test client""" return APIClient() -@pytest.fixture() +@pytest.fixture def preexisting_captions_filenames(): """ Filenames for gdrive files and resources as they relate to diff --git a/gdrive_sync/api_test.py b/gdrive_sync/api_test.py index 75ef156fa..e451c0f89 100644 --- a/gdrive_sync/api_test.py +++ b/gdrive_sync/api_test.py @@ -55,14 +55,14 @@ # pylint:disable=redefined-outer-name, too-many-arguments, unused-argument, protected-access -@pytest.fixture() +@pytest.fixture def mock_service(mocker): """Mock google drive service""" return mocker.patch("gdrive_sync.api.get_drive_service") -@pytest.fixture() -def mock_get_s3_content_type(mocker): # noqa: PT004 +@pytest.fixture +def mock_get_s3_content_type(mocker): """Mock gdrive_sync.api.get_s3_content_type""" mocker.patch( "gdrive_sync.api.get_s3_content_type", return_value="application/ms-word" @@ -173,7 +173,7 @@ def test_stream_to_s3(settings, mocker, is_video, current_s3_key): assert drive_file.s3_key == expected_key -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize("num_errors", [2, 3, 4]) def test_stream_to_s3_error(settings, mocker, num_errors): """Task should mark DriveFile status as failed if an s3 upload error occurs more often than retries""" @@ -200,7 +200,7 @@ def test_stream_to_s3_error(settings, mocker, num_errors): ) -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("parent_folder", "parent_folder_in_ancestors"), [(None, False), ("correct_parent", False), ("correct_parent", True)], @@ -536,8 +536,8 @@ def test_walk_gdrive_folder(mocker): ) # parent, subfolder1, subfolder1_1, subfolder2 -@pytest.fixture() -def mock_gdrive_pdf(mocker): # noqa: PT004 +@pytest.fixture +def mock_gdrive_pdf(mocker): """Mock reading the metadata of a PDF file with blank metadata""" mocker.patch( "gdrive_sync.api.GDriveStreamReader", diff --git a/gdrive_sync/management/commands/backfill_gdrive_folder_test.py b/gdrive_sync/management/commands/backfill_gdrive_folder_test.py index b7d5b9fc0..487f43a04 100644 --- a/gdrive_sync/management/commands/backfill_gdrive_folder_test.py +++ b/gdrive_sync/management/commands/backfill_gdrive_folder_test.py @@ -14,7 +14,7 @@ pytestmark = pytest.mark.django_db -@pytest.fixture() +@pytest.fixture def mock_get_drive_service(mocker): """Mock Google Drive service""" mock_gdrive_service = mocker.Mock() @@ -36,7 +36,7 @@ def mock_get_drive_service(mocker): ) -@pytest.fixture() +@pytest.fixture def mock_get_boto3_client(mocker): """Mock S3 client""" return mocker.patch("main.s3_utils.get_boto3_client") diff --git a/gdrive_sync/models_test.py b/gdrive_sync/models_test.py index 8e8f5f3a7..55f18248f 100644 --- a/gdrive_sync/models_test.py +++ b/gdrive_sync/models_test.py @@ -11,7 +11,7 @@ from websites.factories import WebsiteContentFactory, WebsiteFactory -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_valid_s3_key(): """get_valid_s3_key avoids dupe s3 keys""" site = WebsiteFactory.create() @@ -46,7 +46,7 @@ def test_get_valid_s3_key(): assert file_5.s3_key == f"{site_prefix}/{site.name}/テストファイル.png" -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_content_dependencies(): """get_content_dependencies should return content that uses `drive_file.resource`.""" for starter, item, field in all_starters_items_fields(): @@ -79,7 +79,7 @@ def test_get_content_dependencies(): assert len(dependencies) == 0 -@pytest.mark.django_db() +@pytest.mark.django_db def test_drivefile_allows_large_files(): """ Ensure database column can store large file sizes, e.g., bigger than int4. diff --git a/gdrive_sync/signals_test.py b/gdrive_sync/signals_test.py index 82eff1b84..8616f253f 100644 --- a/gdrive_sync/signals_test.py +++ b/gdrive_sync/signals_test.py @@ -5,7 +5,7 @@ from gdrive_sync.factories import DriveFileFactory -@pytest.mark.django_db() +@pytest.mark.django_db def test_delete_from_s3(mocker): """Deleting a DriveFile should also delete it from S3""" mock_delete_s3_objects = mocker.patch("gdrive_sync.signals.delete_s3_objects") diff --git a/gdrive_sync/tasks_test.py b/gdrive_sync/tasks_test.py index d1b20a58f..9fe04ffad 100644 --- a/gdrive_sync/tasks_test.py +++ b/gdrive_sync/tasks_test.py @@ -30,8 +30,8 @@ # pylint:disable=redefined-outer-name -@pytest.fixture() -def mock_gdrive_files(mocker): # noqa: PT004 +@pytest.fixture +def mock_gdrive_files(mocker): """Return mock results from a google drive api request""" mocker.patch( "gdrive_sync.tasks.api.query_files", diff --git a/localdev/configs/api_test.py b/localdev/configs/api_test.py index 6c431104a..a8c8da9a0 100644 --- a/localdev/configs/api_test.py +++ b/localdev/configs/api_test.py @@ -37,7 +37,6 @@ def test_equivalent_example_configs(settings): with open(os.path.join(dirpath, filename)) as f: # noqa: PTH118, PTH123 raw_yaml_config = f.read().strip() parsed_config = yaml.load(raw_yaml_config, Loader=yaml.SafeLoader) - # js_config_path = os.path.join( # noqa: PTH118 settings.BASE_DIR, JS_CONFIG_DIRECTORY, f"{base_filename}.json" ) diff --git a/main/middleware_test.py b/main/middleware_test.py index e58ee2017..5ba8bb80b 100644 --- a/main/middleware_test.py +++ b/main/middleware_test.py @@ -12,8 +12,8 @@ FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS = 60 -@pytest.fixture() -def middleware_settings(settings): # noqa: PT004 +@pytest.fixture +def middleware_settings(settings): """Default settings for middleware""" # noqa: D401 settings.MIDDLEWARE_FEATURE_FLAG_QS_PREFIX = "ZZ" settings.MIDDLEWARE_FEATURE_FLAG_COOKIE_NAME = FEATURE_FLAG_COOKIE_NAME @@ -22,13 +22,13 @@ def middleware_settings(settings): # noqa: PT004 ) -@pytest.fixture() +@pytest.fixture def qs_middleware(mocker, middleware_settings): # pylint: disable=unused-argument """Mocked middleware for QueryStringFeatureFlagMiddleware""" # noqa: D401 return QueryStringFeatureFlagMiddleware(mocker.Mock()) -@pytest.fixture() +@pytest.fixture def cookie_middleware(mocker, middleware_settings): # pylint: disable=unused-argument """Mocked middleware for QueryStringFeatureFlagMiddleware""" # noqa: D401 return CookieFeatureFlagMiddleware(mocker.Mock()) diff --git a/news/util_test.py b/news/util_test.py index 6fe780ec6..ce676beb3 100644 --- a/news/util_test.py +++ b/news/util_test.py @@ -1,6 +1,6 @@ """Tests for utility functions for OCW News""" -import xml.etree.ElementTree as ET # noqa: N817 +import xml.etree.ElementTree as ET import pytest diff --git a/news/views.py b/news/views.py index bf22404b4..76b0b31f5 100644 --- a/news/views.py +++ b/news/views.py @@ -1,6 +1,6 @@ """Views related to OCW News""" -import xml.etree.ElementTree as ET # noqa: N817 +import xml.etree.ElementTree as ET import requests from django.http import JsonResponse diff --git a/ocw_import/api_test.py b/ocw_import/api_test.py index 04aa5381f..6ea762a0b 100644 --- a/ocw_import/api_test.py +++ b/ocw_import/api_test.py @@ -303,7 +303,7 @@ def test_import_ocw2hugo_content_log_exception(mocker, settings): ) -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("course_num", "term", "year", "expected_id"), [ diff --git a/repl.py b/repl.py index f6ab26664..c1886af11 100755 --- a/repl.py +++ b/repl.py @@ -12,7 +12,7 @@ sys.exit( check_call( - [ # noqa: S603 + [ os.path.join(base_dir, "manage.py"), # noqa: PTH118 "shell", *sys.argv[1:], diff --git a/videos/conftest.py b/videos/conftest.py index 5df8b175b..0899271bb 100644 --- a/videos/conftest.py +++ b/videos/conftest.py @@ -16,7 +16,7 @@ def __init__(self, status, reason="mock reason"): @pytest.fixture(autouse=True) -def valid_settings(settings): # noqa: PT004 +def valid_settings(settings): """Valid settings for video processing""" # noqa: D401 settings.AWS_ACCOUNT_ID = "account-id" settings.AWS_REGION = "us-west-1" @@ -27,7 +27,7 @@ def valid_settings(settings): # noqa: PT004 @pytest.fixture(autouse=True) -def youtube_settings(settings, mocker): # noqa: PT004 +def youtube_settings(settings, mocker): """Populate required youtube settings with dummy values""" settings.YT_CLIENT_ID = "testvalue" settings.YT_CLIENT_SECRET = "testvalue" # pragma: allowlist secret # noqa: S105 @@ -38,6 +38,6 @@ def youtube_settings(settings, mocker): # noqa: PT004 @pytest.fixture(autouse=True) -def mock_smart_open_reader(mocker): # noqa: PT004 +def mock_smart_open_reader(mocker): """Mock the smartopen s3 Reader""" mocker.patch("videos.youtube.Reader") diff --git a/videos/signals_test.py b/videos/signals_test.py index 6d128041b..7908a5ddf 100644 --- a/videos/signals_test.py +++ b/videos/signals_test.py @@ -6,10 +6,10 @@ from videos.constants import DESTINATION_YOUTUBE from videos.factories import VideoFactory, VideoFileFactory -from videos.models import Video # noqa: TCH001 +from videos.models import Video # noqa: TC001 -@pytest.mark.django_db() +@pytest.mark.django_db def test_delete_video_file_signal(mocker): """Deleting a youtube VideoFile should trigger the Youtube API delete function""" mock_remove = mocker.patch("videos.signals.remove_youtube_video") @@ -20,7 +20,7 @@ def test_delete_video_file_signal(mocker): mock_delete_s3_objects.delay.assert_called_once_with(video_file.s3_key) -@pytest.mark.django_db() +@pytest.mark.django_db def test_delete_video_transcripts(): """Deleting a Video object should delete related files.""" pdf_temp_file = TemporaryUploadedFile( diff --git a/videos/tasks_test.py b/videos/tasks_test.py index c4dcbaf98..c51f40e7a 100644 --- a/videos/tasks_test.py +++ b/videos/tasks_test.py @@ -126,7 +126,7 @@ def updated_transctipts_reponse(): } -@pytest.fixture() +@pytest.fixture def youtube_video_files_new(): """Return 3 Youtube video files""" return VideoFileFactory.create_batch( @@ -137,7 +137,7 @@ def youtube_video_files_new(): ) -@pytest.fixture() +@pytest.fixture def youtube_video_files_processing(): """Return 3 Youtube video files""" return VideoFileFactory.create_batch( diff --git a/videos/views_test.py b/videos/views_test.py index cdb4f9d11..c6c008ad3 100644 --- a/videos/views_test.py +++ b/videos/views_test.py @@ -20,7 +20,7 @@ pytestmark = pytest.mark.django_db -@pytest.fixture() +@pytest.fixture def video_group(settings): """Collection of model objects for testing video views""" # noqa: D401 drive_file_id = "abc123" diff --git a/videos/youtube_test.py b/videos/youtube_test.py index 64342f7ab..eb4031a14 100644 --- a/videos/youtube_test.py +++ b/videos/youtube_test.py @@ -42,13 +42,13 @@ # pylint: disable=redefined-outer-name,unused-argument,no-value-for-parameter,unused-variable -@pytest.fixture() +@pytest.fixture def youtube_mocker(mocker): """Return a mock youtube api client""" return mocker.patch("videos.youtube.build") -@pytest.fixture() +@pytest.fixture def youtube_website(mocker): """Return a website with youtube resources""" website = WebsiteFactory.create() @@ -71,7 +71,7 @@ def youtube_website(mocker): return website -@pytest.fixture() +@pytest.fixture def mock_mail(mocker): """Objects and mocked functions for mail tests""" mock_get_message_sender = mocker.patch("videos.youtube.get_message_sender") diff --git a/websites/conftest.py b/websites/conftest.py index 1ebf39558..28d34d33e 100644 --- a/websites/conftest.py +++ b/websites/conftest.py @@ -25,7 +25,7 @@ SCHEMA_CONFIG_FILE = "ocw-course-site-config.yml" -@pytest.fixture() +@pytest.fixture def permission_groups(): """Set up groups, users and websites for permission testing""" ( @@ -61,7 +61,7 @@ def permission_groups(): ) -@pytest.fixture() +@pytest.fixture def global_admin_user(): """Returns a user with global admin permissions""" # noqa: D401 create_global_groups() @@ -70,7 +70,7 @@ def global_admin_user(): return global_admin_user -@pytest.fixture() +@pytest.fixture def basic_site_config(settings): """Returns an example site config""" # noqa: D401 return yaml.load( @@ -79,7 +79,7 @@ def basic_site_config(settings): ) -@pytest.fixture() +@pytest.fixture def site_config_yml(settings): """Fixture that returns the contents of the example site config YAML file in the resource directory""" # noqa: E501 with open( # noqa: PTH123 @@ -91,13 +91,13 @@ def site_config_yml(settings): return f.read().strip() -@pytest.fixture() +@pytest.fixture def parsed_site_config(site_config_yml): """Fixture that returns the parsed contents of the example site config YAML file in the resource directory""" # noqa: E501 return yaml.load(site_config_yml, Loader=yaml.SafeLoader) -@pytest.fixture() +@pytest.fixture def site_config_repeatable_only(basic_site_config): """Returns an example site config with a repeatable config item as the only item in 'collections'""" # noqa: D401, E501 site_config = basic_site_config.copy() @@ -108,7 +108,7 @@ def site_config_repeatable_only(basic_site_config): return {**site_config, "collections": [config_item]} -@pytest.fixture() +@pytest.fixture def site_config_singleton_only(basic_site_config): """Returns an example site config with a singleton config item as the only item in 'collections'""" # noqa: D401, E501 site_config = basic_site_config.copy() @@ -120,7 +120,7 @@ def site_config_singleton_only(basic_site_config): return {**site_config, "collections": [files_config_item]} -@pytest.fixture() +@pytest.fixture def ocw_site(parsed_site_config): """OCW Course site with metadata""" website = WebsiteFactory.create( diff --git a/websites/management/commands/markdown_cleaning/__init__.py b/websites/management/commands/markdown_cleaning/__init__.py index e236bbda7..034daf0a2 100644 --- a/websites/management/commands/markdown_cleaning/__init__.py +++ b/websites/management/commands/markdown_cleaning/__init__.py @@ -6,4 +6,4 @@ MarkdownCleanupRule, ) -__all__ = ["WebsiteContentMarkdownCleaner", "MarkdownCleanupRule", "rules"] +__all__ = ["MarkdownCleanupRule", "WebsiteContentMarkdownCleaner", "rules"] diff --git a/websites/management/commands/markdown_cleaning/cleaner.py b/websites/management/commands/markdown_cleaning/cleaner.py index 1637e2c5a..2158d367e 100644 --- a/websites/management/commands/markdown_cleaning/cleaner.py +++ b/websites/management/commands/markdown_cleaning/cleaner.py @@ -77,7 +77,7 @@ def __init__(self, rule: MarkdownCleanupRule): WebsiteContentMarkdownCleaner.ReplacementMatch ] = [] - def store_match_data( # noqa: PLR0913 + def store_match_data( self, original_text: str, replacement: str, diff --git a/websites/management/commands/markdown_cleaning/rules/link_resolveuid_test.py b/websites/management/commands/markdown_cleaning/rules/link_resolveuid_test.py index a802b8966..380b24c2d 100644 --- a/websites/management/commands/markdown_cleaning/rules/link_resolveuid_test.py +++ b/websites/management/commands/markdown_cleaning/rules/link_resolveuid_test.py @@ -24,7 +24,7 @@ def get_cleaner(): return Cleaner(rule) -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("content", "expected_content"), [ @@ -60,7 +60,7 @@ def test_resolveuid_content_text_id(content, expected_content): assert target_content.markdown == expected_content -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("content", "expected_content"), [ @@ -101,7 +101,7 @@ def test_resolveuid_website_legacy_uid(content, expected_content): assert target_content.markdown == expected_content -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("content", "expected_content"), [ diff --git a/websites/management/commands/markdown_cleaning/rules/link_to_external_resource_test.py b/websites/management/commands/markdown_cleaning/rules/link_to_external_resource_test.py index a8a50227e..f2b91e272 100644 --- a/websites/management/commands/markdown_cleaning/rules/link_to_external_resource_test.py +++ b/websites/management/commands/markdown_cleaning/rules/link_to_external_resource_test.py @@ -117,7 +117,7 @@ def test_build_external_resource(): assert external_resource.metadata["has_external_license_warning"] is True -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize("content_exists", [True, False]) def test_get_or_build_external_resource(content_exists): """Test get_or_build_external_resource builds or gets depending on content existence.""" diff --git a/websites/management/commands/markdown_cleaning/rules/link_wrapped_images.py b/websites/management/commands/markdown_cleaning/rules/link_wrapped_images.py index 9ffb3e81e..469c10559 100644 --- a/websites/management/commands/markdown_cleaning/rules/link_wrapped_images.py +++ b/websites/management/commands/markdown_cleaning/rules/link_wrapped_images.py @@ -138,7 +138,7 @@ def replace_match( # noqa: PLR0911 fragment=fragment, ) - def get_replacement( # noqa: PLR0913 + def get_replacement( self, page_content: WebsiteContent, linked_content: WebsiteContent, diff --git a/websites/management/commands/markdown_cleaning/rules/rootrelative_urls.py b/websites/management/commands/markdown_cleaning/rules/rootrelative_urls.py index 21d76f06c..a8a8226fe 100644 --- a/websites/management/commands/markdown_cleaning/rules/rootrelative_urls.py +++ b/websites/management/commands/markdown_cleaning/rules/rootrelative_urls.py @@ -156,7 +156,7 @@ def fuzzy_find_linked_content( # noqa: C901, PLR0911, PLR0915 match = self.legacy_file_lookup.find(site.uuid, site_rel_path) return match, "unique file match" # noqa: TRY300 except self.legacy_file_lookup.MultipleMatchError as error: - raise self.NotFoundError(error) # noqa: B904, TRY200 + raise self.NotFoundError(error) # noqa: B904 except KeyError as error: if "." in site_rel_path[-8:]: msg = "Content not found. Perhaps unmigrated file" diff --git a/websites/management/commands/update_content_fields.py b/websites/management/commands/update_content_fields.py index 10d309499..0584cb732 100644 --- a/websites/management/commands/update_content_fields.py +++ b/websites/management/commands/update_content_fields.py @@ -71,4 +71,4 @@ def handle(self, *args, **options): contents = self.filter_website_contents(website_contents=contents) contents.update(**updated_data) except FieldDoesNotExist as e: - raise CommandError(e) # noqa: B904, TRY200 + raise CommandError(e) # noqa: B904 diff --git a/websites/serializers_test.py b/websites/serializers_test.py index 44fa240c6..ae6fa58b0 100644 --- a/websites/serializers_test.py +++ b/websites/serializers_test.py @@ -50,7 +50,7 @@ # pylint:disable=redefined-outer-name -@pytest.fixture() +@pytest.fixture def mocked_website_funcs(mocker): """Mocked website-related functions""" # noqa: D401 return SimpleNamespace( diff --git a/websites/signals_test.py b/websites/signals_test.py index ee75d107b..28d72e20f 100644 --- a/websites/signals_test.py +++ b/websites/signals_test.py @@ -7,7 +7,7 @@ from websites.factories import WebsiteFactory -@pytest.mark.django_db() +@pytest.mark.django_db def test_handle_website_save(): """Groups should be created for a new Website""" website = WebsiteFactory.create(owner=UserFactory.create()) diff --git a/websites/views_test.py b/websites/views_test.py index 427bb6e6b..8aa6508d9 100644 --- a/websites/views_test.py +++ b/websites/views_test.py @@ -56,7 +56,7 @@ } -@pytest.fixture() +@pytest.fixture def websites(course_starter): """Create some websites for tests, with all but one having a sitemetadata WebsiteContent object""" courses = WebsiteFactory.create_batch(3, published=True, starter=course_starter) @@ -75,7 +75,7 @@ def websites(course_starter): ) -@pytest.fixture() +@pytest.fixture def file_upload(): """File upload for tests""" return SimpleUploadedFile("exam.pdf", b"sample pdf", content_type="application/pdf")