Skip to content

Commit

Permalink
Merge pull request #4587 from mozilla/move-to-pyproject
Browse files Browse the repository at this point in the history
Move Python configuration to `pyproject.toml`
  • Loading branch information
jwhitlock authored Apr 10, 2024
2 parents 0c90168 + 76688c3 commit 43db2e2
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 42 deletions.
58 changes: 34 additions & 24 deletions emails/tests/views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,10 @@ def test_get_message_content_from_s3_not_found(self) -> None:
operation_name="S3.something",
error_response={"Error": {"Code": "NoSuchKey", "Message": "the message"}},
)
with self.assertLogs(INFO_LOG) as info_caplog, self.assertLogs(
ERROR_LOG, "ERROR"
) as events_caplog:
with (
self.assertLogs(INFO_LOG) as info_caplog,
self.assertLogs(ERROR_LOG, "ERROR") as events_caplog,
):
response = _sns_notification(EMAIL_SNS_BODIES["s3_stored_replies"])
self.mock_send_raw_email.assert_not_called()
assert response.status_code == 404
Expand All @@ -866,9 +867,10 @@ def test_get_message_content_from_s3_other_error(self) -> None:
operation_name="S3.something",
error_response={"Error": {"Code": "IsNapping", "Message": "snooze"}},
)
with self.assertLogs(INFO_LOG) as info_caplog, self.assertLogs(
ERROR_LOG, "ERROR"
) as error_caplog:
with (
self.assertLogs(INFO_LOG) as info_caplog,
self.assertLogs(ERROR_LOG, "ERROR") as error_caplog,
):
response = _sns_notification(EMAIL_SNS_BODIES["s3_stored_replies"])
self.mock_send_raw_email.assert_not_called()
assert response.status_code == 503
Expand All @@ -888,9 +890,10 @@ def test_ses_client_error(self) -> None:
EMAIL_SNS_BODIES["s3_stored_replies"], text="text content"
)
self.mock_send_raw_email.side_effect = SEND_RAW_EMAIL_FAILED
with self.assertLogs(INFO_LOG) as info_caplog, self.assertLogs(
ERROR_LOG, "ERROR"
) as error_caplog:
with (
self.assertLogs(INFO_LOG) as info_caplog,
self.assertLogs(ERROR_LOG, "ERROR") as error_caplog,
):
response = _sns_notification(EMAIL_SNS_BODIES["s3_stored_replies"])
assert response.status_code == 400
assert response.content == b"SES client error"
Expand Down Expand Up @@ -1412,9 +1415,10 @@ def test_get_text_html_s3_client_error_email_in_s3_not_deleted(
{"Error": {"Code": "SomeErrorCode", "Message": "Details"}}, ""
)

with self.assertLogs(INFO_LOG) as info_caplog, self.assertLogs(
ERROR_LOG, "ERROR"
) as error_caplog:
with (
self.assertLogs(INFO_LOG) as info_caplog,
self.assertLogs(ERROR_LOG, "ERROR") as error_caplog,
):
response = _sns_notification(EMAIL_SNS_BODIES["s3_stored"])
self.mock_remove_message_from_s3.assert_not_called()
assert response.status_code == 503
Expand Down Expand Up @@ -1519,9 +1523,10 @@ def test_get_message_content_from_s3_not_found(self) -> None:
operation_name="S3.something",
error_response={"Error": {"Code": "NoSuchKey", "Message": "the message"}},
)
with self.assertLogs(INFO_LOG) as info_caplog, self.assertLogs(
ERROR_LOG, "ERROR"
) as error_caplog:
with (
self.assertLogs(INFO_LOG) as info_caplog,
self.assertLogs(ERROR_LOG, "ERROR") as error_caplog,
):
response = _sns_message(self.message_json)
self.mock_ses_client.send_raw_email.assert_not_called()
assert response.status_code == 404
Expand All @@ -1535,9 +1540,10 @@ def test_get_message_content_from_s3_not_found(self) -> None:

