Skip to content
Snippets Groups Projects
Commit 2475c235 authored by Janet Goldstein's avatar Janet Goldstein
Browse files

WS-908: fix broken notification tests

parent 218acc48
No related branches found
No related tags found
1 merge request!794WS-908: fix broken notification tests
Pipeline #4380 passed
......@@ -28,7 +28,7 @@ The logic can be found in `notification/views/notify.py`.
# TODO: re-enable after pydoc has been added
# pylint: disable=C0116
import copy
import http
from unittest.mock import patch
......@@ -68,8 +68,6 @@ class TestNotifyViews:
def test_send_notification_with_list(self, dummy_send: DummyRequest):
from notification.views.notify import NotificationRestService
# TODO: save original dummy_send values, and after assertions restore them in a `finally()`
dummy_send.json_body = {
"destination_email": ["chausman@nrao.edu", "dreamerofthestars@gmail.com"],
"subject": "first thing",
......@@ -85,41 +83,60 @@ class TestNotifyViews:
assert response["errors"] == {}
assert response["message"] == "Email sent"
@pytest.mark.skip("breaks update-template test")
def test_create_notification(self, dummy_send: DummyRequest):
# FIXME
from notification.views.notify import NotificationListRestService
"""
Can we create a notification template?
# TODO: save original dummy_send.matchdict first, then restore it in a `finally:`
dummy_send.json_body = {
"name": "new_template",
:param dummy_send:
:return:
"""
from notification.views.notify import NotificationRestService
dummy_create = copy.copy(dummy_send)
template_name = "oh_no_not_another_template"
dummy_create.json_body = {
"template_name": template_name,
"description": "a test template",
"content": "Subject: {{foo}}\n\n{{bar}}",
}
response = NotificationListRestService(dummy_send).create_notification_template()
assert response.status_code == http.HTTPStatus.CREATED
assert response.json_body == dummy_send.json_body
created = NotificationRestService(dummy_create).create_notification_template()
assert created.content == "Subject: {{foo}}\n\n{{bar}}"
dummy_create.matchdict["template_name"] = template_name
response = NotificationRestService(dummy_create).delete_notification_template()
assert response.status_code == http.HTTPStatus.OK
# if we can update it, we know it's been created
dummy_update = copy.copy(dummy_create)
dummy_update.json_body["template_name"] = template_name
dummy_update.json_body["template_text"] = "my little pony"
response = NotificationRestService(dummy_update).update_notification_template()
assert response.status_code == http.HTTPStatus.OK
NotificationRestService(dummy_update).delete_notification_template()
def test_delete_notification(self, dummy_send: DummyRequest):
from notification.views.notify import NotificationRestService
dummy_send.matchdict["template_name"] = "new_template"
template_name = "delete_me"
dummy_send.matchdict["template_name"] = template_name
response = NotificationRestService(dummy_send).delete_notification_template()
assert response.status_code == http.HTTPStatus.OK
# TODO: was template -actually- deleted?
# TODO: confirm the thing really was deleted
def test_update_notification_template(self, dummy_send: DummyRequest):
from notification.views.notify import NotificationRestService
dummy_send.json_body = {
"template_name": "a_template",
"template_text": '{"message": "this is the message", "routing_key": "ingestion-complete.#", '
'"project_code": '
'"13B-014"}',
}
template_name = "email"
template_text = "Subject: {{foo}}\n\n{{bar}}\nTo:\n\n{{baz}}"
dummy_send.json_body["template_name"] = template_name
dummy_send.json_body["template_text"] = template_text
response = NotificationRestService(dummy_send).update_notification_template()
assert response.status_code == http.HTTPStatus.OK
# TODO: did template text -really- get updated?
......@@ -65,7 +65,8 @@ class NotificationInfo(NotificationInfoIF):
:param template_text: full text of the template
:return:
"""
template = self.session.query(NotificationTemplate).filter_by(name=template_name).one()
template = self.lookup_template(template_name)
template.content = template_text
self.save_entity(template)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment