-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix daily limit counting when scheduling jobs (#2112)
* Fix daily limit counting when scheduling jobs - When scheduling a job, the daily limits in Redis will only be incremented if the job was scheduled for the current day - When refreshing daily count keys from the DB the underlying query will now include counts from jobs scheduled for the current day - Experimenting with a new decorator for feature flags - Fixed an issue with the dev container where the poetry installation will sometimes not be detected by adding the installation dir to the $PATH * Bump utils version and update lock file * fix tests? * Fix tests * Bump waffles commit sha in test action
- Loading branch information
Showing
10 changed files
with
164 additions
and
40 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 |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
from app.models import ( | ||
EMAIL_TYPE, | ||
INTERNATIONAL_SMS_TYPE, | ||
JOB_STATUS_SCHEDULED, | ||
KEY_TYPE_NORMAL, | ||
KEY_TYPE_TEAM, | ||
KEY_TYPE_TEST, | ||
|
@@ -68,6 +69,7 @@ | |
user_folder_permissions, | ||
) | ||
from app.schemas import service_schema | ||
from tests.app.conftest import create_sample_job | ||
from tests.app.db import ( | ||
create_annual_billing, | ||
create_api_key, | ||
|
@@ -1396,7 +1398,7 @@ def create_email_sms_letter_template(): | |
|
||
|
||
class TestServiceEmailLimits: | ||
def test_get_email_count_for_service(self, notify_db_session): | ||
def test_get_email_count_for_service(self): | ||
active_user_1 = create_user(email="[email protected]", state="active") | ||
service = Service( | ||
name="service_name", | ||
|
@@ -1432,7 +1434,98 @@ def test_dao_fetch_todays_total_message_count_returns_0_with_yesterday_messages( | |
notification = save_notification( | ||
create_notification( | ||
created_at=yesterday, | ||
template=create_template(service=create_service(service_name="tester"), template_type="email"), | ||
template=create_template(service=create_service(service_name="tester123"), template_type="email"), | ||
) | ||
) | ||
assert fetch_todays_total_message_count(notification.service.id) == 0 | ||
|
||
def test_dao_fetch_todays_total_message_count_counts_notifications_in_jobs_scheduled_for_today( | ||
self, notify_db, notify_db_session | ||
): | ||
service = create_service(service_name="tester12") | ||
template = create_template(service=service, template_type="email") | ||
today = datetime.utcnow().date() | ||
|
||
create_sample_job( | ||
notify_db, | ||
notify_db_session, | ||
service=service, | ||
template=template, | ||
scheduled_for=today, | ||
job_status=JOB_STATUS_SCHEDULED, | ||
notification_count=10, | ||
) | ||
save_notification( | ||
create_notification( | ||
created_at=today, | ||
template=template, | ||
) | ||
) | ||
assert fetch_todays_total_message_count(service.id) == 11 | ||
|
||
def test_dao_fetch_todays_total_message_count_counts_notifications_in_jobs_scheduled_for_today_but_not_after_today( | ||
self, notify_db, notify_db_session | ||
): | ||
service = create_service() | ||
template = create_template(service=service, template_type="email") | ||
today = datetime.utcnow().date() | ||
|
||
create_sample_job( | ||
notify_db, | ||
notify_db_session, | ||
service=service, | ||
template=template, | ||
scheduled_for=today, | ||
job_status=JOB_STATUS_SCHEDULED, | ||
notification_count=10, | ||
) | ||
save_notification( | ||
create_notification( | ||
created_at=today, | ||
template=template, | ||
) | ||
) | ||
create_sample_job( | ||
notify_db, | ||
notify_db_session, | ||
service=service, | ||
template=template, | ||
scheduled_for=today + timedelta(days=1), | ||
job_status=JOB_STATUS_SCHEDULED, | ||
notification_count=10, | ||
) | ||
|
||
assert fetch_todays_total_message_count(service.id) == 11 | ||
|
||
def test_dao_fetch_todays_total_message_count_counts_notifications_in_jobs_scheduled_for_today_but_not_before_today( | ||
self, notify_db, notify_db_session | ||
): | ||
service = create_service() | ||
template = create_template(service=service, template_type="email") | ||
today = datetime.utcnow().date() | ||
|
||
create_sample_job( | ||
notify_db, | ||
notify_db_session, | ||
service=service, | ||
template=template, | ||
scheduled_for=today, | ||
job_status=JOB_STATUS_SCHEDULED, | ||
notification_count=10, | ||
) | ||
create_sample_job( | ||
notify_db, | ||
notify_db_session, | ||
service=service, | ||
template=template, | ||
scheduled_for=today - timedelta(days=1), | ||
job_status=JOB_STATUS_SCHEDULED, | ||
notification_count=10, | ||
) | ||
save_notification( | ||
create_notification( | ||
created_at=today, | ||
template=template, | ||
) | ||
) | ||
assert fetch_todays_total_message_count(service.id) == 11 |
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