Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Nov 11, 2024
1 parent 233fd59 commit be0422b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
27 changes: 0 additions & 27 deletions app/clients/sms/aws_sns.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import datetime
import os
import re
from time import monotonic
from unittest.mock import MagicMock

import botocore
import phonenumbers
from boto3 import client

from app.celery.tasks import __total_sending_limits_for_job_exceeded
from app.clients import AWS_CLIENT_CONFIG
from app.clients.sms import SmsClient
from app.cloudfoundry_config import cloud_config
Expand Down Expand Up @@ -98,27 +95,3 @@ def send_sms(self, to, content, reference, sender=None, international=False):
if not matched:
self.current_app.logger.error("No valid numbers found in {}".format(to))
raise ValueError("No valid numbers found for SMS delivery")

def test_total_sending_limits_exceeded(mocker):
mock_service = MagicMock()
mock_service.total_message_limit = 1000
mock_job = MagicMock()
mock_job.notification_count = 300
job_id = "test_job_id"

mock_check_service_limit = mocker.patch(
"app.clients.sms.aws_sns.check_service_over_total_message_limit"
)
mock_check_service_limit.return_value = 800

mock_utc_now = mocker.patch("app.clients.sms.aws_sns.utc_now")
mock_utc_now.return_value = datetime(2024, 11, 10, 12, 0, 0)

mock_dao_update_job = mocker.patch("app.clients.sms.aws_sns.dao_update_job")

result = __total_sending_limits_for_job_exceeded(mock_service, mock_job, job_id)
assert result is True

assert mock_job.job_status == "sensding limits exceeded"
assert mock_job.processing_finished == datetime(2024, 11, 10, 12, 0, 0)
mock_dao_update_job.assert_called_once_with(mock_job)
28 changes: 27 additions & 1 deletion tests/app/celery/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import uuid
from datetime import datetime, timedelta
from unittest.mock import Mock, call
from unittest.mock import MagicMock, Mock, call

import pytest
import requests_mock
Expand All @@ -13,6 +13,7 @@
from app import encryption
from app.celery import provider_tasks, tasks
from app.celery.tasks import (
__total_sending_limits_for_job_exceeded,
get_recipient_csv_and_template_and_sender_id,
process_incomplete_job,
process_incomplete_jobs,
Expand Down Expand Up @@ -1634,3 +1635,28 @@ def create_encrypted_notification():

assert len(Notification.query.all()) == 3
assert len(mock_provider_task.call_args_list) == 3


def test_total_sending_limits_exceeded(mocker):
mock_service = MagicMock()
mock_service.total_message_limit = 1000
mock_job = MagicMock()
mock_job.notification_count = 300
job_id = "test_job_id"

mock_check_service_limit = mocker.patch(
"app.celery.tasks.check_service_over_total_message_limit"
)
mock_check_service_limit.return_value = 800

mock_utc_now = mocker.patch("app.celery.tasks.utc_now")
mock_utc_now.return_value = datetime(2024, 11, 10, 12, 0, 0)

mock_dao_update_job = mocker.patch("app.celery.tasks.dao_update_job")

result = __total_sending_limits_for_job_exceeded(mock_service, mock_job, job_id)
assert result is True

assert mock_job.job_status == "sensding limits exceeded"
assert mock_job.processing_finished == datetime(2024, 11, 10, 12, 0, 0)
mock_dao_update_job.assert_called_once_with(mock_job)

0 comments on commit be0422b

Please sign in to comment.