Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion notify-service/notify-api/devops/vaults.gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ NOTIFY_DATABASE_NAME="op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_NAME"
NOTIFY_DATABASE_SCHEMA="op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_SCHEMA"
MILLIONVERIFIER_API_URL="op://notify/$APP_ENV/millionverifier/MILLIONVERIFIER_API_URL"
MILLIONVERIFIER_API_KEY="op://notify/$APP_ENV/millionverifier/MILLIONVERIFIER_API_KEY"
GCP_AUTH_KEY="op://gcp-queue/$APP_ENV/c4hnrd/COMMON_GCP_AUTH_KEY"
AUDIENCE="op://gcp-queue/$APP_ENV/base/AUDIENCE"
PUBLISHER_AUDIENCE="op://gcp-queue/$APP_ENV/base/PUBLISHER_AUDIENCE"
DELIVERY_GCNOTIFY_TOPIC="op://gcp-queue/$APP_ENV/topics/NOTIFY_DELIVERY_GCNOTIFY_TOPIC"
Expand Down
1 change: 0 additions & 1 deletion notify-service/notify-api/src/notify_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Config: # pylint: disable=too-few-public-methods
JWT_OIDC_JWKS_CACHE_TIMEOUT = 300

# PUBSUB
GCP_AUTH_KEY = os.getenv("GCP_AUTH_KEY", "")
AUDIENCE = os.getenv("AUDIENCE", "https://pubsub.googleapis.com/google.pubsub.v1.Subscriber")
PUBLISHER_AUDIENCE = os.getenv("PUBLISHER_AUDIENCE", "https://pubsub.googleapis.com/google.pubsub.v1.Publisher")
DELIVERY_GCNOTIFY_TOPIC = os.getenv("DELIVERY_GCNOTIFY_TOPIC", "")
Expand Down
1 change: 0 additions & 1 deletion notify-service/notify-delivery/devops/vaults.gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ NOTIFY_DATABASE_INSTANCE_CONNECTION_NAME="op://database/$APP_ENV/notify-db-gcp/N
NOTIFY_DATABASE_USERNAME="op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_USERNAME"
NOTIFY_DATABASE_SCHEMA="op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_SCHEMA"
NOTIFY_DATABASE_NAME="op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_NAME"
GCP_AUTH_KEY="op://gcp-queue/$APP_ENV/c4hnrd/COMMON_GCP_AUTH_KEY"
VERIFY_PUBSUB_EMAIL="op://gcp-queue/$APP_ENV/c4hnrd/COMMON_SERVICE_ACCOUNT"
AUDIENCE="op://gcp-queue/$APP_ENV/base/AUDIENCE"
PUBLISHER_AUDIENCE="op://gcp-queue/$APP_ENV/base/PUBLISHER_AUDIENCE"
Expand Down
1 change: 0 additions & 1 deletion notify-service/notify-delivery/devops/vaults.ocp.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ NOTIFY_DATABASE_INSTANCE_CONNECTION_NAME=op://database/$APP_ENV/notify-db-gcp/NO
NOTIFY_DATABASE_USERNAME=op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_USERNAME
NOTIFY_DATABASE_NAME=op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_NAME
NOTIFY_DATABASE_SCHEMA=op://database/$APP_ENV/notify-db-gcp/NOTIFY_DATABASE_SCHEMA
GCP_AUTH_KEY=op://gcp-queue/$APP_ENV/c4hnrd/COMMON_GCP_AUTH_KEY
VERIFY_PUBSUB_EMAIL=op://gcp-queue/$APP_ENV/c4hnrd/COMMON_SERVICE_ACCOUNT
AUDIENCE=op://gcp-queue/$APP_ENV/base/AUDIENCE
PUBLISHER_AUDIENCE=op://gcp-queue/$APP_ENV/base/PUBLISHER_AUDIENCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class Config:
GC_NOTIFY_HOUSING_EMAIL_REPLY_TO_ID = os.getenv("GC_NOTIFY_HOUSING_EMAIL_REPLY_TO_ID", "")

