-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
89 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
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
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 |
---|---|---|
|
@@ -719,11 +719,11 @@ def create_batch(): | |
return batch | ||
|
||
|
||
def create_furnishing(business=None, batch_id=None, email='[email protected]'): | ||
def create_furnishing(business=None, batch_id=None, email='[email protected]', furnishing_name='DISSOLUTION_COMMENCEMENT_NO_AR'): | ||
"""Return a test furnishing.""" | ||
furnishing = Furnishing() | ||
furnishing.furnishing_type = 'EMAIL' | ||
furnishing.furnishing_name = 'DISSOLUTION_COMMENCEMENT_NO_AR' | ||
furnishing.furnishing_name = furnishing_name | ||
furnishing.status = Furnishing.FurnishingStatus.QUEUED | ||
furnishing.email = email | ||
if business: | ||
|
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 |
---|---|---|
|
@@ -11,15 +11,15 @@ | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""The Unit Tests for the stage 1 overdue ARs email processor.""" | ||
"""The Unit Tests for the involuntary_dissolution_stage_1_notification processor.""" | ||
from unittest.mock import patch | ||
|
||
from entity_emailer.email_processors import ar_overdue_stage_1_notification | ||
from entity_emailer.email_processors import involuntary_dissolution_stage_1_notification | ||
from tests.unit import create_business, create_furnishing # noqa: I003 | ||
|
||
|
||
def test_ar_overdue_stage_1_notification(app, session, mocker): | ||
"""Assert that the stage 1 overdue ARs notification can be processed.""" | ||
def test_involuntary_dissolution_stage_1_notification(app, session, mocker): | ||
"""Assert that the test_involuntary_dissolution_stage_1_notification can be processed.""" | ||
token = 'token' | ||
message_id = '16fd2111-8baf-433b-82eb-8c7fada84ccc' | ||
business_identifier = 'BC1234567' | ||
|
@@ -44,10 +44,9 @@ def test_ar_overdue_stage_1_notification(app, session, mocker): | |
|
||
# test processor | ||
mocker.patch( | ||
'entity_emailer.email_processors.ar_overdue_stage_1_notification.get_jurisdictions', | ||
'entity_emailer.email_processors.involuntary_dissolution_stage_1_notification.get_jurisdictions', | ||
return_value=[]) | ||
with patch.object(ar_overdue_stage_1_notification, 'get_recipient_from_auth', return_value='[email protected]'): | ||
email = ar_overdue_stage_1_notification.process(message_payload, token) | ||
email = involuntary_dissolution_stage_1_notification.process(message_payload, token) | ||
|
||
assert email['content']['subject'] == f'Attention {business_identifier} - Test Business' | ||
assert email['recipients'] == '[email protected]' | ||
|
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 |
---|---|---|
|
@@ -16,15 +16,15 @@ | |
from unittest.mock import patch | ||
|
||
import pytest | ||
from entity_queue_common.service_utils import QueueException | ||
from entity_queue_common.service_utils import EmailException, QueueException | ||
from legal_api.models import Business | ||
from legal_api.services import NameXService | ||
from legal_api.services.bootstrap import AccountService | ||
from legal_api.utils.legislation_datetime import LegislationDatetime | ||
|
||
from entity_emailer import worker | ||
from entity_emailer.email_processors import ( | ||
ar_overdue_stage_1_notification, | ||
involuntary_dissolution_stage_1_notification, | ||
ar_reminder_notification, | ||
correction_notification, | ||
filing_notification, | ||
|
@@ -471,40 +471,53 @@ def test_send_email_with_incomplete_payload(app, session, email_msg): | |
assert 'Unsuccessful sending email' in str(excinfo) | ||
|
||
|
||
def test_ar_overdue_stage_1_notification(app, session, mocker): | ||
@pytest.mark.parametrize(['test_name', 'exception', 'furnishing_name', 'expected_furnishing_status'], [ | ||
('Will be failed with invalid furnishing_name', QueueException, 'INVALID_NAME', 'QUEUED'), | ||
('Will be processed with valid furnishing_name', None, 'DISSOLUTION_COMMENCEMENT_NO_AR', 'PROCESSED'), | ||
('Will be processed with valid furnishing_name', None, 'DISSOLUTION_COMMENCEMENT_NO_TR', 'PROCESSED'), | ||
('Will be processed with valid furnishing_name', None, 'DISSOLUTION_COMMENCEMENT_NO_AR_XPRO', 'PROCESSED'), | ||
('Will be processed with valid furnishing_name', None, 'DISSOLUTION_COMMENCEMENT_NO_TR_XPRO', 'PROCESSED'), | ||
('When email is failed', EmailException, 'DISSOLUTION_COMMENCEMENT_NO_AR', 'FAILED') | ||
]) | ||
def test_involuntary_dissolution_stage_1_notification(app, db, session, mocker, test_name, exception, furnishing_name, expected_furnishing_status): | ||
"""Assert that the stage 1 overdue ARs notification can be processed.""" | ||
token = 'token' | ||
business_identifier = 'BC1234567' | ||
business = create_business(business_identifier, 'BC', 'Test Business') | ||
furnishing = create_furnishing(business) | ||
furnishing = create_furnishing(business=business) | ||
|
||
mocker.patch( | ||
'entity_emailer.email_processors.ar_overdue_stage_1_notification.get_jurisdictions', | ||
'entity_emailer.email_processors.involuntary_dissolution_stage_1_notification.get_jurisdictions', | ||
return_value=[]) | ||
|
||
|
||
message_payload = { | ||
'specversion': '1.x-wip', | ||
'type': 'bc.registry.dissolution', | ||
'source': 'furnishingsJob', | ||
'id': '16fd2111-8baf-433b-82eb-8c7fada84ccc', | ||
'time': '', | ||
'datacontenttype': 'application/json', | ||
'identifier': business_identifier, | ||
'data': { | ||
'furnishing': { | ||
'type': 'PROCESSING', | ||
'furnishingId': furnishing.id, | ||
'furnishingName': furnishing_name | ||
} | ||
} | ||
} | ||
|
||
# run worker | ||
with patch.object(AccountService, 'get_bearer_token', return_value=token): | ||
with patch.object(worker, 'send_email', return_value='success') as mock_send_email: | ||
with patch.object(ar_overdue_stage_1_notification, 'get_recipient_from_auth', return_value='[email protected]'): | ||
worker.process_email({ | ||
'specversion': '1.x-wip', | ||
'type': 'bc.registry.dissolution', | ||
'source': 'furnishingsJob', | ||
'id': 'f36e3af7-90c3-4859-a6f6-2feefbdc1e37', | ||
'time': '', | ||
'datacontenttype': 'application/json', | ||
'identifier': business_identifier, | ||
'data': { | ||
'furnishing': { | ||
'type': 'PROCESSING', | ||
'furnishingId': furnishing.id, | ||
'furnishingName': furnishing.furnishing_name | ||
} | ||
} | ||
}, app) | ||
|
||
call_args = mock_send_email.call_args | ||
assert call_args[0][0]['content']['subject'] == f'Attention {business_identifier} - Test Business' | ||
assert call_args[0][0]['recipients'] == '[email protected]' | ||
assert call_args[0][0]['content']['body'] | ||
assert call_args[0][1] == token | ||
with patch.object(worker, 'send_email', return_value='success', side_effect=exception) as mock_send_email: | ||
if exception: | ||
with pytest.raises(exception): | ||
worker.process_email(message_payload, app) | ||
else: | ||
worker.process_email(message_payload, app) | ||
|
||
if furnishing_name != 'INVALID_NAME': | ||
call_args = mock_send_email.call_args | ||
assert call_args[0][0]['content']['subject'] == f'Attention {business_identifier} - Test Business' | ||
assert call_args[0][0]['recipients'] == '[email protected]' | ||
assert call_args[0][0]['content']['body'] | ||
|
||
assert furnishing.status.name == expected_furnishing_status |