mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Merge branch 'master' into reset-password
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from app.models import Notification
|
||||
from app.models import Notification, Job
|
||||
from datetime import datetime
|
||||
from app.dao.notifications_dao import (
|
||||
dao_create_notification,
|
||||
@@ -7,14 +7,70 @@ from app.dao.notifications_dao import (
|
||||
get_notification_for_job,
|
||||
get_notifications_for_job
|
||||
)
|
||||
from tests.app.conftest import sample_job
|
||||
|
||||
|
||||
def test_save_notification(sample_template, sample_job):
|
||||
def test_save_notification_and_increment_job(sample_template, sample_job):
|
||||
|
||||
assert Notification.query.count() == 0
|
||||
data = {
|
||||
'to': '+44709123456',
|
||||
'job_id': sample_job.id,
|
||||
'service': sample_template.service,
|
||||
'template': sample_template,
|
||||
'created_at': datetime.utcnow()
|
||||
}
|
||||
|
||||
notification = Notification(**data)
|
||||
dao_create_notification(notification)
|
||||
|
||||
assert Notification.query.count() == 1
|
||||
notification_from_db = Notification.query.all()[0]
|
||||
assert notification_from_db.id
|
||||
assert data['to'] == notification_from_db.to
|
||||
assert data['job_id'] == notification_from_db.job_id
|
||||
assert data['service'] == notification_from_db.service
|
||||
assert data['template'] == notification_from_db.template
|
||||
assert data['created_at'] == notification_from_db.created_at
|
||||
assert 'sent' == notification_from_db.status
|
||||
assert Job.query.get(sample_job.id).notifications_sent == 1
|
||||
|
||||
|
||||
def test_save_notification_and_increment_correct_job(notify_db, notify_db_session, sample_template):
|
||||
|
||||
job_1 = sample_job(notify_db, notify_db_session, sample_template.service)
|
||||
job_2 = sample_job(notify_db, notify_db_session, sample_template.service)
|
||||
|
||||
assert Notification.query.count() == 0
|
||||
data = {
|
||||
'to': '+44709123456',
|
||||
'job_id': job_1.id,
|
||||
'service': sample_template.service,
|
||||
'template': sample_template,
|
||||
'created_at': datetime.utcnow()
|
||||
}
|
||||
|
||||
notification = Notification(**data)
|
||||
dao_create_notification(notification)
|
||||
|
||||
assert Notification.query.count() == 1
|
||||
notification_from_db = Notification.query.all()[0]
|
||||
assert notification_from_db.id
|
||||
assert data['to'] == notification_from_db.to
|
||||
assert data['job_id'] == notification_from_db.job_id
|
||||
assert data['service'] == notification_from_db.service
|
||||
assert data['template'] == notification_from_db.template
|
||||
assert data['created_at'] == notification_from_db.created_at
|
||||
assert 'sent' == notification_from_db.status
|
||||
assert Job.query.get(job_1.id).notifications_sent == 1
|
||||
assert Job.query.get(job_2.id).notifications_sent == 0
|
||||
|
||||
|
||||
def test_save_notification_with_no_job(sample_template):
|
||||
|
||||
assert Notification.query.count() == 0
|
||||
data = {
|
||||
'to': '+44709123456',
|
||||
'job': sample_job,
|
||||
'service': sample_template.service,
|
||||
'template': sample_template,
|
||||
'created_at': datetime.utcnow()
|
||||
@@ -27,7 +83,6 @@ def test_save_notification(sample_template, sample_job):
|
||||
notification_from_db = Notification.query.all()[0]
|
||||
assert notification_from_db.id
|
||||
assert data['to'] == notification_from_db.to
|
||||
assert data['job'] == notification_from_db.job
|
||||
assert data['service'] == notification_from_db.service
|
||||
assert data['template'] == notification_from_db.template
|
||||
assert data['created_at'] == notification_from_db.created_at
|
||||
|
||||
@@ -10,7 +10,7 @@ def test_should_create_a_new_sms_template_for_a_service(notify_api, sample_servi
|
||||
data = {
|
||||
'name': 'my template',
|
||||
'template_type': 'sms',
|
||||
'content': 'template content',
|
||||
'content': 'template <b>content</b>',
|
||||
'service': str(sample_service.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
@@ -42,7 +42,7 @@ def test_should_create_a_new_email_template_for_a_service(notify_api, sample_ser
|
||||
'name': 'my template',
|
||||
'template_type': 'email',
|
||||
'subject': 'subject',
|
||||
'content': 'template content',
|
||||
'content': 'template <b>content</b>',
|
||||
'service': str(sample_service.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
@@ -222,7 +222,7 @@ def test_should_be_able_to_update_a_template(notify_api, sample_service):
|
||||
json_resp = json.loads(create_response.get_data(as_text=True))
|
||||
assert json_resp['data']['name'] == 'my template'
|
||||
data = {
|
||||
'name': 'my template has a new name'
|
||||
'content': 'my template has new content <script type="text/javascript">alert("foo")</script>'
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
@@ -239,7 +239,7 @@ def test_should_be_able_to_update_a_template(notify_api, sample_service):
|
||||
|
||||
assert update_response.status_code == 200
|
||||
update_json_resp = json.loads(update_response.get_data(as_text=True))
|
||||
assert update_json_resp['data']['name'] == 'my template has a new name'
|
||||
assert update_json_resp['data']['content'] == 'my template has new content alert("foo")'
|
||||
|
||||
|
||||
def test_should_be_able_to_get_all_templates_for_a_service(notify_api, sample_service):
|
||||
|
||||
@@ -2,10 +2,11 @@ import json
|
||||
import moto
|
||||
from datetime import (datetime, timedelta)
|
||||
from flask import url_for
|
||||
from app.models import (VerifyCode)
|
||||
from app.models import (VerifyCode, User)
|
||||
import app.celery.tasks
|
||||
from app import db, encryption
|
||||
from tests import create_authorization_header
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
def test_user_verify_code_sms(notify_api,
|
||||
@@ -127,6 +128,7 @@ def test_user_verify_code_email_expired_code(notify_api,
|
||||
assert not VerifyCode.query.first().code_used
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 10:00:00.000000")
|
||||
def test_user_verify_password(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
@@ -146,6 +148,7 @@ def test_user_verify_password(notify_api,
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert resp.status_code == 204
|
||||
User.query.get(sample_user.id).logged_in_at == datetime.utcnow()
|
||||
|
||||
|
||||
def test_user_verify_password_invalid_password(notify_api,
|
||||
|
||||
Reference in New Issue
Block a user