# GCP PubSub
GCP_AUTH_KEY = os.getenv("GCP_AUTH_KEY", "")
AUDIENCE = os.getenv("AUDIENCE", "https://pubsub.googleapis.com/google.pubsub.v1.Subscriber")
PUBLISHER_AUDIENCE = os.getenv("PUBLISHER_AUDIENCE", "https://pubsub.googleapis.com/google.pubsub.v1.Publisher")
VERIFY_PUBSUB_EMAIL = os.getenv("VERIFY_PUBSUB_EMAIL", None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ def _create_mock_app(self, config_override=None):
"""Helper to create properly configured mock app."""
config = {**self.mock_config, **(config_override or {})}
mock_app = Mock()
mock_app.config.get.side_effect = lambda key, default=None: config.get(key, default)
mock_app.config.get.side_effect = config.get
return mock_app

@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_email_smtp_initialization(self, mock_current_app):
"""Test EmailSMTP class initialization."""
mock_current_app.config.get.side_effect = lambda key: self.mock_config.get(key)
mock_current_app.config.get.side_effect = self.mock_config.get

email_smtp = EmailSMTP(self.mock_notification)

Expand All @@ -82,7 +82,7 @@ def test_email_smtp_initialization(self, mock_current_app):
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_email_production_environment(self, mock_current_app, mock_smtp_class):
"""Test email sending in production environment."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

mock_server = Mock()
mock_smtp_class.return_value.__enter__.return_value = mock_server
Expand All @@ -101,7 +101,7 @@ def test_send_email_production_environment(self, mock_current_app, mock_smtp_cla
def test_send_email_development_environment(self, mock_current_app, mock_smtp_class):
"""Test email sending in development environment with subject suffix."""
dev_config = {**self.mock_config, "DEPLOYMENT_ENV": "development"}
mock_current_app.config.get.side_effect = lambda key, default=None: dev_config.get(key, default)
mock_current_app.config.get.side_effect = dev_config.get

mock_server = Mock()
mock_smtp_class.return_value.__enter__.return_value = mock_server
Expand All @@ -118,7 +118,7 @@ def test_send_email_development_environment(self, mock_current_app, mock_smtp_cl
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_email_multiple_recipients(self, mock_current_app, mock_smtp_class):
"""Test email sending to multiple recipients."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

multi_recipient_notification = Notification(
id=1,
Expand All @@ -143,7 +143,7 @@ def test_send_email_multiple_recipients(self, mock_current_app, mock_smtp_class)
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_email_with_attachments(self, mock_current_app, mock_smtp_class):
"""Test email sending with file attachments."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

attachment = Attachment(file_name="test_document.pdf", file_bytes=b"fake pdf content")
content_with_attachments = Content(
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_send_email_with_attachments(self, mock_current_app, mock_smtp_class):
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_email_unicode_attachment_filename(self, mock_current_app, mock_smtp_class):
"""Test email sending with unicode characters in attachment filename."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

attachment = Attachment(file_name="tëst_dócümént_ñäme.pdf", file_bytes=b"fake pdf content")
content_with_attachments = Content(
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_send_email_unicode_attachment_filename(self, mock_current_app, mock_smt
@patch("notify_delivery.services.providers.email_smtp.logger")
def test_send_email_smtp_connection_error(self, mock_logger, mock_current_app, mock_smtp_class):
"""Test handling of SMTP connection errors."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

mock_smtp_class.side_effect = smtplib.SMTPException("Connection failed")

Expand All @@ -221,7 +221,7 @@ def test_send_email_smtp_connection_error(self, mock_logger, mock_current_app, m
@patch("notify_delivery.services.providers.email_smtp.logger")
def test_send_email_individual_recipient_error(self, mock_logger, mock_current_app, mock_smtp_class):
"""Test handling of individual recipient send errors."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

multi_recipient_notification = Notification(
id=1,
Expand Down Expand Up @@ -253,7 +253,7 @@ def sendmail_side_effect(from_addr, to_addrs, msg):
def test_send_email_empty_deployment_env(self, mock_current_app, mock_smtp_class):
"""Test email sending with empty deployment environment."""
empty_env_config = {**self.mock_config, "DEPLOYMENT_ENV": ""}
mock_current_app.config.get.side_effect = lambda key, default=None: empty_env_config.get(key, default)
mock_current_app.config.get.side_effect = empty_env_config.get

mock_server = Mock()
mock_smtp_class.return_value.__enter__.return_value = mock_server
Expand All @@ -270,7 +270,7 @@ def test_send_email_empty_deployment_env(self, mock_current_app, mock_smtp_class
def test_send_email_missing_deployment_env(self, mock_current_app, mock_smtp_class):
"""Test email sending with missing deployment environment config."""
config_without_env = {k: v for k, v in self.mock_config.items() if k != "DEPLOYMENT_ENV"}
mock_current_app.config.get.side_effect = lambda key, default=None: config_without_env.get(key, default)
mock_current_app.config.get.side_effect = config_without_env.get

mock_server = Mock()
mock_smtp_class.return_value.__enter__.return_value = mock_server
Expand All @@ -285,7 +285,7 @@ def test_send_email_missing_deployment_env(self, mock_current_app, mock_smtp_cla
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_email_no_content_error(self, mock_current_app):
"""Test email sending with notification having no content."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

notification_no_content = Notification(
id=1,
Expand All @@ -306,7 +306,7 @@ def test_send_email_no_content_error(self, mock_current_app):
def test_send_email_staging_environment(self, mock_current_app, mock_smtp_class):
"""Test email sending in staging environment."""
staging_config = {**self.mock_config, "DEPLOYMENT_ENV": "staging"}
mock_current_app.config.get.side_effect = lambda key, default=None: staging_config.get(key, default)
mock_current_app.config.get.side_effect = staging_config.get

mock_server = Mock()
mock_smtp_class.return_value.__enter__.return_value = mock_server
Expand All @@ -322,7 +322,7 @@ def test_send_email_staging_environment(self, mock_current_app, mock_smtp_class)
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_email_message_structure(self, mock_current_app, mock_smtp_class):
"""Test that email message structure is correctly formatted."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

mock_server = Mock()
mock_smtp_class.return_value.__enter__.return_value = mock_server
Expand All @@ -346,7 +346,7 @@ def test_send_email_message_structure(self, mock_current_app, mock_smtp_class):
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_invalid_content_structure(self, mock_current_app):
"""Test sending with invalid content structure."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

# Create content without required attributes
invalid_content = MagicMock()
Expand All @@ -372,7 +372,7 @@ def test_send_invalid_content_structure(self, mock_current_app):
@patch("notify_delivery.services.providers.email_smtp.current_app", new_callable=Mock)
def test_send_with_whitespace_recipients(self, mock_current_app, mock_smtp_class):
"""Test email sending with recipients containing whitespace."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

notification_with_spaces = Notification(
id=1,
Expand All @@ -398,7 +398,7 @@ def test_send_with_whitespace_recipients(self, mock_current_app, mock_smtp_class
@patch("notify_delivery.services.providers.email_smtp.logger")
def test_send_general_exception_handling(self, mock_logger, mock_current_app, mock_smtp_class):
"""Test general exception handling during SMTP connection."""
mock_current_app.config.get.side_effect = lambda key, default=None: self.mock_config.get(key, default)
mock_current_app.config.get.side_effect = self.mock_config.get

mock_smtp_class.side_effect = Exception("Unexpected error")

Expand All @@ -415,7 +415,7 @@ def test_send_general_exception_handling(self, mock_logger, mock_current_app, mo
def test_prepare_subject_production(self, mock_current_app):
"""Test subject preparation in production environment."""
production_config = {**self.mock_config, "DEPLOYMENT_ENV": "production"}
mock_current_app.config.get.side_effect = lambda key, default=None: production_config.get(key, default)
mock_current_app.config.get.side_effect = production_config.get

email_smtp = EmailSMTP(self.mock_notification)
result = email_smtp._prepare_subject("Test Subject")
Expand All @@ -426,7 +426,7 @@ def test_prepare_subject_production(self, mock_current_app):
def test_prepare_subject_development(self, mock_current_app):
"""Test subject preparation in development environment."""
dev_config = {**self.mock_config, "DEPLOYMENT_ENV": "development"}
mock_current_app.config.get.side_effect = lambda key, default=None: dev_config.get(key, default)
mock_current_app.config.get.side_effect = dev_config.get

email_smtp = EmailSMTP(self.mock_notification)
result = email_smtp._prepare_subject("Test Subject")
Expand All @@ -437,7 +437,7 @@ def test_prepare_subject_development(self, mock_current_app):
def test_prepare_subject_unknown_env(self, mock_current_app):
"""Test subject preparation with unknown environment."""
config_without_env = {k: v for k, v in self.mock_config.items() if k != "DEPLOYMENT_ENV"}
mock_current_app.config.get.side_effect = lambda key, default=None: config_without_env.get(key, default)
mock_current_app.config.get.side_effect = config_without_env.get

email_smtp = EmailSMTP(self.mock_notification)
result = email_smtp._prepare_subject("Test Subject")
Expand All @@ -448,7 +448,7 @@ def test_prepare_subject_unknown_env(self, mock_current_app):
def test_prepare_subject_empty_env(self, mock_current_app):
"""Test subject preparation with empty deployment environment."""
empty_env_config = {**self.mock_config, "DEPLOYMENT_ENV": ""}
mock_current_app.config.get.side_effect = lambda key, default=None: empty_env_config.get(key, default)
mock_current_app.config.get.side_effect = empty_env_config.get

email_smtp = EmailSMTP(self.mock_notification)
result = email_smtp._prepare_subject("Test Subject")
Expand Down
Loading