forked from bcgov/sbc-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Debugging print * more logging to figure out an issue * more debug * more debug * Disable update env * remove self._publisher * Fix up the queue * Change logging a bit, fix make files so it's rapid fire. * Move logging down a tad * Move logging.conf * Add in error for unknown message type, add in enums for missing sections * Put in detection against duplicate queue messages for account-mailer. * Point at new auth-api * lint fix * lint fix * lint fixes * Add in unit test for duplicate message ids * rename accident * Fix enums in account-mailer so they match sbc-common * use correct enum * Update URL, other one causes an error * Fix indent * Add in duplicate message handling for auth-queue. * fix up requirements * Fix linting issues * See if unit test passes again * restore update-env for makefiles * lint + test fix
- Loading branch information
Showing
24 changed files
with
169 additions
and
29 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
auth-api/migrations/versions/2024_05_15_b3a741249edc_duplicate_queue_messages.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Add in new table for account mailer for pubsub message processing. | ||
Revision ID: b3a741249edc | ||
Revises: e2d1d6417607 | ||
Create Date: 2024-05-15 14:52:45.780399 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'b3a741249edc' | ||
down_revision = 'e2d1d6417607' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table('pubsub_message_processing', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('cloud_event_id', sa.String(length=250), nullable=False), | ||
sa.Column('created', sa.DateTime(), nullable=True), | ||
sa.Column('message_type', sa.String(length=250), nullable=False), | ||
sa.Column('processed', sa.DateTime(), nullable=True), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_pubsub_message_processing_id'), 'pubsub_message_processing', ['id'], unique=False) | ||
|
||
|
||
def downgrade(): | ||
op.drop_index(op.f('ix_pubsub_message_processing_id'), table_name='pubsub_message_processing') | ||
op.drop_table('pubsub_message_processing') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""This model manages pubsub message processing. | ||
NOTE: Only use this when it's not possible to use other indicators to track message processing. | ||
Currently used by the account-mailer / auth-queue. This prevents duplicates. | ||
""" | ||
import datetime as dt | ||
import pytz | ||
|
||
from sqlalchemy import Column, DateTime, Integer, String | ||
from .db import db | ||
|
||
|
||
class PubSubMessageProcessing(db.Model): | ||
"""PubSub Message Processing for cloud event messages.""" | ||
|
||
__tablename__ = 'pubsub_message_processing' | ||
|
||
id = Column(Integer, index=True, primary_key=True) | ||
cloud_event_id = Column(String(250), nullable=False) | ||
created = Column(DateTime, default=dt.datetime.now(pytz.utc)) | ||
message_type = Column(String(250), nullable=False) | ||
processed = Column(DateTime, nullable=True) | ||
|
||
@classmethod | ||
def find_by_id(cls, identifier): | ||
"""Find a pubsub message processing by id.""" | ||
return cls.query.filter_by(id=identifier).one_or_none() | ||
|
||
@classmethod | ||
def find_by_cloud_event_id_and_type(cls, cloud_event_id, message_type): | ||
"""Find a pubsub message processing for cloud event id and type.""" | ||
return cls.query.filter_by(cloud_event_id=cloud_event_id, message_type=message_type).one_or_none() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,32 @@ def test_refund_request(app, session, client): | |
mock_send.assert_called | ||
|
||
|
||
def test_duplicate_messages(app, session, client): | ||
"""Assert that duplicate messages are handled by the queue..""" | ||
user = factory_user_model_with_contact() | ||
org = factory_org_model() | ||
factory_membership_model(user.id, org.id) | ||
id = org.id | ||
mail_details = { | ||
'accountId': id, | ||
'accountName': org.name | ||
} | ||
|
||
with patch.object(notification_service, 'send_email', return_value=None) as mock_send: | ||
helper_add_event_to_queue(client, message_type=QueueMessageTypes.NSF_LOCK_ACCOUNT.value, | ||
mail_details=mail_details, message_id='f76e5ca9-93f3-44ee-a0f8-f47ee83b1971') | ||
mock_send.assert_called | ||
assert mock_send.call_args.args[0].get('recipients') == '[email protected]' | ||
assert mock_send.call_args.args[0].get('content').get('subject') == SubjectType.NSF_LOCK_ACCOUNT_SUBJECT.value | ||
assert mock_send.call_args.args[0].get('attachments') is None | ||
assert True | ||
|
||
with patch.object(notification_service, 'send_email', return_value=None) as mock_send: | ||
helper_add_event_to_queue(client, message_type=QueueMessageTypes.NSF_LOCK_ACCOUNT.value, | ||
mail_details=mail_details, message_id='f76e5ca9-93f3-44ee-a0f8-f47ee83b1971') | ||
mock_send.assert_not_called | ||
|
||
|
||
def test_lock_account_mailer_queue(app, session, client): | ||
"""Assert that events can be retrieved and decoded from the Queue.""" | ||
user = factory_user_model_with_contact() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.