-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notifications model and goods report notification (#1036)
* Introduce Notification base-class and specialising sub-classes. * Change emphasis of sub-class implementations - get notify template ID and notified users. * Associate Notifications with their source notified object. * Use proxy model of inheritance in base classes. * WIP mostly working fix notification choices * address type error and serialisation issues * remove comment add todo * Refactor notification inits and fixed email list * tests, mocks broke & goods report not working * Working tests! * removing unused fixtures * test fixes and admin filter * test fix * Confirm should be true by default * PR comments --------- Co-authored-by: Paul Pepper <[email protected]>
- Loading branch information
1 parent
6833b1b
commit bec000a
Showing
31 changed files
with
1,685 additions
and
363 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,5 @@ _dumped_cache.pkl | |
|
||
# Vim | ||
.swp | ||
|
||
tamato_*.sql |
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,40 @@ | ||
{% extends "layouts/layout.jinja" %} | ||
{% from "components/breadcrumbs/macro.njk" import govukBreadcrumbs %} | ||
{% from "components/button/macro.njk" import govukButton %} | ||
{% from "components/panel/macro.njk" import govukPanel %} | ||
|
||
|
||
{% set page_title = "Notify Goods Report" %} | ||
|
||
|
||
{% block breadcrumb %} | ||
{{ govukBreadcrumbs({ | ||
"items": [ | ||
{"text": "Home", "href": url("home")}, | ||
{"text": "Edit an existing workbasket", "href": url("workbaskets:workbasket-ui-list")}, | ||
{"text": "Workbasket " ~ request.session.workbasket.id ~ " - Review goods", | ||
"href": url("workbaskets:workbasket-ui-review-goods")}, | ||
{"text": page_title} | ||
] | ||
}) }} | ||
{% endblock %} | ||
|
||
|
||
{% block content %} | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
{{ govukPanel({ | ||
"titleText": "Notification email sent", | ||
"text": "An email notification has been successfully sent to Channel Islands.", | ||
"classes": "govuk-!-margin-bottom-7" | ||
}) }} | ||
|
||
<div class="govuk-button-group"> | ||
<a class="govuk-link" href="{{ url('workbaskets:workbasket-ui-review-goods') }}"> | ||
Back to Review goods list | ||
</a> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
{% endblock %} |
43 changes: 43 additions & 0 deletions
43
importer/management/commands/send_goods_report_notification.py
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,43 @@ | ||
from django.core.management import BaseCommand | ||
from django.core.management.base import CommandError | ||
|
||
from importer.models import ImportBatch | ||
from notifications.models import GoodsSuccessfulImportNotification | ||
|
||
|
||
def send_notifcation( | ||
import_id: int, | ||
): | ||
try: | ||
import_batch = ImportBatch.objects.get( | ||
pk=import_id, | ||
) | ||
except ImportBatch.DoesNotExist: | ||
raise CommandError( | ||
f"No ImportBatch instance found with pk={import_id}", | ||
) | ||
|
||
notification = GoodsSuccessfulImportNotification( | ||
notified_object_pk=import_batch.id, | ||
) | ||
notification.save() | ||
notification.synchronous_send_emails() | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Send a good report notifcation for a give Id" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--import-batch-id", | ||
help=( | ||
"The primary key ID of ImportBatch instance for which a report " | ||
"should be generated." | ||
), | ||
type=int, | ||
) | ||
|
||
def handle(self, *args, **options): | ||
send_notifcation( | ||
import_id=options["import_batch_id"], | ||
) |
52 changes: 52 additions & 0 deletions
52
importer/tests/management/commands/test_send_goods_report_notification.py
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,52 @@ | ||
from unittest.mock import MagicMock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from django.core.management import call_command | ||
from django.core.management.base import CommandError | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args, exception_type, error_msg", | ||
[ | ||
( | ||
[""], | ||
CommandError, | ||
"Error: unrecognized arguments:", | ||
), | ||
( | ||
["--import-batch-id", "1234"], | ||
CommandError, | ||
"No ImportBatch instance found with pk=1234", | ||
), | ||
], | ||
) | ||
def test_send_goods_report_notification_required_arguments( | ||
args, | ||
exception_type, | ||
error_msg, | ||
): | ||
"""Test that `send_goods_report_notification` command raises errors when | ||
invalid arguments are provided.""" | ||
with pytest.raises(exception_type, match=error_msg): | ||
call_command("send_goods_report_notification", *args) | ||
|
||
|
||
def test_send_goods_report_notification( | ||
completed_goods_import_batch, | ||
): | ||
"""Test that `send_goods_report_notification` command triggers an email | ||
notification.""" | ||
|
||
with patch( | ||
"notifications.models.send_emails_task", | ||
return_value=MagicMock(), | ||
) as mocked_email_task: | ||
call_command( | ||
"send_goods_report_notification", | ||
"--import-batch-id", | ||
str(completed_goods_import_batch.id), | ||
) | ||
mocked_email_task.assert_called_once() |
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.