def test_ses_send_raw_email_has_client_error_early_exits(self) -> None:
self.mock_ses_client.send_raw_email.side_effect = SEND_RAW_EMAIL_FAILED
with self.assertLogs(INFO_LOG) as info_caplog, self.assertLogs(
ERROR_LOG, "ERROR"
) as error_caplog:
with (
self.assertLogs(INFO_LOG) as info_caplog,
self.assertLogs(ERROR_LOG, "ERROR") as error_caplog,
):
response = _sns_message(self.message_json)
self.mock_ses_client.send_raw_email.assert_called_once()
assert response.status_code == 503
Expand Down Expand Up @@ -1624,17 +1630,21 @@ def test_uppercase_domain_part_of_existing_domain_address(self) -> None:
assert _get_address("[email protected]") == self.domain_address

def test_subdomain_for_wrong_domain_raises(self) -> None:
with pytest.raises(
ObjectDoesNotExist
) as exc_info, MetricsMock() as mm, self.assertNoLogs(GLEAN_LOG, "INFO"):
with (
pytest.raises(ObjectDoesNotExist) as exc_info,
MetricsMock() as mm,
self.assertNoLogs(GLEAN_LOG, "INFO"),
):
_get_address("[email protected]")
assert str(exc_info.value) == "Address does not exist"
mm.assert_incr_once("fx.private.relay.email_for_not_supported_domain")

def test_unknown_subdomain_raises(self) -> None:
with pytest.raises(
Profile.DoesNotExist
), MetricsMock() as mm, self.assertNoLogs(GLEAN_LOG, "INFO"):
with (
pytest.raises(Profile.DoesNotExist),
MetricsMock() as mm,
self.assertNoLogs(GLEAN_LOG, "INFO"),
):
_get_address("[email protected]")
mm.assert_incr_once("fx.private.relay.email_for_dne_subdomain")

Expand Down
9 changes: 6 additions & 3 deletions privaterelay/tests/views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,12 @@ def request_callback(request) -> tuple[int, dict[str, str], str]:
json.dumps(profile_response.data),
)

with responses.RequestsMock() as mock_responses, patch(
"privaterelay.views.fxa_verifying_keys", return_value=[fxa_verifying_key]
) as mock_fxa_verifying_keys:
with (
responses.RequestsMock() as mock_responses,
patch(
"privaterelay.views.fxa_verifying_keys", return_value=[fxa_verifying_key]
) as mock_fxa_verifying_keys,
):
mock_responses.add_callback(
responses.GET,
f"{settings.SOCIALACCOUNT_PROVIDERS['fxa']['PROFILE_ENDPOINT']}/profile",
Expand Down
35 changes: 28 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[project]
requires-python = ">= 3.11"

[tool.django-stubs]
django_settings_module = "privaterelay.settings"

[tool.mypy]
plugins = ["mypy_django_plugin.main"]
mypy_path = "$MYPY_CONFIG_FILE_DIR/mypy_stubs"
exclude = "env"
mypy_path = "$MYPY_CONFIG_FILE_DIR/mypy_stubs"
plugins = ["mypy_django_plugin.main"]
python_version = "3.11"
show_error_codes = true
strict = true
Expand All @@ -15,9 +21,6 @@ disallow_untyped_calls = false
disallow_incomplete_defs = false
disallow_untyped_defs = false

[tool.django-stubs]
django_settings_module = "privaterelay.settings"

[[tool.mypy.overrides]]
ignore_missing_imports = true
module = [
Expand Down Expand Up @@ -46,14 +49,32 @@ module = [
"oauthlib.oauth2.rfc6749.errors",
"requests_oauthlib",
"silk",
"twilio.base.instance_resource",
"twilio.base.exceptions",
"twilio.rest",
"twilio.base.instance_resource",
"twilio.request_validator",
"twilio.rest",
"vobject",
"waffle",
"waffle.models",
"waffle.testutils",
"whitenoise.middleware",
"whitenoise.storage",
]

[tool.paul-mclendahand]
# Creates a PR that combines several dependabot PRs
# https://github.com/willkg/paul-mclendahand
github_project="fx-private-relay"
github_user="mozilla"
main_branch="main"

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "privaterelay.settings"
python_files = "tests.py test_*.py *_tests.py"
norecursedirs = ".git .local extension frontend node_modules"
testpaths = [
"api",
"emails",
"phones",
"privaterelay",
]
4 changes: 0 additions & 4 deletions pytest.ini

This file was deleted.

4 changes: 0 additions & 4 deletions setup.cfg

This file was deleted.

0 comments on commit 43db2e2

Please sign in to comment.