-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Implement Postmark Community Nudge Report (#1196)
* Feat: Add email tagging functionality to mass email sending * Chore: Remove unused postmark_nudge_report.py file * Refactor: Update email tagging in nudges and add new report functionality - Modified `generate_email_tag` function to include a development mode tag when not in production. - Updated email tagging in `cadmin_events_nudge.py`, `cadmin_testimonial_nudge.py`, and `user_event_nudge.py` to use constants from `type_constants.py`. - Introduced `postmark_nudge_report.py` to generate and send CSV reports for nudge statistics using Postmark API. * Feat: Add shell command to Makefile for local Django environment - Introduced a new `sh` target in the Makefile to launch the Django shell in a local environment using `DJANGO_ENV=local`. * Feat: Implement Postmark Nudge Report functionality - Added a new report type, POSTMARK_NUDGE_REPORT, to the constants. - Enhanced the email sending functionality to include a new nudge report for community admins. - Introduced methods to generate and send CSV reports based on nudge statistics using the Postmark API. - Updated the DownloadHandler to handle requests for the new nudge report. - Refactored existing code to integrate the new report generation and sending logic. This commit improves the reporting capabilities for community engagement metrics. * Refactor: Remove print statements and enhance error logging in postmark_nudge_report.py - Eliminated print statements from various functions to streamline error handling. - Improved error logging by ensuring all exceptions are logged consistently. - Maintained functionality for generating and sending community reports via Postmark API. * Fix: Update Postmark Nudge Report URL to include tag parameter - Modified the URL in the get_stats_from_postmark function to include the 'tag' parameter for more accurate reporting. - This change enhances the functionality of the Postmark Nudge Report by allowing filtering based on specific tags. * Test: Add unit tests for Postmark Nudge Report functionality - Introduced a new test suite for the Postmark Nudge Report, covering key functions such as get_stats_from_postmark, get_community_admins, generate_csv_file, send_community_report, and generate_postmark_nudge_report. - Ensured that the tests validate the expected behavior of these functions, contributing to improved code reliability and maintainability. * Test: Add comprehensive unit tests for Postmark Nudge Report functionality - Introduced a new test suite in `test_postmark_nudge_report.py` to validate key functions related to Postmark Nudge Reports, including `get_stats_from_postmark`, `get_community_admins`, `generate_csv_file`, `generate_community_report_data`, `send_community_report`, and `send_user_requested_postmark_nudge_report`. - Implemented tests to ensure correct behavior and output for generating reports and handling community data, contributing to enhanced reliability and maintainability of the codebase. * Test: Enhance integration tests for Postmark Nudge Report functionality - Added a new test case in `test_download.py` to validate the behavior of the Postmark Nudge Report endpoint, ensuring correct responses based on user authentication status. - Removed outdated tests from `test_postmark_nudge_report.py` to streamline the test suite and focus on relevant functionality. - These changes improve the reliability of the integration tests and ensure accurate reporting for community engagement metrics. * Test: Update Postmark Nudge Report integration test - Commented out the patch for the download_data.delay method in the test_postmark_nudge_report function within test_download.py. - This change simplifies the test setup while maintaining the focus on validating the Postmark Nudge Report endpoint functionality. * Test: Re-enable patch for download_data.delay in Postmark Nudge Report integration test - Restored the patch decorator for the download_data.delay method in the test_postmark_nudge_report function within test_download.py. - This change enhances the test setup by allowing the simulation of the download task, ensuring a more comprehensive validation of the Postmark Nudge Report endpoint functionality.
- Loading branch information
1 parent
b60c93d
commit 7093f1a
Showing
16 changed files
with
360 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.test import TestCase | ||
from task_queue.nudges.postmark_nudge_report import ( | ||
get_stats_from_postmark, | ||
get_community_admins, | ||
generate_csv_file, | ||
send_community_report, | ||
generate_postmark_nudge_report | ||
) | ||
from database.models import Community, UserProfile, CommunityAdminGroup | ||
|
||
class PostmarkNudgeReportTests(TestCase): | ||
|
||
def setUp(self): | ||
self.community = Community.objects.create(name="Test Community", subdomain="test") | ||
self.user = UserProfile.objects.create(email="[email protected]", full_name="Test User") | ||
ad = CommunityAdminGroup.objects.create(community=self.community) | ||
ad.members.add(self.user) | ||
|
||
def test_get_stats_from_postmark(self): | ||
response = get_stats_from_postmark("test_tag", "2023-01-01", "2023-01-31") | ||
self.assertIsNotNone(response) | ||
|
||
def test_get_community_admins(self): | ||
# Test getting community admins | ||
admins = get_community_admins(self.community) | ||
self.assertIn(self.user.email, admins) | ||
|
||
def test_generate_csv_file(self): | ||
rows = [["Header1", "Header2"], ["Row1Col1", "Row1Col2"]] | ||
csv_content = generate_csv_file(rows) | ||
self.assertIsNotNone(csv_content) | ||
|
||
def test_send_community_report(self): | ||
report = b"Test report content" | ||
filename = "test_report.csv" | ||
send_community_report(report, self.community, filename, self.user) | ||
|
||
|
||
def test_generate_postmark_nudge_report(self): | ||
result = generate_postmark_nudge_report() | ||
self.assertTrue(result) |
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
Oops, something went wrong.