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 Dec 16, 2024
1 parent b82af8c commit eb04b2b
Show file tree
Hide file tree
Showing 41 changed files with 106 additions and 107 deletions.
16 changes: 8 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
14 changes: 7 additions & 7 deletions content_sync/apis/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions content_sync/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ 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
settings.ENVIRONMENT = request.param


@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 = []
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
6 changes: 3 additions & 3 deletions content_sync/pipelines/concourse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion external_resources/signals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 7 additions & 7 deletions external_resources/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit eb04b2b

Please sign in to comment.