-
Notifications
You must be signed in to change notification settings - Fork 5
Feat/purchase email #733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/purchase email #733
Conversation
## Walkthrough
This change introduces a full event-driven notification system for privilege purchases. It adds event schemas, event publishing logic, notification infrastructure (NotificationStack), Lambda handlers for privilege purchase events, and email notification templates. The system ensures that providers receive email confirmations with detailed privilege and cost information upon privilege purchase.
## Changes
| File(s) | Change Summary |
|-----------------------------------------------------------------------------------------------------------|---------------|
| .../common_constructs/queued_lambda_processor.py | Added configurable DLQ alarm threshold to processor constructor and alarms. |
| .../lambdas/nodejs/email-notification-service/lambda.ts | Added handler case for privilege purchase provider notification email. |
| .../lambdas/nodejs/lib/email/base-email-service.ts | Added methods for tuple/table insertion and text alignment in email templates. |
| .../lambdas/nodejs/lib/email/email-notification-service.ts | Added method to send privilege purchase provider notification emails. |
| .../lambdas/nodejs/tests/email-notification-service.test.ts | Added tests for privilege purchase provider notification email sending and error handling. |
| .../lambdas/python/common/cc_common/config.py | Added event bus client as a cached property. |
| .../lambdas/python/common/cc_common/data_model/data_client.py | `create_provider_privileges` now returns privilege summaries. |
| .../lambdas/python/common/cc_common/email_service_client.py | Added method to send privilege purchase emails. |
| .../lambdas/python/common/cc_common/event_bus_client.py | New module: EventBusClient for publishing privilege-related events. |
| .../lambdas/python/common/cc_common/data_model/schema/data_event/api.py | New module: Marshmallow schemas for event payloads (privilege purchase, issuance, renewal). |
| .../lambdas/python/provider-data-v1/handlers/privileges.py | Added SQS handler for privilege purchase events to send notification emails. |
| .../lambdas/python/purchases/handlers/privileges.py | Publishes privilege purchase, issued, and renewed events after privilege creation. |
| .../lambdas/python/purchases/purchase_client.py | Ensures line items are returned as strings in privilege purchase response. |
| .../stacks/api_stack/v1_api/api.py | Loads event bus from SSM and passes to API components. |
| .../stacks/api_stack/v1_api/purchases.py, .../stacks/api_stack/v1_api/provider_management.py | Accepts event bus as constructor parameter and grants Lambda permissions to put events. |
| .../stacks/notification_stack.py | New NotificationStack: sets up event-driven notification processing for privilege purchases. |
| .../pipeline/backend_stage.py | Instantiates NotificationStack alongside ReportingStack. |
| .../lambdas/python/common/tests/function/test_data_client.py | Adds assertions for returned privilege data. |
| .../lambdas/python/common/tests/resources/events/purchase_event_body.json | Adds sample privilege purchase event for testing. |
| .../lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py | Adds test for privilege purchase message handler sending email. |
| .../lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py, .../unit/test_purchase_client.py | Adds/updates tests for line items in privilege purchase responses and event emission. |
| .../lambdas/python/purchases/tests/__init__.py, .../function/__init__.py | Adds event bus to test environment and setup. |
| .../common_constructs/stack.py, .../data_model/schema/*, .../event_batch_writer.py, .../handlers/bulk_upload.py, .../handlers/ingest.py | Minor formatting, import, or whitespace changes. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant PurchasesLambda as Purchases Lambda
participant EventBus as Event Bus
participant NotificationStack as Notification Lambda (SQS)
participant EmailService as Email Service Lambda
participant Provider as Provider
PurchasesLambda->>EventBus: Publish privilege.purchase event (with privileges, cost, line items)
EventBus->>NotificationStack: Route event to SQS queue (via EventBridge rule)
NotificationStack->>EmailService: Invoke send_privilege_purchase_email (with event details)
EmailService->>Provider: Send privilege purchase confirmation email Assessment against linked issues
Suggested reviewers
Poem
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (3)
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py (3)
2-2
: Remove unused imports.The static analysis correctly identifies that
UTC
anddatetime
are imported but never used in this file.-from datetime import UTC, date, datetime +from datetime import date🧰 Tools
🪛 Ruff (0.11.9)
2-2:
datetime.UTC
imported but unusedRemove unused import
(F401)
2-2:
datetime.datetime
imported but unusedRemove unused import
(F401)
315-317
: Fix the cost calculation to handle potential edge cases.The current implementation could fail if
unitPrice
orquantity
contain non-numeric values or if line items are missing required fields.Apply this diff to make the calculation more robust:
- # calculate total cost of transaction - total_cost = 0 - for line_item in cost_line_items: - total_cost = total_cost + float(line_item['unitPrice']) * int(line_item['quantity']) + # calculate total cost of transaction + total_cost = 0 + for line_item in cost_line_items: + try: + unit_price = float(line_item.get('unitPrice', 0)) + quantity = int(line_item.get('quantity', 0)) + total_cost += unit_price * quantity + except (ValueError, TypeError) as e: + logger.error(f'Invalid line item data: {line_item}, error: {e}') + raise CCInternalException('Invalid transaction line item data') from e
332-336
: Fix the logical error in determining renewed vs issued privileges.The current logic compares jurisdiction strings against a list of privilege records, which will always return
False
. This means all privileges will be incorrectly classified as "issued" instead of "renewed".The comparison should check if the jurisdiction exists in the existing privileges:
for jurisdiction in selected_jurisdictions_postal_abbreviations: - if jurisdiction in existing_privileges_for_license: + if any(privilege['jurisdiction'].lower() == jurisdiction for privilege in existing_privileges_for_license): privileges_renewed.append(jurisdiction) else: privileges_issued.append(jurisdiction)
🧹 Nitpick comments (1)
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py (1)
296-353
: Consider extracting event publishing logic into a separate method.The event publishing section significantly increases the length of the main handler function. Consider extracting this logic into a dedicated method to improve readability and separation of concerns.
Example refactor:
+ def _publish_privilege_events(self, provider_email: str, compact_abbr: str, license_jurisdiction: str, + privileges: list, total_cost: str, cost_line_items: list, + selected_jurisdictions_postal_abbreviations: list, + existing_privileges_for_license: list): + """Publish privilege purchase, issued, and renewed events.""" + config.event_bus_client.publish_privilege_purchase_event( + source='post_purchase_privileges', + jurisdiction=license_jurisdiction, + compact=compact_abbr, + provider_email=provider_email, + privileges=privileges, + total_cost=total_cost, + cost_line_items=cost_line_items, + ) + + existing_jurisdictions = {privilege['jurisdiction'].lower() for privilege in existing_privileges_for_license} + + for jurisdiction in selected_jurisdictions_postal_abbreviations: + if jurisdiction in existing_jurisdictions: + config.event_bus_client.publish_privilege_renewed_event( + source='post_purchase_privileges', + jurisdiction=jurisdiction, + compact=compact_abbr, + provider_email=provider_email, + ) + else: + config.event_bus_client.publish_privilege_issued_event( + source='post_purchase_privileges', + jurisdiction=jurisdiction, + compact=compact_abbr, + provider_email=provider_email, + ) # calculate total cost of transaction - total_cost = 0 - for line_item in cost_line_items: - total_cost = total_cost + float(line_item['unitPrice']) * int(line_item['quantity']) - - config.event_bus_client.publish_privilege_purchase_event( - source='post_purchase_privileges', - jurisdiction=license_jurisdiction, - compact=compact_abbr, - provider_email=provider_email, - privileges=privileges, - total_cost=str(total_cost), - cost_line_items=cost_line_items, - ) - - privileges_renewed = [] - privileges_issued = [] - - for jurisdiction in selected_jurisdictions_postal_abbreviations: - if jurisdiction in existing_privileges_for_license: - privileges_renewed.append(jurisdiction) - else: - privileges_issued.append(jurisdiction) - - for privilege_jurisdiction_issued in privileges_issued: - config.event_bus_client.publish_privilege_issued_event( - source='post_purchase_privileges', - jurisdiction=privilege_jurisdiction_issued, - compact=compact_abbr, - provider_email=provider_email, - ) - - for privilege_jurisdiction_renewed in privileges_renewed: - config.event_bus_client.publish_privilege_renewed_event( - source='post_purchase_privileges', - jurisdiction=privilege_jurisdiction_renewed, - compact=compact_abbr, - provider_email=provider_email, - ) + try: + total_cost = sum(float(item.get('unitPrice', 0)) * int(item.get('quantity', 0)) + for item in cost_line_items) + except (ValueError, TypeError) as e: + logger.error(f'Invalid line item data: {cost_line_items}, error: {e}') + raise CCInternalException('Invalid transaction line item data') from e + + self._publish_privilege_events( + provider_email, compact_abbr, license_jurisdiction, privileges, + str(total_cost), cost_line_items, selected_jurisdictions_postal_abbreviations, + existing_privileges_for_license + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py
(3 hunks)backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py
(7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py
🧰 Additional context used
🪛 Ruff (0.11.9)
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py
2-2: datetime.UTC
imported but unused
Remove unused import
(F401)
2-2: datetime.datetime
imported but unused
Remove unused import
(F401)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: TestPython
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful 🥹
@jlkravitz This is ready for review. Also, heads up that one of @landonshumway-ia current tickets is blocked until this gets merged so I think this is the highest priority thing from our perspective. Thanks! |
@ChiefStief on this right now! Sorry I didn't see this message- I should check my email notification settings... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left several comments! I think a couple of resolved comments still require some changes, but feel free to respond on those threads if I'm wrong and/or if you decided to leave them out for whatever reason.
backend/compact-connect/lambdas/nodejs/lib/email/email-notification-service.ts
Show resolved
Hide resolved
backend/compact-connect/lambdas/python/provider-data-v1/handlers/privileges.py
Show resolved
Hide resolved
...pact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
Outdated
Show resolved
Hide resolved
...pact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
Outdated
Show resolved
Hide resolved
...pact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
Outdated
Show resolved
Hide resolved
...ct-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py
Outdated
Show resolved
Hide resolved
...ct-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py
Outdated
Show resolved
Hide resolved
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py
Outdated
Show resolved
Hide resolved
backend/compact-connect/lambdas/python/common/cc_common/data_model/schema/data_event/api.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (4)
backend/compact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py (1)
292-292
: Remove commented out code.This commented line should be removed as it serves no purpose and was flagged in previous reviews.
- # self._run_privilege_purchase_message_handler()
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py (1)
327-329
: 🛠️ Refactor suggestionEnhance cost calculation robustness.
The cost calculation should handle potential edge cases where
unitPrice
orquantity
might be missing or contain invalid values, as mentioned in previous reviews.Apply this diff to make the calculation more robust:
- # calculate total cost of transaction - total_cost = 0 - for line_item in cost_line_items: - total_cost = total_cost + float(line_item['unitPrice']) * int(line_item['quantity']) + # calculate total cost of transaction + total_cost = 0 + for line_item in cost_line_items: + try: + unit_price = float(line_item.get('unitPrice', 0)) + quantity = int(line_item.get('quantity', 0)) + total_cost += unit_price * quantity + except (ValueError, TypeError) as e: + logger.error(f'Invalid line item data: {line_item}, error: {e}') + raise CCInternalException('Invalid transaction line item data') from ebackend/compact-connect/lambdas/python/common/cc_common/event_bus_client.py (2)
18-22
: [Duplicate] Consider dependency injection in the constructor.This empty constructor still creates tight coupling to the global config module, making testing difficult.
23-44
: [Duplicate] Add error handling and logging to the_publish_event
method.The method still lacks error handling for API calls that could fail due to network issues or permission problems.
🧹 Nitpick comments (7)
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py (1)
331-367
: Consider extracting event publishing logic into a separate method.The event publishing logic is well-implemented but makes the main handler quite long. Consider extracting this into a separate method like
_publish_privilege_events()
to improve readability and separate concerns, as suggested in previous reviews.This would help organize the code by separating privilege creation logic from event publishing logic.
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 344-344: Line too long (104/100)
(C0301)
backend/compact-connect/lambdas/python/common/cc_common/data_model/schema/data_event/api.py (2)
1-53
: Add module and class docstrings for better maintainability.The schema structure is well-designed with proper inheritance and field validation. However, adding docstrings would improve code documentation and address static analysis warnings.
Consider adding a module docstring and class docstrings:
+""" +Marshmallow schemas for privilege purchase event validation and serialization. + +These schemas define the structure for privilege-related events published to the event bus, +including purchase, issuance, and renewal events. +""" + # ruff: noqa: N801, N815 invalid-nameAlso consider adding brief class docstrings for each schema class to document their purpose.
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 40-40: Line too long (120/100)
(C0301)
[convention] 43-43: Line too long (104/100)
(C0301)
[convention] 1-1: Missing module docstring
(C0114)
[error] 2-2: Unable to import 'cc_common.data_model.schema.base_record'
(E0401)
[error] 3-6: Unable to import 'cc_common.data_model.schema.fields'
(E0401)
[error] 7-13: Unable to import 'marshmallow.fields'
(E0401)
[error] 14-14: Unable to import 'marshmallow.validate'
(E0401)
[convention] 17-17: Missing class docstring
(C0115)
[refactor] 17-17: Too few public methods (0/2)
(R0903)
[convention] 25-25: Missing class docstring
(C0115)
[refactor] 25-25: Too few public methods (0/2)
(R0903)
[convention] 32-32: Missing class docstring
(C0115)
[refactor] 32-32: Too few public methods (0/2)
(R0903)
[convention] 38-38: Missing class docstring
(C0115)
[refactor] 38-38: Too few public methods (0/2)
(R0903)
[convention] 47-47: Missing class docstring
(C0115)
[refactor] 47-47: Too few public methods (0/2)
(R0903)
[convention] 51-51: Missing class docstring
(C0115)
[refactor] 51-51: Too few public methods (0/2)
(R0903)
40-44
: Fix line length issues for better readability.The long lines exceed the project's 100-character limit. Consider breaking them for better readability:
- privileges = List(Nested(PrivilegeEventPrivilegeSchema(), required=True, allow_none=False), validate=Length(1, 100)) + privileges = List( + Nested(PrivilegeEventPrivilegeSchema(), required=True, allow_none=False), + validate=Length(1, 100) + ) totalCost = String(required=True, allow_none=False) - costLineItems = List( - Nested(PrivilegeEventLineItemSchema(), required=True, allow_none=False), validate=Length(1, 300) - ) + costLineItems = List( + Nested(PrivilegeEventLineItemSchema(), required=True, allow_none=False), + validate=Length(1, 300) + )🧰 Tools
🪛 Pylint (3.3.7)
[convention] 40-40: Line too long (120/100)
(C0301)
[convention] 43-43: Line too long (104/100)
(C0301)
backend/compact-connect/stacks/notification_stack.py (1)
49-49
: Consider breaking long lines for better readability.- 'EMAIL_NOTIFICATION_SERVICE_LAMBDA_NAME': persistent_stack.email_notification_service_lambda.function_name, # noqa: E501 line-too-long + 'EMAIL_NOTIFICATION_SERVICE_LAMBDA_NAME': ( + persistent_stack.email_notification_service_lambda.function_name + ),🧰 Tools
🪛 Pylint (3.3.7)
[convention] 49-49: Line too long (151/100)
(C0301)
backend/compact-connect/lambdas/python/common/cc_common/event_bus_client.py (2)
46-55
: Add comprehensive docstrings for public methods.The public event publishing methods lack docstrings. Given their complex parameter lists and role as public API, they should include detailed documentation.
Example for the first method:
def publish_privilege_purchase_event( self, source: str, jurisdiction: str, compact: str, provider_email: str, privileges: list[dict], total_cost: str, cost_line_items: list[dict], ): + """ + Publish a privilege purchase event to the event bus. + + Args: + source: The source system publishing the event + jurisdiction: The jurisdiction where the privilege was purchased + compact: The compact identifier + provider_email: Email address of the provider purchasing the privilege + privileges: List of privilege dictionaries containing privilege details + total_cost: Total cost of the purchase as a string + cost_line_items: List of cost breakdown items + """Also applies to: 73-79, 94-100
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 46-46: Missing function or method docstring
(C0116)
[refactor] 46-46: Too many arguments (8/5)
(R0913)
[refactor] 46-46: Too many positional arguments (8/5)
(R0917)
71-71
: Fix line length violations for better readability.The
_publish_event
calls exceed the 100-character limit. Consider multi-line formatting:- self._publish_event(source=source, detail_type='privilege.purchase', detail=deserialized_detail) + self._publish_event( + source=source, + detail_type='privilege.purchase', + detail=deserialized_detail + )Apply similar formatting to lines 92 and 113.
Also applies to: 92-92, 113-113
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 71-71: Line too long (104/100)
(C0301)
backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py (1)
339-339
: Minor style improvements for better maintainability.Consider addressing these minor issues:
- Line length violations on lines 339 and 343 could be resolved with multi-line formatting
- Add docstrings to the new test methods for better documentation
- Specify encoding when opening files (line 344)
Example for line 339:
- event = self._when_testing_provider_user_event_with_custom_claims(license_expiration_date=test_expiration_date) + event = self._when_testing_provider_user_event_with_custom_claims( + license_expiration_date=test_expiration_date + )Also applies to: 343-343
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 339-339: Line too long (119/100)
(C0301)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
backend/compact-connect/lambdas/python/common/cc_common/data_model/schema/data_event/api.py
(1 hunks)backend/compact-connect/lambdas/python/common/cc_common/event_bus_client.py
(1 hunks)backend/compact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
(4 hunks)backend/compact-connect/lambdas/python/purchases/handlers/privileges.py
(2 hunks)backend/compact-connect/lambdas/python/purchases/purchase_client.py
(2 hunks)backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py
(7 hunks)backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py
(2 hunks)backend/compact-connect/stacks/notification_stack.py
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/compact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py (4)
backend/compact-connect/lambdas/python/common/tests/function/__init__.py (1)
_load_provider_data
(212-227)backend/compact-connect/lambdas/python/common/cc_common/email_service_client.py (1)
send_privilege_purchase_email
(187-218)backend/compact-connect/lambdas/python/common/cc_common/exceptions.py (1)
CCInternalException
(31-32)backend/compact-connect/lambdas/python/provider-data-v1/handlers/privileges.py (1)
privilege_purchase_message_handler
(127-165)
🪛 Pylint (3.3.7)
backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py
[convention] 33-33: Line too long (117/100)
(C0301)
[convention] 249-249: Line too long (101/100)
(C0301)
[convention] 249-249: Missing function or method docstring
(C0116)
[convention] 339-339: Line too long (119/100)
(C0301)
[convention] 343-343: Line too long (107/100)
(C0301)
[convention] 271-271: Missing function or method docstring
(C0116)
[convention] 276-276: Import outside toplevel (handlers.privileges.post_purchase_privileges)
(C0415)
[convention] 304-304: Missing function or method docstring
(C0116)
[convention] 309-309: Import outside toplevel (handlers.privileges.post_purchase_privileges)
(C0415)
[convention] 326-326: Missing function or method docstring
(C0116)
[convention] 331-331: Import outside toplevel (handlers.privileges.post_purchase_privileges)
(C0415)
[warning] 344-344: Using open without explicitly specifying an encoding
(W1514)
[convention] 533-533: Line too long (109/100)
(C0301)
[convention] 580-580: Line too long (109/100)
(C0301)
backend/compact-connect/lambdas/python/common/cc_common/data_model/schema/data_event/api.py
[convention] 40-40: Line too long (120/100)
(C0301)
[convention] 43-43: Line too long (104/100)
(C0301)
[convention] 1-1: Missing module docstring
(C0114)
[error] 2-2: Unable to import 'cc_common.data_model.schema.base_record'
(E0401)
[error] 3-6: Unable to import 'cc_common.data_model.schema.fields'
(E0401)
[error] 7-13: Unable to import 'marshmallow.fields'
(E0401)
[error] 14-14: Unable to import 'marshmallow.validate'
(E0401)
[convention] 17-17: Missing class docstring
(C0115)
[refactor] 17-17: Too few public methods (0/2)
(R0903)
[convention] 25-25: Missing class docstring
(C0115)
[refactor] 25-25: Too few public methods (0/2)
(R0903)
[convention] 32-32: Missing class docstring
(C0115)
[refactor] 32-32: Too few public methods (0/2)
(R0903)
[convention] 38-38: Missing class docstring
(C0115)
[refactor] 38-38: Too few public methods (0/2)
(R0903)
[convention] 47-47: Missing class docstring
(C0115)
[refactor] 47-47: Too few public methods (0/2)
(R0903)
[convention] 51-51: Missing class docstring
(C0115)
[refactor] 51-51: Too few public methods (0/2)
(R0903)
backend/compact-connect/lambdas/python/common/cc_common/event_bus_client.py
[convention] 71-71: Line too long (104/100)
(C0301)
[convention] 92-92: Line too long (102/100)
(C0301)
[convention] 113-113: Line too long (103/100)
(C0301)
[convention] 1-1: Missing module docstring
(C0114)
[convention] 46-46: Missing function or method docstring
(C0116)
[refactor] 46-46: Too many arguments (8/5)
(R0913)
[refactor] 46-46: Too many positional arguments (8/5)
(R0917)
[convention] 73-73: Missing function or method docstring
(C0116)
[convention] 94-94: Missing function or method docstring
(C0116)
backend/compact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
[convention] 168-168: Line too long (108/100)
(C0301)
[convention] 214-214: Line too long (114/100)
(C0301)
[convention] 220-220: Line too long (117/100)
(C0301)
[convention] 249-249: Line too long (120/100)
(C0301)
[convention] 289-289: Line too long (117/100)
(C0301)
[convention] 293-293: Import outside toplevel (handlers.privileges.privilege_purchase_message_handler)
(C0415)
[warning] 295-295: Using open without explicitly specifying an encoding
(W1514)
[error] 301-301: Too many positional arguments for function call
(E1121)
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py
[convention] 344-344: Line too long (104/100)
(C0301)
backend/compact-connect/lambdas/python/purchases/purchase_client.py
[convention] 467-467: Line too long (104/100)
(C0301)
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py
[convention] 235-235: Line too long (111/100)
(C0301)
[convention] 235-235: Missing function or method docstring
(C0116)
[convention] 236-236: Import outside toplevel (purchase_client.PurchaseClient)
(C0415)
[convention] 322-322: Line too long (114/100)
(C0301)
backend/compact-connect/stacks/notification_stack.py
[convention] 49-49: Line too long (151/100)
(C0301)
[convention] 58-58: Line too long (112/100)
(C0301)
[convention] 62-62: Line too long (102/100)
(C0301)
[convention] 82-82: Line too long (119/100)
(C0301)
[convention] 99-99: Line too long (104/100)
(C0301)
[convention] 1-1: Missing module docstring
(C0114)
[error] 5-5: Unable to import 'aws_cdk'
(E0401)
[error] 6-6: Unable to import 'aws_cdk.aws_cloudwatch'
(E0401)
[error] 7-7: Unable to import 'aws_cdk.aws_cloudwatch_actions'
(E0401)
[error] 8-8: Unable to import 'aws_cdk.aws_events'
(E0401)
[error] 9-9: Unable to import 'aws_cdk.aws_events_targets'
(E0401)
[error] 10-10: Unable to import 'cdk_nag'
(E0401)
[error] 15-15: Unable to import 'constructs'
(E0401)
[convention] 20-20: Missing class docstring
(C0115)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: TestPython
🔇 Additional comments (13)
backend/compact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py (2)
166-175
: LGTM: Improved test isolation with targeted patching.The refactoring from decorator-based to context manager patching with a more specific target (
handlers.privileges.config.email_service_client
) improves test isolation and clarity about what's being mocked.🧰 Tools
🪛 Pylint (3.3.7)
[convention] 168-168: Line too long (108/100)
(C0301)
219-225
: LGTM: Consistent refactoring pattern applied.These changes follow the same improved patching pattern established in the earlier test method, maintaining consistency across the test suite.
Also applies to: 255-261
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 220-220: Line too long (117/100)
(C0301)
backend/compact-connect/lambdas/python/purchases/purchase_client.py (2)
411-411
: LGTM: Well-justified duplicate window adjustment.The 35-second duplicate window strikes a good balance between preventing duplicate transactions and allowing legitimate retries, especially given the 30-second API Gateway timeout mentioned in previous discussions.
462-479
: LGTM: Proper serialization handling for downstream processing.The line items serialization correctly handles AuthorizeNet SDK object conversion to JSON-serializable dictionaries. The string casting prevents serialization errors and follows the same pattern used elsewhere in the codebase for transaction details.
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 467-467: Line too long (104/100)
(C0301)
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py (1)
234-278
: LGTM! Excellent use of comprehensive assertion approach.This test follows the best practice suggested in past reviews by using a single comprehensive assertion to validate the entire
lineItems
structure rather than multiple individual field assertions. The test thoroughly validates both line items with all expected fields.🧰 Tools
🪛 Pylint (3.3.7)
[convention] 235-235: Line too long (111/100)
(C0301)
[convention] 235-235: Missing function or method docstring
(C0116)
[convention] 236-236: Import outside toplevel (purchase_client.PurchaseClient)
(C0415)
backend/compact-connect/lambdas/python/purchases/handlers/privileges.py (1)
308-320
: Well-structured privilege filtering approach.The privilege filtering creates a clean, minimal subset of data that's appropriate for event publishing. Good implementation that separates concerns between internal data structures and event payloads.
backend/compact-connect/stacks/notification_stack.py (2)
20-32
: Excellent infrastructure setup with comprehensive monitoring.The notification stack is well-designed with proper error handling, alarms, and permissions. The integration of EventBridge, SQS, and Lambda follows AWS best practices.
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 20-20: Missing class docstring
(C0115)
100-100
: Great addition of configurable DLQ alarm threshold.Setting the DLQ alarm threshold to 1 ensures immediate notification of any failed message processing, which is appropriate for critical email notifications.
backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_purchase_privileges.py (5)
33-33
: Good addition of test constant.The
MOCK_LINE_ITEMS
constant promotes consistency and maintainability across tests.🧰 Tools
🪛 Pylint (3.3.7)
[convention] 33-33: Line too long (117/100)
(C0301)
140-142
: LGTM! Mock properly updated to match interface changes.The mock now correctly returns both
transactionId
andlineItems
, matching the updated purchase client interface.
261-267
: Excellent test coverage for updated response format.The assertions properly verify both
transactionId
andlineItems
in responses, ensuring complete test coverage of the interface changes.Also applies to: 533-533, 580-580
269-301
: Comprehensive event bus integration testing.These tests provide excellent coverage of the event publishing functionality:
- Separate tests for each event type (purchase, issued, renewed)
- Proper verification of event parameters and data
- Good test isolation with focused assertions
The renewed event test properly sets up an existing privilege scenario, ensuring realistic test conditions.
Also applies to: 302-323, 324-366
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 271-271: Missing function or method docstring
(C0116)
[convention] 276-276: Import outside toplevel (handlers.privileges.post_purchase_privileges)
(C0415)
713-715
: Proper update to transaction voiding.The void transaction call now includes
lineItems
in the order information, ensuring complete transaction data is provided for proper cleanup.
...pact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
Outdated
Show resolved
Hide resolved
backend/compact-connect/lambdas/python/purchases/tests/unit/test_purchase_client.py
Show resolved
Hide resolved
@jlkravitz Ok, ready for another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one commented out code and one coderabbit comment but otherwise looks good!
...pact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
Outdated
Show resolved
Hide resolved
...pact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_privileges.py
Outdated
Show resolved
Hide resolved
@jlkravitz Ok, I resolved the coderabbit comment and deleted the last commented out code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isabeleliassen good to merge!
Requirements List
Description List
Testing List
backend/compact-connect/tests/unit/test_api.py
Closes #533
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Tests
Documentation