Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 16, 2024
1 parent 6d75f51 commit 2db919b
Show file tree
Hide file tree
Showing 37 changed files with 84 additions and 85 deletions.
14 changes: 7 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def default_settings(settings): # noqa: PT004
settings.DISABLE_WEBPACK_LOADER_STATS = True


@pytest.fixture()
@pytest.fixture
def mocked_celery(mocker):
"""Mock object that patches certain celery functions"""
exception_class = TabError
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion content_sync/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions content_sync/apis/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion content_sync/backends/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions content_sync/backends/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions content_sync/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def mock_concourse_hard_purge(settings, request): # noqa: PT004
settings.CONCOURSE_HARD_PURGE = request.param


@pytest.fixture()
@pytest.fixture
def mock_branches(settings, mocker):
"""Return mock github branches with names"""
mocked_branches = []
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion content_sync/pipelines/concourse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
]


@pytest.fixture()
@pytest.fixture
def mock_auth(mocker): # noqa: PT004
"""Mock the concourse api auth method"""
mocker.patch("content_sync.pipelines.concourse.PipelineApi.auth")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions content_sync/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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"
Expand All @@ -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"),
[
Expand Down Expand Up @@ -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"""
Expand All @@ -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"}
Expand All @@ -337,7 +337,7 @@ def test_metadata_file_serialize():
}


@pytest.mark.django_db()
@pytest.mark.django_db
@pytest.mark.parametrize(
("serializer_cls", "file_content"),
[
Expand Down Expand Up @@ -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"),
[
Expand Down
4 changes: 2 additions & 2 deletions content_sync/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
# 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"
settings.CONTENT_SYNC_PIPELINE_BACKEND = "concourse"
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")
Expand Down
4 changes: 2 additions & 2 deletions external_resources/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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",
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_check_external_resources( # noqa: PLR0913
)


@pytest.mark.django_db()
@pytest.mark.django_db
def test_check_external_resources_failed(mocker):
"""Test for failed api check"""
external_resource_state = ExternalResourceStateFactory()
Expand Down
4 changes: 2 additions & 2 deletions fixtures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions gdrive_sync/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
# 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()
@pytest.fixture
def mock_get_s3_content_type(mocker): # noqa: PT004
"""Mock gdrive_sync.api.get_s3_content_type"""
mocker.patch(
Expand Down Expand Up @@ -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"""
Expand All @@ -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)],
Expand Down Expand Up @@ -536,7 +536,7 @@ def test_walk_gdrive_folder(mocker):
) # parent, subfolder1, subfolder1_1, subfolder2


@pytest.fixture()
@pytest.fixture
def mock_gdrive_pdf(mocker): # noqa: PT004
"""Mock reading the metadata of a PDF file with blank metadata"""
mocker.patch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
Loading

0 comments on commit 2db919b

Please sign in to comment.